From 117d18bc928945404b09b7e70916cee53a60ffc1 Mon Sep 17 00:00:00 2001 From: kakwa Date: Wed, 24 Jun 2015 00:46:10 +0200 Subject: [PATCH] prefixing all form attributes to differenciate between types --- ldapcherry/__init__.py | 26 +++++++++++++++++++------- resources/templates/form.tmpl | 14 +++++++------- resources/templates/modify.tmpl | 4 ++-- resources/templates/roles.tmpl | 15 +++++++-------- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index eefe26e..1a8ba27 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -362,7 +362,17 @@ class LdapCherry(object): ret[attrid] = tmp[attr] return ret - + def _parse_params(self, params): + ret = {'attrs': {}, 'roles': {}, 'groups': {}} + for p in params: + p_type, sep, param = p.partition('.') + if p_type == 'attr': + ret['attrs'][param] = params[p] + elif p_type == 'role': + ret['roles'][param] = params[p] + elif p_type == 'group': + ret['groups'][param] = params[p] + return ret def _check_admin(self): if self.auth_mode == 'none': @@ -391,25 +401,26 @@ class LdapCherry(object): raise cherrypy.HTTPRedirect("/signin") def _adduser(self, params): + params = self._parse_params(params) badd = {} for attr in self.attributes.get_attributes(): if self.attributes.attributes[attr]['type'] == 'password': pwd1 = attr + '1' pwd2 = attr + '2' - if params[pwd1] != params[pwd2]: + if params['attrs'][pwd1] != params['attrs'][pwd2]: raise Exception() - params[attr] = params[pwd1] - if attr in params: + params['attrs'][attr] = params['attrs'][pwd1] + if attr in params['attrs']: backends = self.attributes.get_backends_attributes(attr) for b in backends: if not b in badd: badd[b] = {} - badd[b][backends[b]] = params[attr] + badd[b][backends[b]] = params['attrs'][attr] for b in badd: self.backends[b].add_user(badd[b]) key = self.attributes.get_key() - username = params[key] + username = params['attrs'][key] sess = cherrypy.session admin = str(sess.get(SESSION_KEY, None)) @@ -425,7 +436,7 @@ class LdapCherry(object): roles = [] for r in self.roles.get_allroles(): - if r in params: + if r in params['roles']: roles.append(r) groups = self.roles.get_groups(roles) for b in groups: @@ -442,6 +453,7 @@ class LdapCherry(object): ) def _modify(self, params): + params = self._parse_params(params) pass def _deleteuser(self, username): diff --git a/resources/templates/form.tmpl b/resources/templates/form.tmpl index 07047f8..ff38aaf 100644 --- a/resources/templates/form.tmpl +++ b/resources/templates/form.tmpl @@ -37,25 +37,25 @@ for a in sorted(attributes.keys(), key=lambda attr: attributes[attr]['weight']): ${attr['display_name']} % if attr['type'] == 'string': - + % elif attr['type'] == 'email': - + % elif attr['type'] == 'int': - + % elif attr['type'] == 'fix': - + ${attr['value']} % elif attr['type'] == 'stringlist': - ${value2} %for val in attr['values']: %endfor % elif attr['type'] == 'password': - + Retype ${attr['display_name']} - + % endif diff --git a/resources/templates/modify.tmpl b/resources/templates/modify.tmpl index a77e152..c2840ff 100644 --- a/resources/templates/modify.tmpl +++ b/resources/templates/modify.tmpl @@ -39,8 +39,8 @@ - + name="group.${backend}.${group}" data-size="mini" id="group.${backend}.${group}" checked> + % endfor diff --git a/resources/templates/roles.tmpl b/resources/templates/roles.tmpl index 410cd5e..b65a06e 100644 --- a/resources/templates/roles.tmpl +++ b/resources/templates/roles.tmpl @@ -8,15 +8,14 @@ for (var i = 0; i < len; i++) { var role = parentRoles[i]; var DnParentRole = roles[role]; - var checked = document.getElementById(role).checked; - $('input[name=' + role +']').bootstrapSwitch('state', true, true); + var checked = document.getElementById('role.'+ role).checked; + $('input[name="role.' + role +'"]').bootstrapSwitch('state', true, true); if ( ! checked){ $.notify("Enable Role '" + DnParentRole + "' (Parent Role of '" + DnRole +"')", { type: 'info', delay: 6500, } - ); } } @@ -28,8 +27,8 @@ for (var i = 0; i < len; i++) { var role = parentRoles[i]; var DnParentRole = roles[role]; - var checked = document.getElementById(role).checked; - $('input[name=' + role +']').bootstrapSwitch('state', false, true); + var checked = document.getElementById('role.'+role).checked; + $('input[name="role.' + role +'"]').bootstrapSwitch('state', false, true); if (checked){ $.notify("Disable Role '" + DnParentRole + "' (Sub Role of '" + DnRole +"')", { @@ -86,9 +85,9 @@ -