Commits

Anonymous committed 8b40bc9

group restrictions

  • Participants
  • Parent commits ed395ee
  • Branches groups

Comments (0)

Files changed (3)

 
 fabfile.py
 producton_settings.py
+newsmeme/production_settings.py
 
 dist
 docs/output

File newsmeme/forms.py

                         coerce=int,
                         choices=((Post.PUBLIC, _("Everyone")),
                                  (Post.FRIENDS, _("Friends only")),
+                                 (Post.MEMBERS, _("Group members only")),
                                  (Post.PRIVATE, _("Just myself"))))
 
     def __init__(self, *args, **kwargs):

File newsmeme/models.py

             if user.friends:
                 criteria.append(db.and_(Post.access==Post.FRIENDS,
                                         Post.author_id.in_(user.friends)))
+
+            if user.groups:
+                criteria.append(db.and_(Post.access==Post.MEMBERS,
+                                        db.not_(Post.group_id==None),
+                                        Post.group_id.in_(user.groups)))
         
         return self.filter(reduce(db.or_, criteria))
 
     PUBLIC = 100
     FRIENDS = 200
     PRIVATE = 300
+    MEMBERS = 400
 
     query_class = PostQuery
 
         if user.is_moderator or user.id == self.author_id:
             return True
 
-        return self.access == self.FRIENDS and self.author_id in user.friends
+        if self.access == self.FRIENDS:
+            return self.author_id in user.friends
+
+        if self.access == self.MEMBERS:
+            return self.group_id in user.groups
 
     def can_vote(self, user):
         if user is None or \