Skip to content

Instantly share code, notes, and snippets.

@vishnevskiy
Created April 5, 2010 01:26
Show Gist options
  • Save vishnevskiy/355885 to your computer and use it in GitHub Desktop.
Save vishnevskiy/355885 to your computer and use it in GitHub Desktop.
class Forums(Module):
can_moderate_forums = Permission('Can moderate forums')
can_start_threads = Permission('Can start new threads', groups=['root_user', 'guild_guest', 'guild_member'])
can_reply_to_threads = Permission('Can reply to threads', groups=['root_user', 'guild_guest', 'guild_member'])
can_delete_own_posts = Permission('Can delete own posts')
can_edit_own_posts = Permission('Can edit own posts', groups=['root_user', 'guild_guest', 'guild_member'])
can_create_polls = Permission('Can create polls', groups=['root_user', 'guild_guest', 'guild_member'])
can_vote_in_polls = Permission('Can vote in polls', groups=['root_user', 'guild_guest', 'guild_member'])
can_rate_posts = Permission('Can rate posts', groups=['root_user', 'guild_guest', 'guild_member'])
def can_add_poll(self, thread):
return thread.started_by_id == self.user.id and self.can_create_polls
def can_edit_post(self, post):
return self.can_moderate_forums or (post.posted_by_id == self.user.id and self.can_edit_own_posts)
def can_delete_post(self, thread, post):
return (self.can_moderate_forums or (post.posted_by_id == self.user.id and self.can_delete_own_posts))\
and not post.id == thread.first_post_id
def can_rate_post(self, post):
return (self.user.authenticated and not self.user.id == post.posted_by_id)\
and (self.can_moderate_forums or self.can_rate_posts)\
and (self.user.id not in post.rating.up and self.user.id not in post.rating.down)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment