Skip to content

Commit

Permalink
Permission handler updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ellmetha committed Mar 31, 2015
1 parent 9259f5d commit b6a62d6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
17 changes: 17 additions & 0 deletions machina/apps/forum_permission/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.contrib.contenttypes.models import ContentType
from django.shortcuts import _get_queryset
from django.utils.timezone import now
from guardian.shortcuts import get_objects_for_user
from guardian.utils import get_anonymous_user

# Local application / specific library imports
Expand Down Expand Up @@ -175,6 +176,22 @@ def can_download_files(self, forum, user):
"""
return self._perform_basic_permission_check(forum, user, 'can_download_file')

# Moderation

def can_access_moderation_panel(self, user):
"""
Returns True if the passed user can access the moderation panel.
This panel allows:
- posts approval
"""
perms = [
'can_approve_posts',
]
moderated_forums = get_objects_for_user(user, perms, klass=Forum, any_perm=True)
return moderated_forums.exists()

# Common
# --

Expand Down
18 changes: 18 additions & 0 deletions tests/unit/permission/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,21 @@ def test_knows_that_a_superuser_can_download_files(self):
u2 = UserFactory.create(is_superuser=True)
# Run & check
self.assertTrue(self.perm_handler.can_download_files(self.forum_1, u2))

def test_knows_that_a_non_moderator_cannot_access_the_moderation_panel(self):
# Setup
u2 = UserFactory.create()
# Run & check
self.assertFalse(self.perm_handler.can_access_moderation_panel(u2))

def test_knows_that_a_moderator_can_access_the_moderation_panel(self):
# Setup
assign_perm('can_approve_posts', self.u1, self.forum_1)
# Run & check
self.assertTrue(self.perm_handler.can_access_moderation_panel(self.u1))

def test_knows_that_a_superuser_can_access_the_moderation_panel(self):
# Setup
u2 = UserFactory.create(is_superuser=True)
# Run & check
self.assertTrue(self.perm_handler.can_access_moderation_panel(u2))

0 comments on commit b6a62d6

Please sign in to comment.