changeset 460:2ff5f4c1476d

Fixing #221. Found some additional cases where the forum moderator check was failing. Replaced this code with calls to the new permissions module.
author Brian Neal <bgneal@gmail.com>
date Sun, 03 Jul 2011 19:35:09 +0000
parents 9d3bd7304050
children 2d96d9bcf0de
files gpp/forums/forms.py gpp/forums/views/main.py gpp/forums/views/spam.py
diffstat 3 files changed, 6 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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)
--- 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: