##// END OF EJS Templates
perms: updated perms summary for users...
marcink -
r2011:72acb5fb default
parent child Browse files
Show More
@@ -1,214 +1,254 b''
1 1 ## snippet for displaying permissions overview for users
2 2 ## usage:
3 3 ## <%namespace name="p" file="/base/perms_summary.mako"/>
4 4 ## ${p.perms_summary(c.perm_user.permissions)}
5 5
6 6 <%def name="perms_summary(permissions, show_all=False, actions=True, side_link=None)">
7 7 <div id="perms" class="table fields">
8 8 %for section in sorted(permissions.keys()):
9 9 <div class="panel panel-default">
10 10 <div class="panel-heading">
11 11 <h3 class="panel-title">${section.replace("_"," ").capitalize()}</h3>
12 12 % if side_link:
13 13 <div class="pull-right">
14 14 <a href="${side_link}">${_('in JSON format')}</a>
15 15 </div>
16 16 % endif
17 17 </div>
18 18 <div class="panel-body">
19 19 <div class="perms_section_head field">
20 20 <div class="radios">
21 21 %if section != 'global':
22 22 <span class="permissions_boxes">
23 23 <span class="desc">${_('show')}: </span>
24 24 ${h.checkbox('perms_filter_none_%s' % section, 'none', 'checked', class_='perm_filter filter_%s' % section, section=section, perm_type='none')} <label for="${'perms_filter_none_%s' % section}"><span class="perm_tag none">${_('none')}</span></label>
25 25 ${h.checkbox('perms_filter_read_%s' % section, 'read', 'checked', class_='perm_filter filter_%s' % section, section=section, perm_type='read')} <label for="${'perms_filter_read_%s' % section}"><span class="perm_tag read">${_('read')}</span></label>
26 26 ${h.checkbox('perms_filter_write_%s' % section, 'write', 'checked', class_='perm_filter filter_%s' % section, section=section, perm_type='write')} <label for="${'perms_filter_write_%s' % section}"> <span class="perm_tag write">${_('write')}</span></label>
27 27 ${h.checkbox('perms_filter_admin_%s' % section, 'admin', 'checked', class_='perm_filter filter_%s' % section, section=section, perm_type='admin')} <label for="${'perms_filter_admin_%s' % section}"><span class="perm_tag admin">${_('admin')}</span></label>
28 28 </span>
29 29 %endif
30 30 </div>
31 31 </div>
32 32 <div class="field">
33 33 %if not permissions[section]:
34 34 <p class="empty_data help-block">${_('No permissions defined')}</p>
35 35 %else:
36 36 <div id='tbl_list_wrap_${section}'>
37 37 <table id="tbl_list_${section}" class="rctable">
38 38 ## global permission box
39 39 %if section == 'global':
40 40 <thead>
41 41 <tr>
42 42 <th colspan="2" class="left">${_('Permission')}</th>
43 43 %if actions:
44 <th>${_('Edit Permission')}</th>
44 <th colspan="2">${_('Edit Permission')}</th>
45 45 %endif
46 46 </thead>
47 47 <tbody>
48 48
49 49 <%
50 50 def get_section_perms(prefix, opts):
51 51 _selected = []
52 52 for op in opts:
53 53 if op.startswith(prefix) and not op.startswith('hg.create.write_on_repogroup'):
54 54 _selected.append(op)
55 55 admin = 'hg.admin' in opts
56 56 _selected_vals = [x.partition(prefix)[-1] for x in _selected]
57 57 return admin, _selected_vals, _selected
58 58 %>
59 <%def name="glob(lbl, val, val_lbl=None, custom_url=None)">
59
60 <%def name="glob(lbl, val, val_lbl=None, edit_url=None, edit_global_url=None)">
60 61 <tr>
61 62 <td class="td-tags">
62 63 ${lbl}
63 64 </td>
64 65 <td class="td-tags">
65 66 %if val[0]:
66 67 %if not val_lbl:
67 ${h.bool2icon(True)}
68 ## super admin case
69 True
68 70 %else:
69 71 <span class="perm_tag admin">${val_lbl}.admin</span>
70 72 %endif
71 73 %else:
72 74 %if not val_lbl:
73 75 ${
74 76 {'false': False,
75 77 'true': True,
76 78 'none': False,
77 79 'repository': True}.get(val[1][0] if 0 < len(val[1]) else 'false')
78 80 }
79 81 %else:
80 82 <span class="perm_tag ${val[1][0]}">${val_lbl}.${val[1][0]}</span>
81 83 %endif
82 84 %endif
83 85 </td>
84 86 %if actions:
85 <td class="td-action">
86 <a href="${custom_url or h.route_path('admin_permissions_global')}">${_('edit')}</a>
87 </td>
87
88 % if edit_url or edit_global_url:
89
90 <td class="td-action">
91 % if edit_url:
92 <a href="${edit_url}">${_('edit')}</a>
93 % else:
94 -
95 % endif
96 </td>
97
98 <td class="td-action">
99 % if edit_global_url:
100 <a href="${edit_global_url}">${_('edit global')}</a>
101 % else:
102 -
103 % endif
104 </td>
105
106 % else:
107 <td class="td-action"></td>
108 <td class="td-action">
109 <a href="${h.route_path('admin_permissions_global')}">${_('edit global')}</a>
110 <td class="td-action">
111 % endif
112
88 113 %endif
89 114 </tr>
90 115 </%def>
91 116
92 ${glob(_('Super admin'), get_section_perms('hg.admin', permissions[section]))}
117 ${glob(_('Repository default permission'), get_section_perms('repository.', permissions[section]), 'repository',
118 edit_url=None, edit_global_url=h.route_path('admin_permissions_object'))}
119
120 ${glob(_('Repository group default permission'), get_section_perms('group.', permissions[section]), 'group',
121 edit_url=None, edit_global_url=h.route_path('admin_permissions_object'))}
93 122
94 ${glob(_('Repository default permission'), get_section_perms('repository.', permissions[section]), 'repository', h.route_path('admin_permissions_object'))}
95 ${glob(_('Repository group default permission'), get_section_perms('group.', permissions[section]), 'group', h.route_path('admin_permissions_object'))}
96 ${glob(_('User group default permission'), get_section_perms('usergroup.', permissions[section]), 'usergroup', h.route_path('admin_permissions_object'))}
123 ${glob(_('User group default permission'), get_section_perms('usergroup.', permissions[section]), 'usergroup',
124 edit_url=None, edit_global_url=h.route_path('admin_permissions_object'))}
125
126 ${glob(_('Super admin'), get_section_perms('hg.admin', permissions[section]),
127 edit_url=h.url('edit_user', user_id=c.user.user_id, anchor='admin'), edit_global_url=None)}
97 128
98 ${glob(_('Create repositories'), get_section_perms('hg.create.', permissions[section]), custom_url=h.route_path('admin_permissions_global'))}
99 ${glob(_('Fork repositories'), get_section_perms('hg.fork.', permissions[section]), custom_url=h.route_path('admin_permissions_global'))}
100 ${glob(_('Create repository groups'), get_section_perms('hg.repogroup.create.', permissions[section]), custom_url=h.route_path('admin_permissions_global'))}
101 ${glob(_('Create user groups'), get_section_perms('hg.usergroup.create.', permissions[section]), custom_url=h.route_path('admin_permissions_global'))}
129 ${glob(_('Inherit permissions'), get_section_perms('hg.inherit_default_perms.', permissions[section]),
130 edit_url=h.url('edit_user_global_perms', user_id=c.user.user_id), edit_global_url=None)}
131
132 ${glob(_('Create repositories'), get_section_perms('hg.create.', permissions[section]),
133 edit_url=h.url('edit_user_global_perms', user_id=c.user.user_id), edit_global_url=h.route_path('admin_permissions_object'))}
102 134
135 ${glob(_('Fork repositories'), get_section_perms('hg.fork.', permissions[section]),
136 edit_url=h.url('edit_user_global_perms', user_id=c.user.user_id), edit_global_url=h.route_path('admin_permissions_object'))}
137
138 ${glob(_('Create repository groups'), get_section_perms('hg.repogroup.create.', permissions[section]),
139 edit_url=h.url('edit_user_global_perms', user_id=c.user.user_id), edit_global_url=h.route_path('admin_permissions_object'))}
140
141 ${glob(_('Create user groups'), get_section_perms('hg.usergroup.create.', permissions[section]),
142 edit_url=h.url('edit_user_global_perms', user_id=c.user.user_id), edit_global_url=h.route_path('admin_permissions_object'))}
103 143
104 144 </tbody>
105 145 %else:
106 146 ## none/read/write/admin permissions on groups/repos etc
107 147 <thead>
108 148 <tr>
109 149 <th>${_('Name')}</th>
110 150 <th>${_('Permission')}</th>
111 151 %if actions:
112 152 <th>${_('Edit Permission')}</th>
113 153 %endif
114 154 </thead>
115 155 <tbody class="section_${section}">
116 156 <%
117 157 def sorter(permissions):
118 158 def custom_sorter(item):
119 159 ## read/write/admin
120 160 section = item[1].split('.')[-1]
121 161 section_importance = {'none': u'0',
122 162 'read': u'1',
123 163 'write':u'2',
124 164 'admin':u'3'}.get(section)
125 165 ## sort by group importance+name
126 166 return section_importance+item[0]
127 167 return sorted(permissions, key=custom_sorter)
128 168 %>
129 169 %for k, section_perm in sorter(permissions[section].items()):
130 170 %if section_perm.split('.')[-1] != 'none' or show_all:
131 171 <tr class="perm_row ${'%s_%s' % (section, section_perm.split('.')[-1])}">
132 172 <td class="td-name"">
133 173 %if section == 'repositories':
134 174 <a href="${h.route_path('repo_summary',repo_name=k)}">${k}</a>
135 175 %elif section == 'repositories_groups':
136 176 <a href="${h.route_path('repo_group_home', repo_group_name=k)}">${k}</a>
137 177 %elif section == 'user_groups':
138 178 ##<a href="${h.url('edit_users_group',user_group_id=k)}">${k}</a>
139 179 ${k}
140 180 %endif
141 181 </td>
142 182 <td class="td-tags">
143 183 %if hasattr(permissions[section], 'perm_origin_stack'):
144 184 %for i, (perm, origin) in enumerate(reversed(permissions[section].perm_origin_stack[k])):
145 185 <span class="${i > 0 and 'perm_overriden' or ''} perm_tag ${perm.split('.')[-1]}">
146 186 ${perm} (${origin})
147 187 </span>
148 188 %endfor
149 189 %else:
150 190 <span class="perm_tag ${section_perm.split('.')[-1]}">${section_perm}</span>
151 191 %endif
152 192 </td>
153 193 %if actions:
154 194 <td class="td-action">
155 195 %if section == 'repositories':
156 196 <a href="${h.route_path('edit_repo_perms',repo_name=k,_anchor='permissions_manage')}">${_('edit')}</a>
157 197 %elif section == 'repositories_groups':
158 198 <a href="${h.url('edit_repo_group_perms',group_name=k,anchor='permissions_manage')}">${_('edit')}</a>
159 199 %elif section == 'user_groups':
160 200 ##<a href="${h.url('edit_users_group',user_group_id=k)}">${_('edit')}</a>
161 201 %endif
162 202 </td>
163 203 %endif
164 204 </tr>
165 205 %endif
166 206 %endfor
167 207
168 208 <tr id="empty_${section}" class="noborder" style="display:none;">
169 209 <td colspan="6">${_('No permission defined')}</td>
170 210 </tr>
171 211
172 212 </tbody>
173 213 %endif
174 214 </table>
175 215 </div>
176 216 %endif
177 217 </div>
178 218 </div>
179 219 </div>
180 220 %endfor
181 221 </div>
182 222
183 223 <script>
184 224 $(document).ready(function(){
185 225 var show_empty = function(section){
186 226 var visible = $('.section_{0} tr.perm_row:visible'.format(section)).length;
187 227 if(visible == 0){
188 228 $('#empty_{0}'.format(section)).show();
189 229 }
190 230 else{
191 231 $('#empty_{0}'.format(section)).hide();
192 232 }
193 233 };
194 234 $('.perm_filter').on('change', function(e){
195 235 var self = this;
196 236 var section = $(this).attr('section');
197 237
198 238 var opts = {};
199 239 var elems = $('.filter_' + section).each(function(el){
200 240 var perm_type = $(this).attr('perm_type');
201 241 var checked = this.checked;
202 242 opts[perm_type] = checked;
203 243 if(checked){
204 244 $('.'+section+'_'+perm_type).show();
205 245 }
206 246 else{
207 247 $('.'+section+'_'+perm_type).hide();
208 248 }
209 249 });
210 250 show_empty(section);
211 251 })
212 252 })
213 253 </script>
214 254 </%def>
General Comments 0
You need to be logged in to leave comments. Login now