コード例 #1
0
ファイル: group_db.py プロジェクト: mrmaple/open_qon
    def create_group(self, user_id, name, owner, description='',
        member_perms=[],
        other_perms=[],
        member_join_perms=[],
        other_join_perms=[],
        anon_read=0,
        no_pay=False):
        """Create a new group.
        
        member_perms, other_perms: see qon.group.HasAccessPolicy
        member_join_perms, other_join_Perms: see qon.group.HasMembership
        """
        
        user_id = user_id.lower()
        
        if self.root.has_key(user_id) or get_usergroup_database().has_key(user_id):
            raise KeyError, "Key %s already exists." % user_id

        if not no_pay:
            # charge owner for new group - don't create group if can't pay
            from qon.karma import NoKarmaToGive
            try:
                owner.pay_karma(self._karma_new_group)
            except NoKarmaToGive:
                return None

        group = Group(user_id=user_id, name=name, owner=owner)
        group.add_owner(owner)
        group.add_sponsor(owner)
        group.anon_read = anon_read
        group.description = description
        
        usergroup = UserGroup(group.user_id)
        get_usergroup_database().add_usergroup(usergroup)
        group.set_owning_group(usergroup)
        
        # members must have at least read access -- otherwise, what's the point of membership?
        mem_perms = member_perms
        if 'read' not in mem_perms:
            mem_perms.append('read')
        
        group.set_group_perms(mem_perms)
        group.set_other_perms(other_perms)
        group.get_members().set_group_perms(member_join_perms)
        group.get_members().set_other_perms(other_join_perms)
        
        # flush owner's group list cache
        self._flush_user_data_caches(owner)

        self.add_group(group)
        return group
コード例 #2
0
ファイル: group_db.py プロジェクト: mrmaple/open_qon
    def remove_group(self, group):  
        del self[group.user_id]
        self.mod_queue.remove_from_queue(group)
        
        # quit groups that group is a member of
        for g in self.member_groups(group):
            self.leave_group(g, group)
            
        # remove members from group
        for member in group.get_member_list():
            self.leave_group(member, group)

        # remove owners from group
        for owner in group.get_owners():
            self.leave_group(owner, group)
        
        # delete usergroup - must be last, since leave_group needs it
        get_usergroup_database().remove_usergroup(group.user_id)
コード例 #3
0
ファイル: group_db.py プロジェクト: mrmaple/open_qon
 def join_group(self, user, group, force=0):
     """User joins group. Disable can_join check by passing True to force."""
     if not force and not group.can_join(user):
         raise NotEnoughPrivileges
         
     group.add_member(user)
     user.add_to_group(get_usergroup_database().get_usergroup(group.get_user_id()))
     if hasattr(user, 'karma_activity_credit'):
         # groups can join groups, and groups don't have karma_activity_credit
         user.karma_activity_credit()
     
     self._flush_user_data_caches(user)
コード例 #4
0
ファイル: group_db.py プロジェクト: mrmaple/open_qon
 def leave_group(self, user, group):
     group.remove_member(user)
     user.remove_from_group(get_usergroup_database().get_usergroup(group.get_user_id()))
     self._flush_user_data_caches(user)
コード例 #5
0
ファイル: user.py プロジェクト: mrmaple/open_qon
 def is_staff(self):
     staff = get_usergroup_database().get_usergroup('staff')
     return staff in self.group_list()
コード例 #6
0
ファイル: user.py プロジェクト: mrmaple/open_qon
 def is_admin(self):
     admin = get_usergroup_database().get_usergroup('admin')
     return admin in self.group_list()