def validate(self): UserEditBase.validate(self) if self.messages.have_errors(): raise self.messages if self.user.enabled and not self.was_enabled: raise ConfirmUserEnable self.user.rights = str(credentials.Rights(self.rights))
def __init__(self, cred, user_id): if 'UNITADMIN' not in cred.rights and 'ADMIN' not in cred.rights: raise credentials.CredentialError('You are not an administrator') UserEditBase.__init__(self, cred, user_id) self.was_enabled = self.user.enabled self.rights = list(credentials.Rights(self.user.rights)) if not self.user.is_new(): self.title = 'Edit details for user %r - %s' % ( self.user.username, self.user.fullname)
def page_enter(ctx, group_id): if group_id is None: ctx.locals.group = globals.db.new_row('groups') else: query = globals.db.query('groups') query.where('group_id = %s', int(group_id)) ctx.locals.group = query.fetchone() ctx.add_session_vars('group') ctx.locals.rights = list(credentials.Rights(ctx.locals.group.rights)) ctx.add_session_vars('rights')
def commit(self, ctx): group = ctx.locals.group if not group.group_name: raise page_common.PageError('Please specify a name') if not group.description: raise page_common.PageError('Please specify a description') group.rights = str(credentials.Rights(ctx.locals.rights)) is_new = group.is_new() ctx.admin_log(group.db_desc()) group.db_update() globals.db.commit() units = credentials.group_units(globals.db, group.group_id) globals.notify.notify('units', *units)
def page_enter(ctx, unit_id): if unit_id is None: ctx.locals.unit = globals.db.new_row('units') else: query = globals.db.query('units') query.where('unit_id = %s', unit_id) ctx.locals.unit = query.fetchone() ctx.locals.group_pt = globals.db.ptset('unit_groups', 'unit_id', 'group_id', unit_id) ctx.locals.group_pt.get_slave_cache().preload_all() ctx.locals.group_edit = SelectPT(ctx.locals.group_pt, 'group_name') ctx.locals.contact_user_select = ForeignKeySearch(ctx.locals.unit, 'contact_user_id', ('username', 'fullname')) ctx.locals.urights = list(credentials.Rights(ctx.locals.unit.rights)) ctx.add_session_vars('unit', 'group_pt', 'group_edit', 'contact_user_select', 'urights')
def commit(self, ctx): unit = ctx.locals.unit if unit.name: unit.name = unit.name.strip() if not unit.name: raise page_common.PageError('A unit name must be given') unit.rights = str(credentials.Rights(ctx.locals.urights)) ctx.admin_log(unit.db_desc()) unit.db_update() ctx.locals.group_edit.set_key(unit.unit_id) ctx.admin_log(ctx.locals.group_edit.db_desc()) ctx.locals.group_edit.db_update() globals.db.commit() ctx.add_message('Updated %s %r' % (config.unit_label.lower(), unit.name)) globals.notify.notify('units', unit.unit_id) globals.notify.notify('unit_groups', unit.unit_id) globals.notify.notify('syndrome_units', unit.unit_id)
def unsaved_check(self, ctx): ctx.locals.unit.rights = str(credentials.Rights(ctx.locals.urights)) if ctx.locals.group_edit.db_has_changed(): raise page_common.ConfirmSave if ctx.locals.unit.db_has_changed(): raise page_common.ConfirmSave
def has_changed(self): self.user.rights = str(credentials.Rights(self.rights)) return UserEditBase.has_changed(self)
def merge_rights(ptset): rights = credentials.Rights() for row in ptset: if row.rights: rights.add(row.rights) return rights