## snippet for displaying permissions overview for users ## usage: ## <%namespace name="p" file="/base/perms_summary.html"/> ## ${p.perms_summary(c.perm_user.permissions)} <%def name="perms_summary(permissions, show_all=False, actions=True)">
%for section in sorted(permissions.keys()):

${section.replace("_"," ").capitalize()}

%if section != 'global': ${_('show')}: ${h.checkbox('perms_filter_none_%s' % section, 'none', 'checked', class_='perm_filter filter_%s' % section, section=section, perm_type='none')} ${h.checkbox('perms_filter_read_%s' % section, 'read', 'checked', class_='perm_filter filter_%s' % section, section=section, perm_type='read')} ${h.checkbox('perms_filter_write_%s' % section, 'write', 'checked', class_='perm_filter filter_%s' % section, section=section, perm_type='write')} ${h.checkbox('perms_filter_admin_%s' % section, 'admin', 'checked', class_='perm_filter filter_%s' % section, section=section, perm_type='admin')} %endif
%if not permissions[section]:

${_('No permissions defined')}

%else:
## global permission box %if section == 'global': %if actions: %endif <% def get_section_perms(prefix, opts): _selected = [] for op in opts: if op.startswith(prefix) and not op.startswith('hg.create.write_on_repogroup'): _selected.append(op) admin = 'hg.admin' in opts _selected_vals = [x.partition(prefix)[-1] for x in _selected] return admin, _selected_vals, _selected %> <%def name="glob(lbl, val, val_lbl=None, custom_url=None)"> %if actions: %endif ${glob(_('Super admin'), get_section_perms('hg.admin', permissions[section]))} ${glob(_('Repository default permission'), get_section_perms('repository.', permissions[section]), 'repository', h.url('admin_permissions_object'))} ${glob(_('Repository group default permission'), get_section_perms('group.', permissions[section]), 'group', h.url('admin_permissions_object'))} ${glob(_('User group default permission'), get_section_perms('usergroup.', permissions[section]), 'usergroup', h.url('admin_permissions_object'))} ${glob(_('Create repositories'), get_section_perms('hg.create.', permissions[section]), custom_url=h.url('admin_permissions_global'))} ${glob(_('Fork repositories'), get_section_perms('hg.fork.', permissions[section]), custom_url=h.url('admin_permissions_global'))} ${glob(_('Create repository groups'), get_section_perms('hg.repogroup.create.', permissions[section]), custom_url=h.url('admin_permissions_global'))} ${glob(_('Create user groups'), get_section_perms('hg.usergroup.create.', permissions[section]), custom_url=h.url('admin_permissions_global'))} %else: ## none/read/write/admin permissions on groups/repos etc %if actions: %endif <% def sorter(permissions): def custom_sorter(item): ## read/write/admin section = item[1].split('.')[-1] section_importance = {'none': u'0', 'read': u'1', 'write':u'2', 'admin':u'3'}.get(section) ## sort by group importance+name return section_importance+item[0] return sorted(permissions, key=custom_sorter) %> %for k, section_perm in sorter(permissions[section].items()): %if section_perm.split('.')[-1] != 'none' or show_all: %if actions: %endif %endif %endfor %endif
${_('Permission')}${_('Edit Permission')}
${lbl} %if val[0]: %if not val_lbl: ${h.bool2icon(True)} %else: ${val_lbl}.admin %endif %else: %if not val_lbl: ${h.bool2icon({'false': False, 'true': True, 'none': False, 'repository': True}.get(val[1][0] if 0 < len(val[1]) else 'false'))} %else: ${val_lbl}.${val[1][0]} %endif %endif ${_('edit')}
${_('Name')} ${_('Permission')}${_('Edit Permission')}
%if section == 'repositories': ${k} %elif section == 'repositories_groups': ${k} %elif section == 'user_groups': ##${k} ${k} %endif ${section_perm} %if section == 'repositories': ${_('edit')} %elif section == 'repositories_groups': ${_('edit')} %elif section == 'user_groups': ##${_('edit')} %endif
%endif
%endfor