# HG changeset patch # User Brian Neal # Date 1309721709 0 # Node ID 2ff5f4c1476d6a6cfdd1e8e446152c368dddb61a # Parent 9d3bd73040507b81a25e37b76d0fe8d2ff1c88a5 Fixing #221. Found some additional cases where the forum moderator check was failing. Replaced this code with calls to the new permissions module. diff -r 9d3bd7304050 -r 2ff5f4c1476d gpp/forums/forms.py --- a/gpp/forums/forms.py Sat Jul 02 23:35:45 2011 +0000 +++ b/gpp/forums/forms.py Sun Jul 03 19:35:09 2011 +0000 @@ -8,6 +8,7 @@ from forums.models import Topic from forums.models import Post from forums.attachments import AttachmentProcessor +import forums.permissions as perms class NewPostForm(forms.Form): @@ -85,7 +86,7 @@ self.user = user self.forum = forum - if user.is_superuser or user in forum.moderators.all(): + if perms.can_moderate(forum, user): self.fields['sticky'] = forms.BooleanField(required=False) self.fields['locked'] = forms.BooleanField(required=False) self.has_mod_fields = True diff -r 9d3bd7304050 -r 2ff5f4c1476d gpp/forums/views/main.py --- a/gpp/forums/views/main.py Sat Jul 02 23:35:45 2011 +0000 +++ b/gpp/forums/views/main.py Sun Jul 03 19:35:09 2011 +0000 @@ -479,10 +479,7 @@ post = get_object_or_404(Post.objects.select_related(), pk=id) - can_delete = request.user.is_superuser or \ - request.user in post.topic.forum.moderators.all() - - if not can_delete: + if not perms.can_moderate(post.topic.forum, request.user): return HttpResponseForbidden("You don't have permission to delete that post.") delete_single_post(post) diff -r 9d3bd7304050 -r 2ff5f4c1476d gpp/forums/views/spam.py --- a/gpp/forums/views/spam.py Sat Jul 02 23:35:45 2011 +0000 +++ b/gpp/forums/views/spam.py Sun Jul 03 19:35:09 2011 +0000 @@ -17,6 +17,7 @@ from comments.models import Comment from forums.models import Post from forums.tools import delete_user_posts +import forums.permissions as perms import bio.models from core.functions import email_admins @@ -62,9 +63,7 @@ poster = post.user poster_profile = poster.get_profile() - can_moderate = request.user.is_superuser or ( - request.user in post.topic.forum.moderators.all()) - + can_moderate = perms.can_moderate(post.topic.forum, request.user) can_deactivate = (poster_profile.status == bio.models.STA_STRANGER and not poster.is_superuser) @@ -120,9 +119,7 @@ poster = post.user poster_profile = poster.get_profile() - can_moderate = request.user.is_superuser or ( - request.user in post.topic.forum.moderators.all()) - + can_moderate = perms.can_moderate(post.topic.forum, request.user) can_promote = poster_profile.status == bio.models.STA_STRANGER if request.method == "POST" and can_moderate and can_promote: