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