Show More
@@ -1,254 +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 | 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 | 59 | |
|
60 | 60 | <%def name="glob(lbl, val, val_lbl=None, edit_url=None, edit_global_url=None)"> |
|
61 | 61 | <tr> |
|
62 | 62 | <td class="td-tags"> |
|
63 | 63 | ${lbl} |
|
64 | 64 | </td> |
|
65 | 65 | <td class="td-tags"> |
|
66 | 66 | %if val[0]: |
|
67 | 67 | %if not val_lbl: |
|
68 | 68 | ## super admin case |
|
69 | 69 | True |
|
70 | 70 | %else: |
|
71 | 71 | <span class="perm_tag admin">${val_lbl}.admin</span> |
|
72 | 72 | %endif |
|
73 | 73 | %else: |
|
74 | 74 | %if not val_lbl: |
|
75 | 75 | ${ |
|
76 | 76 | {'false': False, |
|
77 | 77 | 'true': True, |
|
78 | 78 | 'none': False, |
|
79 | 79 | 'repository': True}.get(val[1][0] if 0 < len(val[1]) else 'false') |
|
80 | 80 | } |
|
81 | 81 | %else: |
|
82 | 82 | <span class="perm_tag ${val[1][0]}">${val_lbl}.${val[1][0]}</span> |
|
83 | 83 | %endif |
|
84 | 84 | %endif |
|
85 | 85 | </td> |
|
86 | 86 | %if actions: |
|
87 | 87 | |
|
88 | 88 | % if edit_url or edit_global_url: |
|
89 | 89 | |
|
90 | 90 | <td class="td-action"> |
|
91 | 91 | % if edit_url: |
|
92 | 92 | <a href="${edit_url}">${_('edit')}</a> |
|
93 | 93 | % else: |
|
94 | 94 | - |
|
95 | 95 | % endif |
|
96 | 96 | </td> |
|
97 | 97 | |
|
98 | 98 | <td class="td-action"> |
|
99 | 99 | % if edit_global_url: |
|
100 | 100 | <a href="${edit_global_url}">${_('edit global')}</a> |
|
101 | 101 | % else: |
|
102 | 102 | - |
|
103 | 103 | % endif |
|
104 | 104 | </td> |
|
105 | 105 | |
|
106 | 106 | % else: |
|
107 | 107 | <td class="td-action"></td> |
|
108 | 108 | <td class="td-action"> |
|
109 | 109 | <a href="${h.route_path('admin_permissions_global')}">${_('edit global')}</a> |
|
110 | 110 | <td class="td-action"> |
|
111 | 111 | % endif |
|
112 | 112 | |
|
113 | 113 | %endif |
|
114 | 114 | </tr> |
|
115 | 115 | </%def> |
|
116 | 116 | |
|
117 | 117 | ${glob(_('Repository default permission'), get_section_perms('repository.', permissions[section]), 'repository', |
|
118 | 118 | edit_url=None, edit_global_url=h.route_path('admin_permissions_object'))} |
|
119 | 119 | |
|
120 | 120 | ${glob(_('Repository group default permission'), get_section_perms('group.', permissions[section]), 'group', |
|
121 | 121 | edit_url=None, edit_global_url=h.route_path('admin_permissions_object'))} |
|
122 | 122 | |
|
123 | 123 | ${glob(_('User group default permission'), get_section_perms('usergroup.', permissions[section]), 'usergroup', |
|
124 | 124 | edit_url=None, edit_global_url=h.route_path('admin_permissions_object'))} |
|
125 | 125 | |
|
126 | 126 | ${glob(_('Super admin'), get_section_perms('hg.admin', permissions[section]), |
|
127 | 127 | edit_url=h.url('edit_user', user_id=c.user.user_id, anchor='admin'), edit_global_url=None)} |
|
128 | 128 | |
|
129 | 129 | ${glob(_('Inherit permissions'), get_section_perms('hg.inherit_default_perms.', permissions[section]), |
|
130 | 130 | edit_url=h.url('edit_user_global_perms', user_id=c.user.user_id), edit_global_url=None)} |
|
131 | 131 | |
|
132 | 132 | ${glob(_('Create repositories'), get_section_perms('hg.create.', permissions[section]), |
|
133 | 133 | edit_url=h.url('edit_user_global_perms', user_id=c.user.user_id), edit_global_url=h.route_path('admin_permissions_object'))} |
|
134 | 134 | |
|
135 | 135 | ${glob(_('Fork repositories'), get_section_perms('hg.fork.', permissions[section]), |
|
136 | 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 | 137 | |
|
138 | 138 | ${glob(_('Create repository groups'), get_section_perms('hg.repogroup.create.', permissions[section]), |
|
139 | 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 | 140 | |
|
141 | 141 | ${glob(_('Create user groups'), get_section_perms('hg.usergroup.create.', permissions[section]), |
|
142 | 142 | edit_url=h.url('edit_user_global_perms', user_id=c.user.user_id), edit_global_url=h.route_path('admin_permissions_object'))} |
|
143 | 143 | |
|
144 | 144 | </tbody> |
|
145 | 145 | %else: |
|
146 | 146 | ## none/read/write/admin permissions on groups/repos etc |
|
147 | 147 | <thead> |
|
148 | 148 | <tr> |
|
149 | 149 | <th>${_('Name')}</th> |
|
150 | 150 | <th>${_('Permission')}</th> |
|
151 | 151 | %if actions: |
|
152 | 152 | <th>${_('Edit Permission')}</th> |
|
153 | 153 | %endif |
|
154 | 154 | </thead> |
|
155 | 155 | <tbody class="section_${section}"> |
|
156 | 156 | <% |
|
157 | 157 | def sorter(permissions): |
|
158 | 158 | def custom_sorter(item): |
|
159 | 159 | ## read/write/admin |
|
160 | 160 | section = item[1].split('.')[-1] |
|
161 | 161 | section_importance = {'none': u'0', |
|
162 | 162 | 'read': u'1', |
|
163 | 163 | 'write':u'2', |
|
164 | 164 | 'admin':u'3'}.get(section) |
|
165 | 165 | ## sort by group importance+name |
|
166 | 166 | return section_importance+item[0] |
|
167 | 167 | return sorted(permissions, key=custom_sorter) |
|
168 | 168 | %> |
|
169 | 169 | %for k, section_perm in sorter(permissions[section].items()): |
|
170 | 170 | %if section_perm.split('.')[-1] != 'none' or show_all: |
|
171 | 171 | <tr class="perm_row ${'%s_%s' % (section, section_perm.split('.')[-1])}"> |
|
172 |
<td class="td-name" |
|
|
172 | <td class="td-name"> | |
|
173 | 173 | %if section == 'repositories': |
|
174 | 174 | <a href="${h.route_path('repo_summary',repo_name=k)}">${k}</a> |
|
175 | 175 | %elif section == 'repositories_groups': |
|
176 | 176 | <a href="${h.route_path('repo_group_home', repo_group_name=k)}">${k}</a> |
|
177 | 177 | %elif section == 'user_groups': |
|
178 | 178 | ##<a href="${h.url('edit_users_group',user_group_id=k)}">${k}</a> |
|
179 | 179 | ${k} |
|
180 | 180 | %endif |
|
181 | 181 | </td> |
|
182 | 182 | <td class="td-tags"> |
|
183 | 183 | %if hasattr(permissions[section], 'perm_origin_stack'): |
|
184 | 184 | %for i, (perm, origin) in enumerate(reversed(permissions[section].perm_origin_stack[k])): |
|
185 | 185 | <span class="${i > 0 and 'perm_overriden' or ''} perm_tag ${perm.split('.')[-1]}"> |
|
186 | 186 | ${perm} (${origin}) |
|
187 | 187 | </span> |
|
188 | 188 | %endfor |
|
189 | 189 | %else: |
|
190 | 190 | <span class="perm_tag ${section_perm.split('.')[-1]}">${section_perm}</span> |
|
191 | 191 | %endif |
|
192 | 192 | </td> |
|
193 | 193 | %if actions: |
|
194 | 194 | <td class="td-action"> |
|
195 | 195 | %if section == 'repositories': |
|
196 | 196 | <a href="${h.route_path('edit_repo_perms',repo_name=k,_anchor='permissions_manage')}">${_('edit')}</a> |
|
197 | 197 | %elif section == 'repositories_groups': |
|
198 | 198 | <a href="${h.url('edit_repo_group_perms',group_name=k,anchor='permissions_manage')}">${_('edit')}</a> |
|
199 | 199 | %elif section == 'user_groups': |
|
200 | 200 | ##<a href="${h.url('edit_users_group',user_group_id=k)}">${_('edit')}</a> |
|
201 | 201 | %endif |
|
202 | 202 | </td> |
|
203 | 203 | %endif |
|
204 | 204 | </tr> |
|
205 | 205 | %endif |
|
206 | 206 | %endfor |
|
207 | 207 | |
|
208 | 208 | <tr id="empty_${section}" class="noborder" style="display:none;"> |
|
209 | 209 | <td colspan="6">${_('No permission defined')}</td> |
|
210 | 210 | </tr> |
|
211 | 211 | |
|
212 | 212 | </tbody> |
|
213 | 213 | %endif |
|
214 | 214 | </table> |
|
215 | 215 | </div> |
|
216 | 216 | %endif |
|
217 | 217 | </div> |
|
218 | 218 | </div> |
|
219 | 219 | </div> |
|
220 | 220 | %endfor |
|
221 | 221 | </div> |
|
222 | 222 | |
|
223 | 223 | <script> |
|
224 | 224 | $(document).ready(function(){ |
|
225 | 225 | var show_empty = function(section){ |
|
226 | 226 | var visible = $('.section_{0} tr.perm_row:visible'.format(section)).length; |
|
227 | 227 | if(visible == 0){ |
|
228 | 228 | $('#empty_{0}'.format(section)).show(); |
|
229 | 229 | } |
|
230 | 230 | else{ |
|
231 | 231 | $('#empty_{0}'.format(section)).hide(); |
|
232 | 232 | } |
|
233 | 233 | }; |
|
234 | 234 | $('.perm_filter').on('change', function(e){ |
|
235 | 235 | var self = this; |
|
236 | 236 | var section = $(this).attr('section'); |
|
237 | 237 | |
|
238 | 238 | var opts = {}; |
|
239 | 239 | var elems = $('.filter_' + section).each(function(el){ |
|
240 | 240 | var perm_type = $(this).attr('perm_type'); |
|
241 | 241 | var checked = this.checked; |
|
242 | 242 | opts[perm_type] = checked; |
|
243 | 243 | if(checked){ |
|
244 | 244 | $('.'+section+'_'+perm_type).show(); |
|
245 | 245 | } |
|
246 | 246 | else{ |
|
247 | 247 | $('.'+section+'_'+perm_type).hide(); |
|
248 | 248 | } |
|
249 | 249 | }); |
|
250 | 250 | show_empty(section); |
|
251 | 251 | }) |
|
252 | 252 | }) |
|
253 | 253 | </script> |
|
254 | 254 | </%def> |
General Comments 0
You need to be logged in to leave comments.
Login now