mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-25 18:54:29 +01:00
implementing displaying roles and standalone groups in modify form
This commit is contained in:
parent
834b5a5152
commit
5e5e7e3c6a
@ -82,11 +82,22 @@ class LdapCherry(object):
|
|||||||
ret = {}
|
ret = {}
|
||||||
for b in self.backends:
|
for b in self.backends:
|
||||||
ret[b] = self.backends[b].get_groups(username)
|
ret[b] = self.backends[b].get_groups(username)
|
||||||
|
cherrypy.log.error(
|
||||||
|
msg = ret,
|
||||||
|
severity = logging.DEBUG,
|
||||||
|
)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def _get_roles(self, username):
|
def _get_roles(self, username):
|
||||||
groups = self._get_groups(username)
|
groups = self._get_groups(username)
|
||||||
return self.roles.get_roles(groups)
|
user_roles = self.roles.get_roles(groups)
|
||||||
|
cherrypy.log.error(
|
||||||
|
msg = user_roles,
|
||||||
|
severity = logging.DEBUG,
|
||||||
|
)
|
||||||
|
return user_roles
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _is_admin(self, username):
|
def _is_admin(self, username):
|
||||||
roles = self._get_roles(username)
|
roles = self._get_roles(username)
|
||||||
@ -521,7 +532,7 @@ class LdapCherry(object):
|
|||||||
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, modify=False)
|
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, current_roles=None)
|
||||||
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)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
@ -553,10 +564,13 @@ 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']
|
||||||
user_attrs = self._get_user(user)
|
user_attrs = self._get_user(user)
|
||||||
|
tmp = self._get_roles(user)
|
||||||
|
user_roles = tmp['roles']
|
||||||
|
user_lonely_groups = tmp['unusedgroups']
|
||||||
roles_js = json.dumps(display_names, separators=(',',':'))
|
roles_js = json.dumps(display_names, separators=(',',':'))
|
||||||
form = self.temp_form.render(attributes=self.attributes.attributes, values=user_attrs, modify=True)
|
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)
|
roles = self.temp_roles.render(roles=self.roles.flatten, graph=self.roles.graph, graph_js=graph_js, roles_js=roles_js, current_roles=user_roles)
|
||||||
return self.temp_modify.render(form=form, roles=roles, is_admin=is_admin, notification=notification)
|
return self.temp_modify.render(form=form, roles=roles, is_admin=is_admin, notification=notification, standalone_groups=user_lonely_groups)
|
||||||
|
|
||||||
@cherrypy.expose
|
@cherrypy.expose
|
||||||
def selfmodify(self, **params):
|
def selfmodify(self, **params):
|
||||||
|
@ -280,12 +280,14 @@ class Roles:
|
|||||||
roles = Set([])
|
roles = Set([])
|
||||||
parentroles = Set([])
|
parentroles = Set([])
|
||||||
notroles = Set([])
|
notroles = Set([])
|
||||||
|
tmp = Set([])
|
||||||
usedgroups = {}
|
usedgroups = {}
|
||||||
unusedgroups = {}
|
unusedgroups = {}
|
||||||
ret = {}
|
ret = {}
|
||||||
# determine roles membership
|
# determine roles membership
|
||||||
for role in self.roles:
|
for role in self.roles:
|
||||||
self._check_member(role, groups, notroles, roles, parentroles, usedgroups)
|
if self._check_member(role, groups, notroles, tmp, parentroles, usedgroups):
|
||||||
|
roles.add(role)
|
||||||
# determine standalone groups not matching any roles
|
# determine standalone groups not matching any roles
|
||||||
for b in groups:
|
for b in groups:
|
||||||
for g in groups[b]:
|
for g in groups[b]:
|
||||||
@ -293,6 +295,7 @@ class Roles:
|
|||||||
if b not in unusedgroups:
|
if b not in unusedgroups:
|
||||||
unusedgroups[b] = Set([])
|
unusedgroups[b] = Set([])
|
||||||
unusedgroups[b].add(g)
|
unusedgroups[b].add(g)
|
||||||
|
|
||||||
ret['roles'] = roles
|
ret['roles'] = roles
|
||||||
ret['unusedgroups'] = unusedgroups
|
ret['unusedgroups'] = unusedgroups
|
||||||
return ret
|
return ret
|
||||||
|
@ -10,7 +10,44 @@
|
|||||||
${form}
|
${form}
|
||||||
<h2 class="h3">Enable/Disable user's roles:</h2>
|
<h2 class="h3">Enable/Disable user's roles:</h2>
|
||||||
${roles}
|
${roles}
|
||||||
|
% if len(standalone_groups) != 0:
|
||||||
<h2 class="h3">Delete user's individual groups:</h2>
|
<h2 class="h3">Delete user's individual groups:</h2>
|
||||||
|
<table id="RecordTable" class="table table-hover table-condensed tablesorter">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="sorter-false">
|
||||||
|
Backend
|
||||||
|
</th>
|
||||||
|
<th class="sorter-false">
|
||||||
|
Group
|
||||||
|
</th>
|
||||||
|
<th class="sorter-false">
|
||||||
|
Enable/Disable
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
% for backend in standalone_groups:
|
||||||
|
% for group in standalone_groups[backend]:
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
${backend}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
${group}
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
|
||||||
|
data-off-text="Disabled" data-handle-width="75" type="checkbox"
|
||||||
|
name="${group}" data-size="mini" id="${group}" checked>
|
||||||
|
<script>$("[name='${group}']").bootstrapSwitch();</script>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
% endfor
|
||||||
|
% endfor
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
% endif
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<button class="btn btn-default blue" type="submit">
|
<button class="btn btn-default blue" type="submit">
|
||||||
|
@ -60,6 +60,12 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
%for role in roles:
|
%for role in roles:
|
||||||
|
<%
|
||||||
|
if not current_roles is None and role in current_roles:
|
||||||
|
checked = ' checked '
|
||||||
|
else:
|
||||||
|
checked = ''
|
||||||
|
%>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
${roles[role]['display_name']}
|
${roles[role]['display_name']}
|
||||||
@ -80,7 +86,7 @@
|
|||||||
<td>
|
<td>
|
||||||
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
|
<input data-on-color="success" data-off-color="danger" data-on-text="Enabled"
|
||||||
data-off-text="Disabled" data-handle-width="75" type="checkbox"
|
data-off-text="Disabled" data-handle-width="75" type="checkbox"
|
||||||
name="${role}" data-size="mini" id="${role}" >
|
name="${role}" data-size="mini" id="${role}" ${checked}>
|
||||||
<script>$("[name='${role}']").bootstrapSwitch();
|
<script>$("[name='${role}']").bootstrapSwitch();
|
||||||
$('input[name="${role}"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
$('input[name="${role}"]').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||||
if (state) {
|
if (state) {
|
||||||
|
Loading…
Reference in New Issue
Block a user