comparison gpp/forums/views/spam.py @ 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 9d470c7a2b93
children 98b373ca09f3
comparison
equal deleted inserted replaced
459:9d3bd7304050 460:2ff5f4c1476d
15 from django.contrib.auth.models import User 15 from django.contrib.auth.models import User
16 16
17 from comments.models import Comment 17 from comments.models import Comment
18 from forums.models import Post 18 from forums.models import Post
19 from forums.tools import delete_user_posts 19 from forums.tools import delete_user_posts
20 import forums.permissions as perms
20 import bio.models 21 import bio.models
21 from core.functions import email_admins 22 from core.functions import email_admins
22 23
23 24
24 SPAMMER_NAILED_SUBJECT = "Spammer Nailed: %s" 25 SPAMMER_NAILED_SUBJECT = "Spammer Nailed: %s"
60 61
61 post = get_object_or_404(Post.objects.select_related(), pk=post_id) 62 post = get_object_or_404(Post.objects.select_related(), pk=post_id)
62 poster = post.user 63 poster = post.user
63 poster_profile = poster.get_profile() 64 poster_profile = poster.get_profile()
64 65
65 can_moderate = request.user.is_superuser or ( 66 can_moderate = perms.can_moderate(post.topic.forum, request.user)
66 request.user in post.topic.forum.moderators.all())
67
68 can_deactivate = (poster_profile.status == bio.models.STA_STRANGER and not 67 can_deactivate = (poster_profile.status == bio.models.STA_STRANGER and not
69 poster.is_superuser) 68 poster.is_superuser)
70 69
71 if request.method == "POST" and can_moderate and can_deactivate: 70 if request.method == "POST" and can_moderate and can_deactivate:
72 deactivate_spammer(poster) 71 deactivate_spammer(poster)
118 """ 117 """
119 post = get_object_or_404(Post.objects.select_related(), pk=post_id) 118 post = get_object_or_404(Post.objects.select_related(), pk=post_id)
120 poster = post.user 119 poster = post.user
121 poster_profile = poster.get_profile() 120 poster_profile = poster.get_profile()
122 121
123 can_moderate = request.user.is_superuser or ( 122 can_moderate = perms.can_moderate(post.topic.forum, request.user)
124 request.user in post.topic.forum.moderators.all())
125
126 can_promote = poster_profile.status == bio.models.STA_STRANGER 123 can_promote = poster_profile.status == bio.models.STA_STRANGER
127 124
128 if request.method == "POST" and can_moderate and can_promote: 125 if request.method == "POST" and can_moderate and can_promote:
129 promote_stranger(poster) 126 promote_stranger(poster)
130 127