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