def adduser(self, **params): """ add user page """ self._check_auth(must_admin=True) is_admin = self._check_admin() if cherrypy.request.method.upper() == 'POST': params = self._parse_params(params) self._adduser(params) self._add_notification("User added") graph = {} for r in self.roles.graph: s = list(self.roles.graph[r]['sub_roles']) p = list(self.roles.graph[r]['parent_roles']) graph[r] = {'sub_roles': s, 'parent_roles': p} graph_js = json.dumps(graph, separators=(',', ':')) display_names = {} for r in self.roles.flatten: display_names[r] = self.roles.flatten[r]['display_name'] roles_js = json.dumps(display_names, separators=(',', ':')) try: form = self.temp['form.tmpl'].render( attributes=self.attributes.attributes, values=None, modify=False, autofill=True ) roles = self.temp['roles.tmpl'].render( roles=self.roles.flatten, graph=self.roles.graph, graph_js=graph_js, roles_js=roles_js, current_roles=None, ) return self.temp['adduser.tmpl'].render( form=form, roles=roles, is_admin=is_admin, custom_js=self.custom_js, notifications=self._empty_notification(), ) except NameError: raise TemplateRenderError( exceptions.text_error_template().render() )
def selfmodify(self, **params): """ self modify user page """ self._check_auth(must_admin=False) is_admin = self._check_admin() sess = cherrypy.session user = sess.get(SESSION_KEY, None) if self.auth_mode == 'none': return self.temp['error.tmpl'].render( is_admin=is_admin, alert='warning', message="Not accessible with authentication disabled." ) if cherrypy.request.method.upper() == 'POST': params = self._parse_params(params) self._selfmodify(params) self._add_notification( "Self modification done" ) user_attrs = self._get_user(user) try: if user_attrs == {}: return self.temp['error.tmpl'].render( is_admin=is_admin, alert='warning', message="User doesn't exist" ) form = self.temp['form.tmpl'].render( attributes=self.attributes.get_selfattributes(), values=user_attrs, modify=True, autofill=False ) return self.temp['selfmodify.tmpl'].render( form=form, is_admin=is_admin, notifications=self._empty_notification(), ) except NameError: raise TemplateRenderError( exceptions.text_error_template().render() )
def modify(self, user=None, **params): """ modify user page """ self._check_auth(must_admin=True) is_admin = self._check_admin() if cherrypy.request.method.upper() == 'POST': params = self._parse_params(params) self._modify(params) self._add_notification("User modified") try: referer = cherrypy.request.headers['Referer'] except Exception as e: referer = '/' raise cherrypy.HTTPRedirect(referer) graph = {} for r in self.roles.graph: s = list(self.roles.graph[r]['sub_roles']) p = list(self.roles.graph[r]['parent_roles']) graph[r] = {'sub_roles': s, 'parent_roles': p} graph_js = json.dumps(graph, separators=(',', ':')) display_names = {} for r in self.roles.flatten: display_names[r] = self.roles.flatten[r]['display_name'] if user is None: cherrypy.response.status = 400 return self.temp['error.tmpl'].render(is_admin=is_admin, alert='warning', message="No user requested") user_attrs = self._get_user(user) if user_attrs == {}: cherrypy.response.status = 400 return self.temp['error.tmpl'].render(is_admin=is_admin, alert='warning', message="User '" + user + "' does not exist") tmp = self._get_roles(user) user_roles = tmp['roles'] standalone_groups = tmp['unusedgroups'] roles_js = json.dumps(display_names, separators=(',', ':')) key = self.attributes.get_key() try: form = self.temp['form.tmpl'].render( attributes=self.attributes.attributes, values=user_attrs, modify=True, keyattr=key, autofill=False) roles = self.temp['roles.tmpl'].render( roles=self.roles.flatten, graph=self.roles.graph, graph_js=graph_js, roles_js=roles_js, current_roles=user_roles, ) glued_template = self.temp['modify.tmpl'].render( form=form, roles=roles, is_admin=is_admin, standalone_groups=standalone_groups, backends_display_names=self.backends_display_names, custom_js=self.custom_js, notifications=self._empty_notification(), ) except NameError: raise TemplateRenderError( exceptions.text_error_template().render()) return glued_template
def modify(self, user=None, **params): """ modify user page """ self._check_auth(must_admin=True) is_admin = self._check_admin() if cherrypy.request.method.upper() == 'POST': params = self._parse_params(params) self._modify(params) self._add_notification("User modified") try: referer = cherrypy.request.headers['Referer'] except Exception as e: referer = '/' raise cherrypy.HTTPRedirect(referer) graph = {} for r in self.roles.graph: s = list(self.roles.graph[r]['sub_roles']) p = list(self.roles.graph[r]['parent_roles']) graph[r] = {'sub_roles': s, 'parent_roles': p} graph_js = json.dumps(graph, separators=(',', ':')) display_names = {} for r in self.roles.flatten: display_names[r] = self.roles.flatten[r]['display_name'] if user is None: cherrypy.response.status = 400 return self.temp['error.tmpl'].render( is_admin=is_admin, alert='warning', message="No user requested" ) user_attrs = self._get_user(user) if user_attrs == {}: cherrypy.response.status = 400 return self.temp['error.tmpl'].render( is_admin=is_admin, alert='warning', message="User '" + user + "' does not exist" ) tmp = self._get_roles(user) user_roles = tmp['roles'] standalone_groups = tmp['unusedgroups'] roles_js = json.dumps(display_names, separators=(',', ':')) key = self.attributes.get_key() try: form = self.temp['form.tmpl'].render( attributes=self.attributes.attributes, values=user_attrs, modify=True, keyattr=key, autofill=False ) roles = self.temp['roles.tmpl'].render( roles=self.roles.flatten, graph=self.roles.graph, graph_js=graph_js, roles_js=roles_js, current_roles=user_roles, ) glued_template = self.temp['modify.tmpl'].render( form=form, roles=roles, is_admin=is_admin, standalone_groups=standalone_groups, backends_display_names=self.backends_display_names, custom_js=self.custom_js, notifications=self._empty_notification(), ) except NameError: raise TemplateRenderError( exceptions.text_error_template().render() ) return glued_template