class GroupForm(HorizontalForm): fields = [ widgets.HiddenField(name='group_id'), widgets.TextField(name='group_name', label=_(u'Group Name')), widgets.TextField(name='display_name', label=_(u'Display Name')), widgets.PasswordField(name='root_password', label=_(u'Root Password'), validator=StrongPassword()), widgets.CheckBox(name='ldap', label=_(u'LDAP'), help_text=_(u'Populate group membership from LDAP?')), ] name = 'Group' action = 'save_data' submit_text = _(u'Save') validator = GroupFormSchema() def update_params(self, d): if not identity.current.user.is_admin() or \ not config.get('identity.ldap.enabled', False): d['disabled_fields'] = ['ldap'] super(GroupForm, self).update_params(d)
class Users(AdminPage): # For XMLRPC methods in this class. exposed = True user_id = widgets.HiddenField(name='user_id') user_name = widgets.TextField(name='user_name', label=_(u'Login')) display_name = widgets.TextField(name='display_name', label=_(u'Display Name')) email_address = widgets.TextField(name='email_address', label=_(u'Email Address')) password = widgets.PasswordField(name='password', label=_(u'Password')) disabled = widgets.CheckBox(name='disabled', label=_(u'Disabled')) user_form = HorizontalForm( 'User', fields=[ user_id, user_name, display_name, email_address, password, disabled ], action='save_data', submit_text=_(u'Save'), ) def __init__(self, *args, **kw): kw['search_url'] = url("/users/by_name?anywhere=1&ldap=0") kw['search_name'] = 'user' super(Users, self).__init__(*args, **kw) self.search_col = User.user_name self.search_mapper = User @identity.require(identity.in_group("admin")) @expose(template='bkr.server.templates.form') def new(self, **kw): return dict( form=self.user_form, action='./save', options={}, value=kw, ) @identity.require(identity.in_group("admin")) @expose(template='bkr.server.templates.user_edit_form') def edit(self, id=None, **kw): if id: user = User.by_id(id) title = _(u'User %s') % user.user_name value = user else: user = None title = _(u'New user') value = kw return_vals = dict(form=self.user_form, action='./save', title=title, options={}, value=value) if id: return_vals['groupsgrid'] = self.show_groups() else: return_vals['groupsgrid'] = None return return_vals @identity.require(identity.in_group("admin")) @expose() @validate(user_form, validators=UserFormSchema()) @error_handler(edit) def save(self, **kw): if kw.get('user_id'): user = User.by_id(kw['user_id']) else: user = User() session.add(user) user.display_name = kw['display_name'] user.user_name = kw['user_name'] user.email_address = kw['email_address'] if kw.get('disabled') != user.disabled: user.disabled = kw.get('disabled') if user.disabled: self._disable(user, method="WEBUI") if kw['password'] != user.password: user.password = kw['password'] flash(_(u"%s saved" % user.display_name)) redirect(".") def make_remove_link(self, user): if user.removed is not None: return XML('<a class="btn" href="unremove?id=%s">' '<i class="fa fa-plus"/> Re-Add</a>' % user.user_id) else: return XML('<a class="btn" href="remove?id=%s">' '<i class="fa fa-times"/> Remove</a>' % user.user_id) @expose(template="bkr.server.templates.admin_grid") @paginate('list', default_order='user_name', limit=20) def index(self, *args, **kw): users = session.query(User) list_by_letters = set( [elem.user_name[0].capitalize() for elem in users]) result = self.process_search(**kw) if result: users = result users_grid = myPaginateDataGrid(fields=[ ('Login', lambda x: make_edit_link(x.user_name, x.user_id)), ('Display Name', lambda x: x.display_name), ('Disabled', lambda x: x.disabled), ('', lambda x: self.make_remove_link(x)), ], add_action='./new') return dict(title="Users", grid=users_grid, alpha_nav_bar=AlphaNavBar(list_by_letters, 'user'), search_widget=self.search_widget_form, list=users) @identity.require(identity.in_group("admin")) @expose() def remove(self, id, **kw): try: user = User.by_id(id) except InvalidRequestError: flash(_(u'Invalid user id %s' % id)) raise redirect('.') try: self._remove(user=user, method='WEBUI') except BX, e: flash( _(u'Failed to remove User %s, due to %s' % (user.user_name, e))) raise redirect('.') else:
class Preferences(RPCRoot): exposed = True delete_link = DeleteLinkWidgetForm() beaker_password = widgets.PasswordField(name='password', label='Beaker Password') root_password = widgets.TextField(name='_root_password', label='Root Password') rootpw_expiry = widgets.TextField(name='rootpw_expiry', label='Root Password Expiry', attrs={'disabled': True}) email = widgets.TextField(name='email_address', label='Email Address', validator=validators.Email()) prefs_form = HorizontalForm( 'UserPrefs', fields=[email, beaker_password, root_password, rootpw_expiry], action='save', submit_text=_(u'Change'), ) sshkey = widgets.TextArea( name='ssh_pub_key', label='Public SSH Key', validator=beaker_validators.SSHPubKey(not_empty=True)) ssh_key_add_form = InlineForm( 'ssh_key_add', fields=[sshkey], action='ssh_key_add', submit_text=_(u'Add'), ) rootpw_grid = BeakerDataGrid(fields=[ BeakerDataGrid.Column('root_password', title=_(u'Root Password'), getter=lambda x: x.value), BeakerDataGrid.Column('effective_from', title=_(u'Effective from'), getter=lambda x: x.valid_from, options=dict(datetime=True)), ]) auto_users = AutoCompleteField(name='user', search_controller=url("../users/by_name"), search_param="input", result_name="matches") submission_delegate_form = InlineForm( 'SubmissionDelegates', fields=[auto_users], action='save_data', submit_text=_(u'Add'), ) remove_submission_delegate_link = DoAndConfirmForm() def show_submission_delegates(self, user): user_fields = [ ('Submission Delegate', lambda x: x.display_name), ('Action', lambda x: self.remove_submission_delegate_link. \ display({'delegate_id': x.user_id}, action=url('remove_submission_delegate'), look='link', msg='Are you sure you want to remove %s as a submitter?' % x, action_text='Remove (-)')),] return BeakerDataGrid(fields=user_fields) @expose(template='bkr.server.templates.prefs') @identity.require(identity.not_anonymous()) def index(self, *args, **kw): user = identity.current.user # Show all future root passwords, and the previous five rootpw = ConfigItem.by_name('root_password') rootpw_values = rootpw.values().filter(rootpw.value_class.valid_from > datetime.utcnow())\ .order_by(rootpw.value_class.valid_from.desc()).all()\ + rootpw.values().filter(rootpw.value_class.valid_from <= datetime.utcnow())\ .order_by(rootpw.value_class.valid_from.desc())[:5] return dict( title='User Prefs', delete_link=self.delete_link, prefs_form=self.prefs_form, ssh_key_form=self.ssh_key_add_form, widgets={}, ssh_keys=user.sshpubkeys, value=user, rootpw=rootpw.current_value(), rootpw_grid=self.rootpw_grid, rootpw_values=rootpw_values, options=None, #Hack, to insert static content for submission_delegate remove_submission_delegate=self.remove_submission_delegate_link, submission_delegates_grid=self.show_submission_delegates(user), submission_delegate_form=self.submission_delegate_form) # XMLRPC interface @expose() @identity.require(identity.not_anonymous()) def remove_submission_delegate_by_name(self, delegate_name, service=u'XMLRPC'): user = identity.current.user try: submission_delegate = User.by_user_name(delegate_name) except NoResultFound: raise BX(_(u'%s is not a valid user name' % delegate_name)) try: user.remove_submission_delegate(submission_delegate, service=service) except ValueError: raise BX(_(u'%s is not a submission delegate of %s' % \ (delegate_name, user))) return delegate_name # UI interface @expose() @identity.require(identity.not_anonymous()) def remove_submission_delegate(self, delegate_id, service=u'WEBUI'): user = identity.current.user try: submission_delegate = User.by_id(delegate_id) except NoResultFound: flash(_(u'%s is not a valid user id' % delegate_id)) redirect('.') user.remove_submission_delegate(submission_delegate, service=service) flash(_(u'%s removed as a submission delegate' % submission_delegate)) redirect('.') # XMLRPC Interface @expose() @identity.require(identity.not_anonymous()) def add_submission_delegate_by_name(self, new_delegate_name, service=u'XMLRPC'): user = identity.current.user new_delegate = User.by_user_name(new_delegate_name) if not new_delegate: raise BX(_(u'%s is not a valid user' % new_delegate_name)) user.add_submission_delegate(new_delegate, service) return new_delegate_name # UI Interface @expose() @identity.require(identity.not_anonymous()) def add_submission_delegate(self, **kwargs): user = identity.current.user new_delegate_name = kwargs['user']['text'] new_delegate = User.by_user_name(new_delegate_name) if not new_delegate: flash(_(u'%s is not a valid user' % new_delegate_name)) redirect('.') try: user.add_submission_delegate(new_delegate, u'WEBUI') except NoChangeException, e: flash(_(unicode(e))) redirect('.') flash(_(u'Added %s as a submission delegate' % new_delegate_name)) redirect('.')
class Fields(widgets.WidgetsList): name = widgets.TextField(validator=validators.UnicodeString()) age = widgets.TextField(validator=validators.Int()) passwd = widgets.PasswordField(validator=validators.NotEmpty()) passwd2 = widgets.PasswordField(validator=validators.UnicodeString())
class Fields(widgets.WidgetsList): name = widgets.TextField() age = widgets.TextField() passwd = widgets.PasswordField() passwd2 = widgets.PasswordField()