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