示例#1
0
文件: main.py 项目: MrPetru/spam
    def post_add_to_group(self, group_id, userids):
        """Add users to a group"""
        session = session_get()
        user = tmpl_context.user
        group = group_get(group_id)
        added = []
        updates = []
        
        for uid in userids:
            adduser = user_get(uid)
            if adduser not in group.users:
                group.users.append(adduser)
                added.append(adduser.user_id)
                
                # prepare updates to notify clients
                updates.append(dict(item=adduser, type='added',
                            topic=TOPIC_GROUPS, filter=group.group_name))
        
        added = ', '.join(added)

        if added:
            # log into Journal
            msg = '%s %s %s' % (added,
                                n_('added to group:',
                                   'added to group:', len(added)),
                                group.group_id)
            journal.add(user, msg)
            notify.send(updates)

            return dict(msg=msg, status='ok', updates=updates)

        return dict(msg='%s %s' % (_('Selected users are already in group:'),
                                    group.group_id), status='info', updates=[])
示例#2
0
文件: main.py 项目: MrPetru/spam
    def remove_from_group(self, user_id, group_id):
        """Remove a user from a group"""
        session = session_get()
        user = tmpl_context.user
        remuser = user_get(user_id)
        group = group_get(group_id)
        updates = []
        
        if remuser in group.users:
            group.users.remove(remuser)
            
            # prepare updates to notify clients
            updates.append(dict(item=remuser, type='deleted',
                        topic=TOPIC_GROUPS, filter=group.group_name))

            # log into Journal
            msg = '%s %s %s' % (remuser.user_id,
                                _('removed from group'),
                                group.group_id)
            journal.add(user, msg)
            notify.send(updates)

            return dict(msg=msg, status='ok', updates=updates)

        return dict(msg='%s %s %s' % (remuser.user_id, _('is not in group:'),
                                    group.group_id), status='error', updates=[])
示例#3
0
文件: main.py 项目: MrPetru/spam
 def get_add_to_group(self, group_id, **kwargs):
     """Display a ADD users form."""
     group = group_get(group_id)
     users = session_get().query(User)
     choices = [(u.user_id, '%-16s (%s)' % (u.user_id, u.display_name))
                                                             for u in users]
     f_add_to_group.child.children.userids.options = choices
     f_add_to_group.value = dict(group_id=group.group_id)
     tmpl_context.form = f_add_to_group
     return dict(title='%s %s' % (_('Add users to group:'), group.group_id))