1
0
mirror of https://github.com/kakwa/ldapcherry synced 2024-11-11 12:08:51 +01:00

begin implementing modify user form

This commit is contained in:
kakwa 2015-06-18 23:43:58 +02:00
parent 234a82b3bd
commit 834b5a5152
3 changed files with 83 additions and 12 deletions

View File

@ -292,6 +292,7 @@ class LdapCherry(object):
self.temp_groups = self.temp_lookup.get_template('groups.tmpl') self.temp_groups = self.temp_lookup.get_template('groups.tmpl')
self.temp_form = self.temp_lookup.get_template('form.tmpl') self.temp_form = self.temp_lookup.get_template('form.tmpl')
self.temp_selfmodify = self.temp_lookup.get_template('selfmodify.tmpl') self.temp_selfmodify = self.temp_lookup.get_template('selfmodify.tmpl')
self.temp_modify = self.temp_lookup.get_template('modify.tmpl')
self._init_auth(config) self._init_auth(config)
@ -338,6 +339,21 @@ class LdapCherry(object):
ret[u][attrid] = tmp[u][attr] ret[u][attrid] = tmp[u][attr]
return ret return ret
def _get_user(self, username):
if username is None:
return {}
ret = {}
for b in self.backends:
tmp = self.backends[b].get_user(username)
for attr in tmp:
if attr in self.attributes.backend_attributes[b]:
attrid = self.attributes.backend_attributes[b][attr]
if not attr in ret:
ret[attrid] = tmp[attr]
return ret
def _check_admin(self): def _check_admin(self):
if self.auth_mode == 'none': if self.auth_mode == 'none':
return True return True
@ -504,7 +520,7 @@ class LdapCherry(object):
for r in self.roles.flatten: for r in self.roles.flatten:
display_names[r] = self.roles.flatten[r]['display_name'] display_names[r] = self.roles.flatten[r]['display_name']
roles_js = json.dumps(display_names, separators=(',',':')) roles_js = json.dumps(display_names, separators=(',',':'))
form = self.temp_form.render(attributes=self.attributes.attributes, values=None) form = self.temp_form.render(attributes=self.attributes.attributes, values=None, modify=False)
roles = self.temp_roles.render(roles=self.roles.flatten, graph=self.roles.graph, graph_js=graph_js, roles_js=roles_js) roles = self.temp_roles.render(roles=self.roles.flatten, graph=self.roles.graph, graph_js=graph_js, roles_js=roles_js)
return self.temp_adduser.render(form=form, roles=roles, is_admin=is_admin, notification=notification) return self.temp_adduser.render(form=form, roles=roles, is_admin=is_admin, notification=notification)
@ -516,16 +532,36 @@ class LdapCherry(object):
pass pass
@cherrypy.expose @cherrypy.expose
def modify(self, **params): def modify(self, user=None, **params):
""" modify user page """ """ modify user page """
self._check_auth(must_admin=True) self._check_auth(must_admin=True)
is_admin = self._check_admin() is_admin = self._check_admin()
pass
if cherrypy.request.method.upper() == 'POST':
notification = "<script type=\"text/javascript\">$.notify('User Modify')</script>"
self._adduser(params)
else:
notification = ''
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']
user_attrs = self._get_user(user)
roles_js = json.dumps(display_names, separators=(',',':'))
form = self.temp_form.render(attributes=self.attributes.attributes, values=user_attrs, modify=True)
roles = self.temp_roles.render(roles=self.roles.flatten, graph=self.roles.graph, graph_js=graph_js, roles_js=roles_js)
return self.temp_modify.render(form=form, roles=roles, is_admin=is_admin, notification=notification)
@cherrypy.expose @cherrypy.expose
def selfmodify(self, **params): def selfmodify(self, **params):
""" self modify user page """ """ self modify user page """
self._check_auth(must_admin=False) self._check_auth(must_admin=False)
is_admin = self._check_admin() is_admin = self._check_admin()
form = self.temp_form.render(attributes=self.attributes.get_selfattributes(), values=None) form = self.temp_form.render(attributes=self.attributes.get_selfattributes(), values=None, modify=True)
return self.temp_selfmodify.render(form=form, is_admin=is_admin) return self.temp_selfmodify.render(form=form, is_admin=is_admin)

View File

@ -19,22 +19,31 @@ for a in sorted(attributes.keys(), key=lambda attr: attributes[attr]['weight']):
<div class="form-group"> <div class="form-group">
<div class="input-group"> <div class="input-group">
<% <%
if modify:
required = ''
else:
required = ' required '
if not values is None and a in values: if not values is None and a in values:
value = ' value="'+ values[a] + '"' if type(values[a]) is list:
value2 = '<option>'+ values[a] +'</option>' tmp = values[a][0]
else:
tmp = values[a]
value = ' value="'+ tmp + '"'
value2 = '<option>'+ tmp +'</option>'
else: else:
value = '' value = ''
value2 = '' value2 = ''
%> %>
<span class="input-group-addon" id="basic-addon1">${attr['display_name']}</span> <span class="input-group-addon" id="basic-addon1">${attr['display_name']}</span>
% if attr['type'] == 'string': % if attr['type'] == 'string':
<input type="text" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" required ${value}> <input type="text" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} ${value}>
% elif attr['type'] == 'email': % elif attr['type'] == 'email':
<input type="email" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" required ${value} data-error="email address is invalid"> <input type="email" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} ${value} data-error="email address is invalid">
% elif attr['type'] == 'int': % elif attr['type'] == 'int':
<input type="number" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" required ${value}> <input type="number" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} ${value}>
% elif attr['type'] == 'fix': % elif attr['type'] == 'fix':
<input type="hidden" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" required value="${attr['value']}"> <input type="hidden" name="${a}" class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1" ${required} value="${attr['value']}">
<span class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1">${attr['value']}</span> <span class="form-control" placeholder="${attr['description']}" aria-describedby="basic-addon1">${attr['value']}</span>
% elif attr['type'] == 'stringlist': % elif attr['type'] == 'stringlist':
<select class="form-control" name="type"> <select class="form-control" name="type">
@ -44,9 +53,9 @@ for a in sorted(attributes.keys(), key=lambda attr: attributes[attr]['weight']):
%endfor %endfor
</select> </select>
% elif attr['type'] == 'password': % elif attr['type'] == 'password':
<input type="password" class="form-control" name="${a}1" id="${a}1" placeholder="${attr['description']}" required> <input type="password" class="form-control" name="${a}1" id="${a}1" placeholder="${attr['description']}" ${required}>
<span class="input-group-addon" id="basic-addon1">Retype ${attr['display_name']}</span> <span class="input-group-addon" id="basic-addon1">Retype ${attr['display_name']}</span>
<input type="password" class="form-control" name="${a}2" id="#${a}2" data-match="#${a}1" placeholder="Confirm" required> <input type="password" class="form-control" name="${a}2" id="#${a}2" data-match="#${a}1" placeholder="Confirm" ${required}>
% endif % endif
</div> </div>
</div> </div>

View File

@ -0,0 +1,26 @@
<%inherit file="navbar.tmpl"/>
<%block name="core">
<div class="row clearfix top-buffer bottom-buffer">
<div class="col-md-2 column">
</div>
<div class="col-md-12 column">
<div class="well well-sm">
<form method='POST' action='/modify' role="form" class="form-signin" data-toggle="validator">
<h2 class="h3">Modify user's attributes:</h2>
${form}
<h2 class="h3">Enable/Disable user's roles:</h2>
${roles}
<h2 class="h3">Delete user's individual groups:</h2>
<div class="form-group">
<div class="input-group">
<button class="btn btn-default blue" type="submit">
<span class="glyphicon glyphicon-cog"> Modify User</button>
</div>
</div>
</form>
</div>
</div>
<div class="col-md-2 column">
</div>
</div>
</%block>