Skip to content

Commit f0d37b3

Browse files
gmjosackclaudep
authored andcommitted
Fix infinite redirect when logged in
By default the `permission_required` decorator redirects to the login url when you don't have sufficient permissions. The result of this is if a user navigates to a page they don't have permission to view they end up in an infinite redirect loop between the forbidden page and the login page. This change will allow logged out users a chance to login but return forbidden when you don't have sufficient permissions.
1 parent b54e954 commit f0d37b3

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

django_comments/views/moderation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def flag(request, comment_id, next=None):
3535

3636

3737
@csrf_protect
38-
@permission_required("django_comments.can_moderate")
38+
@login_required
39+
@permission_required("django_comments.can_moderate", raise_exception=True)
3940
def delete(request, comment_id, next=None):
4041
"""
4142
Deletes a comment. Confirmation on GET, action on POST. Requires the "can
@@ -63,7 +64,8 @@ def delete(request, comment_id, next=None):
6364

6465

6566
@csrf_protect
66-
@permission_required("django_comments.can_moderate")
67+
@login_required
68+
@permission_required("django_comments.can_moderate", raise_exception=True)
6769
def approve(request, comment_id, next=None):
6870
"""
6971
Approve a comment (that is, mark it as public and non-removed). Confirmation

0 commit comments

Comments
 (0)