fix: login_required import and comment author assignment (#140, #118) #186
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Issues #140 and #118
🔗 PR: Fix login_required import and comment author bug
Summary
This pull request resolves two major bugs and introduces a security enhancement in the Django Girls extended tutorial:
✅ Fixes
NameError
due to missing@login_required
import (@login_required is not defined #140)✅ Fixes
ValueError
caused by incorrect comment author assignment (issue on comment submit #118)✅ Adds proper permission checks for comment moderation (approve/remove)
Changes
🔧 1. Import
@login_required
(Fixes #140)Issue:
Tutorial omitted the import for
login_required
, resulting in:Fix:
Added the following line to relevant sections of the tutorial and example code:
🔧 2. Fix Comment Author Assignment (Fixes #118)
Issue:
Using
author = models.CharField(...)
led to:Fix:
Changed
author
field to aForeignKey
to theUser
model. Also removed the author field from the form.Before:
After:
🔒 3. Add Security Checks for Moderation
Problem:
Any logged-in user could approve or delete any comment.
Fix:
Added permission checks:
✅ Only the post author can approve comments.
✅ Only the comment author or post author can delete comments.