def remove_admin(self, proj, user_id): """Remove an administrator from a project""" session = session_get() user = tmpl_context.user project = tmpl_context.project remuser = user_get(user_id) updates = [] if remuser in project.admins: project.admins.remove(remuser) # prepare updates to notify clients updates.append(dict(item=remuser, type='deleted', topic=TOPIC_PROJECT_ADMINS, filter=project.id)) # log into Journal msg = '%s %s %s' % (remuser.user_id, _('revoked as administrator for:'), project.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 an administrator for:'), project.id), status='error', updates=[])
def remove_artist(self, proj, category_id, user_id): """Remove an artist from a category""" session = session_get() user = tmpl_context.user project = project_get(proj) category = category_get(category_id) remuser = user_get(user_id) updates = [] if remuser in project.artists[category]: query = session.query(Artist).filter_by(proj_id=project.id) query = query.filter_by(category_id=category.id) query = query.filter_by(user_id=remuser.user_id) artist = query.one() session.delete(artist) # prepare updates to notify clients updates.append(dict(item=remuser, type='deleted', topic=TOPIC_PROJECT_ARTISTS, filter='%s-%s' % (project.id, category.id))) # log into Journal msg = '%s %s %s/%s' % (remuser.user_id, _('revoked as artist from:'), project.id, category.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 an artist for:'), project.id), status='error', updates=[])
def remove_supervisor(self, proj, category_id, user_id): """Remove a supervisor from a category""" session = session_get() user = tmpl_context.user project = tmpl_context.project category = category_get(category_id) remuser = user_get(user_id) updates = [] if remuser in project.supervisors[category]: query = session.query(Supervisor).filter_by(proj_id=project.id) query = query.filter_by(category_id=category.id) query = query.filter_by(user_id=remuser.user_id) sup = query.one() session.delete(sup) # prepare updates to notify clients updates.append(dict(item=remuser, type='deleted', topic=TOPIC_PROJECT_SUPERVISORS, filter='%s-%s' % (project.id, category.id))) # log into Journal msg = '%s %s %s/%s' % (remuser.user_id, _('revoked as supervisor from:'), project.id, category.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 a supervisor for:'), project.id), status='error', updates=[])
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=[])
def post_add_admins(self, proj, userids): """Add administrators to a project""" session = session_get() user = tmpl_context.user project = tmpl_context.project added = [] updates = [] for uid in userids: adduser = user_get(uid) if adduser not in project.admins: project.admins.append(adduser) added.append(adduser.user_id) # prepare updates to notify clients updates.append(dict(item=adduser, type='added', topic=TOPIC_PROJECT_ADMINS, filter=project.id)) added = ', '.join(added) if added: # log into Journal msg = '%s %s %s' % (added, n_('set as administrator for:', 'set as administrators for:', len(added)), project.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 administrators for:'), project.id), status='info', updates=[])
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=[])
def put(self, user_id, display_name=None): """Edit a user""" session = session_get() user = tmpl_context.user edituser = user_get(user_id) old = edituser.__dict__.copy() modified = False if display_name and not edituser.display_name == display_name: edituser.display_name = display_name modified = True if modified: new = edituser.__dict__.copy() msg = '%s %s' % (_('Updated user:'******'%s - %s' % (msg, diff_dicts(old, new))) # notify clients updates = [ dict(item=edituser, type='updated', topic=TOPIC_USERS) ] notify.send(updates) return dict(msg=msg, status='ok', updates=updates) return dict(msg='%s %s' % (_('User is unchanged:'), edituser.user_id), status='info', updates=[])
def edit(self, user_id, **kwargs): """Display a EDIT form.""" user = user_get(user_id) f_edit.value = dict(user_id=user.user_id, user_name_=user.user_name, display_name=user.display_name) tmpl_context.form = f_edit return dict(title='%s %s' % (_('Edit user:'), user.user_id))
def get_delete(self, user_id, **kwargs): """Display a DELETE confirmation form.""" user = user_get(user_id) f_confirm.custom_method = 'DELETE' f_confirm.value = dict(user_id=user.user_id, user_name_=user.user_name, display_name_=user.display_name) tmpl_context.form = f_confirm return dict(title='%s %s?' % (_('Are you sure you want to delete:'), user.user_id))
def post_delete(self, user_id): """Delete a user.""" session = session_get() user = tmpl_context.user deluser = user_get(user_id) session.delete(deluser) msg = '%s %s' % (_('Deleted user:'******'%s - %s' % (msg, deluser)) # notify clients updates = [dict(item=deluser, type='deleted', topic=TOPIC_USERS)] notify.send(updates) return dict(msg=msg, status='ok', updates=updates)
def post_add_artists(self, proj, category_id, userids): """Add artists to a category""" session = session_get() user = tmpl_context.user project = tmpl_context.project category = category_get(category_id) added = [] updates = [] users = [user_get(uid) for uid in userids] artists = [Artist(project.id, category, adduser) for adduser in users if adduser not in project.artists[category]] for artist in artists: added.append(artist.user.user_id) # prepare updates to notify clients updates.append(dict(item=artist.user, type='added', topic=TOPIC_PROJECT_ARTISTS, filter='%s-%s' % (project.id, category.id))) added = ', '.join(added) if added: # log into Journal msg = '%s %s %s/%s' % (added, n_('set as artist for:', 'set as artists for:', len(added)), project.id, category.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 artists for:'), project.id), status='info', updates=[])