Show More
@@ -1,369 +1,369 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 |
|
2 | |||
3 | # Copyright (C) 2016-2017 RhodeCode GmbH |
|
3 | # Copyright (C) 2016-2017 RhodeCode GmbH | |
4 | # |
|
4 | # | |
5 | # This program is free software: you can redistribute it and/or modify |
|
5 | # This program is free software: you can redistribute it and/or modify | |
6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
6 | # it under the terms of the GNU Affero General Public License, version 3 | |
7 | # (only), as published by the Free Software Foundation. |
|
7 | # (only), as published by the Free Software Foundation. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU Affero General Public License |
|
14 | # You should have received a copy of the GNU Affero General Public License | |
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | # |
|
16 | # | |
17 | # This program is dual-licensed. If you wish to learn more about the |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
20 |
|
20 | |||
21 | import re |
|
21 | import re | |
22 | import logging |
|
22 | import logging | |
23 | import formencode |
|
23 | import formencode | |
24 | from pyramid.interfaces import IRoutesMapper |
|
24 | from pyramid.interfaces import IRoutesMapper | |
25 |
|
25 | |||
26 | from pyramid.view import view_config |
|
26 | from pyramid.view import view_config | |
27 | from pyramid.httpexceptions import HTTPFound |
|
27 | from pyramid.httpexceptions import HTTPFound | |
28 | from pyramid.renderers import render |
|
28 | from pyramid.renderers import render | |
29 | from pyramid.response import Response |
|
29 | from pyramid.response import Response | |
30 |
|
30 | |||
31 | from rhodecode.apps._base import BaseAppView |
|
31 | from rhodecode.apps._base import BaseAppView | |
32 |
|
32 | |||
33 | from rhodecode.lib import helpers as h |
|
33 | from rhodecode.lib import helpers as h | |
34 | from rhodecode.lib.auth import ( |
|
34 | from rhodecode.lib.auth import ( | |
35 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) |
|
35 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) | |
36 | from rhodecode.lib.utils2 import aslist |
|
36 | from rhodecode.lib.utils2 import aslist | |
37 | from rhodecode.model.db import User, UserIpMap |
|
37 | from rhodecode.model.db import User, UserIpMap | |
38 | from rhodecode.model.forms import ( |
|
38 | from rhodecode.model.forms import ( | |
39 | ApplicationPermissionsForm, ObjectPermissionsForm, UserPermissionsForm) |
|
39 | ApplicationPermissionsForm, ObjectPermissionsForm, UserPermissionsForm) | |
40 | from rhodecode.model.meta import Session |
|
40 | from rhodecode.model.meta import Session | |
41 | from rhodecode.model.permission import PermissionModel |
|
41 | from rhodecode.model.permission import PermissionModel | |
42 | from rhodecode.model.settings import SettingsModel |
|
42 | from rhodecode.model.settings import SettingsModel | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | log = logging.getLogger(__name__) |
|
45 | log = logging.getLogger(__name__) | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | class AdminPermissionsView(BaseAppView): |
|
48 | class AdminPermissionsView(BaseAppView): | |
49 | def load_default_context(self): |
|
49 | def load_default_context(self): | |
50 | c = self._get_local_tmpl_context() |
|
50 | c = self._get_local_tmpl_context() | |
51 |
|
51 | |||
52 | self._register_global_c(c) |
|
52 | self._register_global_c(c) | |
53 | PermissionModel().set_global_permission_choices( |
|
53 | PermissionModel().set_global_permission_choices( | |
54 | c, gettext_translator=self.request.translate) |
|
54 | c, gettext_translator=self.request.translate) | |
55 | return c |
|
55 | return c | |
56 |
|
56 | |||
57 | @LoginRequired() |
|
57 | @LoginRequired() | |
58 | @HasPermissionAllDecorator('hg.admin') |
|
58 | @HasPermissionAllDecorator('hg.admin') | |
59 | @view_config( |
|
59 | @view_config( | |
60 | route_name='admin_permissions_application', request_method='GET', |
|
60 | route_name='admin_permissions_application', request_method='GET', | |
61 | renderer='rhodecode:templates/admin/permissions/permissions.mako') |
|
61 | renderer='rhodecode:templates/admin/permissions/permissions.mako') | |
62 | def permissions_application(self): |
|
62 | def permissions_application(self): | |
63 | c = self.load_default_context() |
|
63 | c = self.load_default_context() | |
64 | c.active = 'application' |
|
64 | c.active = 'application' | |
65 |
|
65 | |||
66 | c.user = User.get_default_user(refresh=True) |
|
66 | c.user = User.get_default_user(refresh=True) | |
67 |
|
67 | |||
68 | app_settings = SettingsModel().get_all_settings() |
|
68 | app_settings = SettingsModel().get_all_settings() | |
69 | defaults = { |
|
69 | defaults = { | |
70 | 'anonymous': c.user.active, |
|
70 | 'anonymous': c.user.active, | |
71 | 'default_register_message': app_settings.get( |
|
71 | 'default_register_message': app_settings.get( | |
72 | 'rhodecode_register_message') |
|
72 | 'rhodecode_register_message') | |
73 | } |
|
73 | } | |
74 | defaults.update(c.user.get_default_perms()) |
|
74 | defaults.update(c.user.get_default_perms()) | |
75 |
|
75 | |||
76 | data = render('rhodecode:templates/admin/permissions/permissions.mako', |
|
76 | data = render('rhodecode:templates/admin/permissions/permissions.mako', | |
77 | self._get_template_context(c), self.request) |
|
77 | self._get_template_context(c), self.request) | |
78 | html = formencode.htmlfill.render( |
|
78 | html = formencode.htmlfill.render( | |
79 | data, |
|
79 | data, | |
80 | defaults=defaults, |
|
80 | defaults=defaults, | |
81 | encoding="UTF-8", |
|
81 | encoding="UTF-8", | |
82 | force_defaults=False |
|
82 | force_defaults=False | |
83 | ) |
|
83 | ) | |
84 | return Response(html) |
|
84 | return Response(html) | |
85 |
|
85 | |||
86 | @LoginRequired() |
|
86 | @LoginRequired() | |
87 | @HasPermissionAllDecorator('hg.admin') |
|
87 | @HasPermissionAllDecorator('hg.admin') | |
88 | @CSRFRequired() |
|
88 | @CSRFRequired() | |
89 | @view_config( |
|
89 | @view_config( | |
90 | route_name='admin_permissions_application_update', request_method='POST', |
|
90 | route_name='admin_permissions_application_update', request_method='POST', | |
91 | renderer='rhodecode:templates/admin/permissions/permissions.mako') |
|
91 | renderer='rhodecode:templates/admin/permissions/permissions.mako') | |
92 | def permissions_application_update(self): |
|
92 | def permissions_application_update(self): | |
93 | _ = self.request.translate |
|
93 | _ = self.request.translate | |
94 | c = self.load_default_context() |
|
94 | c = self.load_default_context() | |
95 | c.active = 'application' |
|
95 | c.active = 'application' | |
96 |
|
96 | |||
97 | _form = ApplicationPermissionsForm( |
|
97 | _form = ApplicationPermissionsForm( | |
98 | [x[0] for x in c.register_choices], |
|
98 | [x[0] for x in c.register_choices], | |
99 | [x[0] for x in c.password_reset_choices], |
|
99 | [x[0] for x in c.password_reset_choices], | |
100 | [x[0] for x in c.extern_activate_choices])() |
|
100 | [x[0] for x in c.extern_activate_choices])() | |
101 |
|
101 | |||
102 | try: |
|
102 | try: | |
103 | form_result = _form.to_python(dict(self.request.POST)) |
|
103 | form_result = _form.to_python(dict(self.request.POST)) | |
104 | form_result.update({'perm_user_name': User.DEFAULT_USER}) |
|
104 | form_result.update({'perm_user_name': User.DEFAULT_USER}) | |
105 | PermissionModel().update_application_permissions(form_result) |
|
105 | PermissionModel().update_application_permissions(form_result) | |
106 |
|
106 | |||
107 | settings = [ |
|
107 | settings = [ | |
108 | ('register_message', 'default_register_message'), |
|
108 | ('register_message', 'default_register_message'), | |
109 | ] |
|
109 | ] | |
110 | for setting, form_key in settings: |
|
110 | for setting, form_key in settings: | |
111 | sett = SettingsModel().create_or_update_setting( |
|
111 | sett = SettingsModel().create_or_update_setting( | |
112 | setting, form_result[form_key]) |
|
112 | setting, form_result[form_key]) | |
113 | Session().add(sett) |
|
113 | Session().add(sett) | |
114 |
|
114 | |||
115 | Session().commit() |
|
115 | Session().commit() | |
116 | h.flash(_('Application permissions updated successfully'), |
|
116 | h.flash(_('Application permissions updated successfully'), | |
117 | category='success') |
|
117 | category='success') | |
118 |
|
118 | |||
119 | except formencode.Invalid as errors: |
|
119 | except formencode.Invalid as errors: | |
120 | defaults = errors.value |
|
120 | defaults = errors.value | |
121 |
|
121 | |||
122 | data = render( |
|
122 | data = render( | |
123 | 'rhodecode:templates/admin/permissions/permissions.mako', |
|
123 | 'rhodecode:templates/admin/permissions/permissions.mako', | |
124 | self._get_template_context(c), self.request) |
|
124 | self._get_template_context(c), self.request) | |
125 | html = formencode.htmlfill.render( |
|
125 | html = formencode.htmlfill.render( | |
126 | data, |
|
126 | data, | |
127 | defaults=defaults, |
|
127 | defaults=defaults, | |
128 | errors=errors.error_dict or {}, |
|
128 | errors=errors.error_dict or {}, | |
129 | prefix_error=False, |
|
129 | prefix_error=False, | |
130 | encoding="UTF-8", |
|
130 | encoding="UTF-8", | |
131 | force_defaults=False |
|
131 | force_defaults=False | |
132 | ) |
|
132 | ) | |
133 | return Response(html) |
|
133 | return Response(html) | |
134 |
|
134 | |||
135 | except Exception: |
|
135 | except Exception: | |
136 | log.exception("Exception during update of permissions") |
|
136 | log.exception("Exception during update of permissions") | |
137 | h.flash(_('Error occurred during update of permissions'), |
|
137 | h.flash(_('Error occurred during update of permissions'), | |
138 | category='error') |
|
138 | category='error') | |
139 |
|
139 | |||
140 | raise HTTPFound(h.route_path('admin_permissions_application')) |
|
140 | raise HTTPFound(h.route_path('admin_permissions_application')) | |
141 |
|
141 | |||
142 | @LoginRequired() |
|
142 | @LoginRequired() | |
143 | @HasPermissionAllDecorator('hg.admin') |
|
143 | @HasPermissionAllDecorator('hg.admin') | |
144 | @view_config( |
|
144 | @view_config( | |
145 | route_name='admin_permissions_object', request_method='GET', |
|
145 | route_name='admin_permissions_object', request_method='GET', | |
146 | renderer='rhodecode:templates/admin/permissions/permissions.mako') |
|
146 | renderer='rhodecode:templates/admin/permissions/permissions.mako') | |
147 | def permissions_objects(self): |
|
147 | def permissions_objects(self): | |
148 | c = self.load_default_context() |
|
148 | c = self.load_default_context() | |
149 | c.active = 'objects' |
|
149 | c.active = 'objects' | |
150 |
|
150 | |||
151 | c.user = User.get_default_user(refresh=True) |
|
151 | c.user = User.get_default_user(refresh=True) | |
152 | defaults = {} |
|
152 | defaults = {} | |
153 | defaults.update(c.user.get_default_perms()) |
|
153 | defaults.update(c.user.get_default_perms()) | |
154 |
|
154 | |||
155 | data = render( |
|
155 | data = render( | |
156 | 'rhodecode:templates/admin/permissions/permissions.mako', |
|
156 | 'rhodecode:templates/admin/permissions/permissions.mako', | |
157 | self._get_template_context(c), self.request) |
|
157 | self._get_template_context(c), self.request) | |
158 | html = formencode.htmlfill.render( |
|
158 | html = formencode.htmlfill.render( | |
159 | data, |
|
159 | data, | |
160 | defaults=defaults, |
|
160 | defaults=defaults, | |
161 | encoding="UTF-8", |
|
161 | encoding="UTF-8", | |
162 | force_defaults=False |
|
162 | force_defaults=False | |
163 | ) |
|
163 | ) | |
164 | return Response(html) |
|
164 | return Response(html) | |
165 |
|
165 | |||
166 | @LoginRequired() |
|
166 | @LoginRequired() | |
167 | @HasPermissionAllDecorator('hg.admin') |
|
167 | @HasPermissionAllDecorator('hg.admin') | |
168 | @CSRFRequired() |
|
168 | @CSRFRequired() | |
169 | @view_config( |
|
169 | @view_config( | |
170 | route_name='admin_permissions_object_update', request_method='POST', |
|
170 | route_name='admin_permissions_object_update', request_method='POST', | |
171 | renderer='rhodecode:templates/admin/permissions/permissions.mako') |
|
171 | renderer='rhodecode:templates/admin/permissions/permissions.mako') | |
172 | def permissions_objects_update(self): |
|
172 | def permissions_objects_update(self): | |
173 | _ = self.request.translate |
|
173 | _ = self.request.translate | |
174 | c = self.load_default_context() |
|
174 | c = self.load_default_context() | |
175 | c.active = 'objects' |
|
175 | c.active = 'objects' | |
176 |
|
176 | |||
177 | _form = ObjectPermissionsForm( |
|
177 | _form = ObjectPermissionsForm( | |
178 | [x[0] for x in c.repo_perms_choices], |
|
178 | [x[0] for x in c.repo_perms_choices], | |
179 | [x[0] for x in c.group_perms_choices], |
|
179 | [x[0] for x in c.group_perms_choices], | |
180 | [x[0] for x in c.user_group_perms_choices])() |
|
180 | [x[0] for x in c.user_group_perms_choices])() | |
181 |
|
181 | |||
182 | try: |
|
182 | try: | |
183 | form_result = _form.to_python(dict(self.request.POST)) |
|
183 | form_result = _form.to_python(dict(self.request.POST)) | |
184 | form_result.update({'perm_user_name': User.DEFAULT_USER}) |
|
184 | form_result.update({'perm_user_name': User.DEFAULT_USER}) | |
185 | PermissionModel().update_object_permissions(form_result) |
|
185 | PermissionModel().update_object_permissions(form_result) | |
186 |
|
186 | |||
187 | Session().commit() |
|
187 | Session().commit() | |
188 | h.flash(_('Object permissions updated successfully'), |
|
188 | h.flash(_('Object permissions updated successfully'), | |
189 | category='success') |
|
189 | category='success') | |
190 |
|
190 | |||
191 | except formencode.Invalid as errors: |
|
191 | except formencode.Invalid as errors: | |
192 | defaults = errors.value |
|
192 | defaults = errors.value | |
193 |
|
193 | |||
194 | data = render( |
|
194 | data = render( | |
195 | 'rhodecode:templates/admin/permissions/permissions.mako', |
|
195 | 'rhodecode:templates/admin/permissions/permissions.mako', | |
196 | self._get_template_context(c), self.request) |
|
196 | self._get_template_context(c), self.request) | |
197 | html = formencode.htmlfill.render( |
|
197 | html = formencode.htmlfill.render( | |
198 | data, |
|
198 | data, | |
199 | defaults=defaults, |
|
199 | defaults=defaults, | |
200 | errors=errors.error_dict or {}, |
|
200 | errors=errors.error_dict or {}, | |
201 | prefix_error=False, |
|
201 | prefix_error=False, | |
202 | encoding="UTF-8", |
|
202 | encoding="UTF-8", | |
203 | force_defaults=False |
|
203 | force_defaults=False | |
204 | ) |
|
204 | ) | |
205 | return Response(html) |
|
205 | return Response(html) | |
206 | except Exception: |
|
206 | except Exception: | |
207 | log.exception("Exception during update of permissions") |
|
207 | log.exception("Exception during update of permissions") | |
208 | h.flash(_('Error occurred during update of permissions'), |
|
208 | h.flash(_('Error occurred during update of permissions'), | |
209 | category='error') |
|
209 | category='error') | |
210 |
|
210 | |||
211 | raise HTTPFound(h.route_path('admin_permissions_object')) |
|
211 | raise HTTPFound(h.route_path('admin_permissions_object')) | |
212 |
|
212 | |||
213 | @LoginRequired() |
|
213 | @LoginRequired() | |
214 | @HasPermissionAllDecorator('hg.admin') |
|
214 | @HasPermissionAllDecorator('hg.admin') | |
215 | @view_config( |
|
215 | @view_config( | |
216 | route_name='admin_permissions_global', request_method='GET', |
|
216 | route_name='admin_permissions_global', request_method='GET', | |
217 | renderer='rhodecode:templates/admin/permissions/permissions.mako') |
|
217 | renderer='rhodecode:templates/admin/permissions/permissions.mako') | |
218 | def permissions_global(self): |
|
218 | def permissions_global(self): | |
219 | c = self.load_default_context() |
|
219 | c = self.load_default_context() | |
220 | c.active = 'global' |
|
220 | c.active = 'global' | |
221 |
|
221 | |||
222 | c.user = User.get_default_user(refresh=True) |
|
222 | c.user = User.get_default_user(refresh=True) | |
223 | defaults = {} |
|
223 | defaults = {} | |
224 | defaults.update(c.user.get_default_perms()) |
|
224 | defaults.update(c.user.get_default_perms()) | |
225 |
|
225 | |||
226 | data = render( |
|
226 | data = render( | |
227 | 'rhodecode:templates/admin/permissions/permissions.mako', |
|
227 | 'rhodecode:templates/admin/permissions/permissions.mako', | |
228 | self._get_template_context(c), self.request) |
|
228 | self._get_template_context(c), self.request) | |
229 | html = formencode.htmlfill.render( |
|
229 | html = formencode.htmlfill.render( | |
230 | data, |
|
230 | data, | |
231 | defaults=defaults, |
|
231 | defaults=defaults, | |
232 | encoding="UTF-8", |
|
232 | encoding="UTF-8", | |
233 | force_defaults=False |
|
233 | force_defaults=False | |
234 | ) |
|
234 | ) | |
235 | return Response(html) |
|
235 | return Response(html) | |
236 |
|
236 | |||
237 | @LoginRequired() |
|
237 | @LoginRequired() | |
238 | @HasPermissionAllDecorator('hg.admin') |
|
238 | @HasPermissionAllDecorator('hg.admin') | |
239 | @CSRFRequired() |
|
239 | @CSRFRequired() | |
240 | @view_config( |
|
240 | @view_config( | |
241 | route_name='admin_permissions_global_update', request_method='POST', |
|
241 | route_name='admin_permissions_global_update', request_method='POST', | |
242 | renderer='rhodecode:templates/admin/permissions/permissions.mako') |
|
242 | renderer='rhodecode:templates/admin/permissions/permissions.mako') | |
243 | def permissions_global_update(self): |
|
243 | def permissions_global_update(self): | |
244 | _ = self.request.translate |
|
244 | _ = self.request.translate | |
245 | c = self.load_default_context() |
|
245 | c = self.load_default_context() | |
246 | c.active = 'global' |
|
246 | c.active = 'global' | |
247 |
|
247 | |||
248 | _form = UserPermissionsForm( |
|
248 | _form = UserPermissionsForm( | |
249 | [x[0] for x in c.repo_create_choices], |
|
249 | [x[0] for x in c.repo_create_choices], | |
250 | [x[0] for x in c.repo_create_on_write_choices], |
|
250 | [x[0] for x in c.repo_create_on_write_choices], | |
251 | [x[0] for x in c.repo_group_create_choices], |
|
251 | [x[0] for x in c.repo_group_create_choices], | |
252 | [x[0] for x in c.user_group_create_choices], |
|
252 | [x[0] for x in c.user_group_create_choices], | |
253 | [x[0] for x in c.fork_choices], |
|
253 | [x[0] for x in c.fork_choices], | |
254 | [x[0] for x in c.inherit_default_permission_choices])() |
|
254 | [x[0] for x in c.inherit_default_permission_choices])() | |
255 |
|
255 | |||
256 | try: |
|
256 | try: | |
257 | form_result = _form.to_python(dict(self.request.POST)) |
|
257 | form_result = _form.to_python(dict(self.request.POST)) | |
258 | form_result.update({'perm_user_name': User.DEFAULT_USER}) |
|
258 | form_result.update({'perm_user_name': User.DEFAULT_USER}) | |
259 | PermissionModel().update_user_permissions(form_result) |
|
259 | PermissionModel().update_user_permissions(form_result) | |
260 |
|
260 | |||
261 | Session().commit() |
|
261 | Session().commit() | |
262 | h.flash(_('Global permissions updated successfully'), |
|
262 | h.flash(_('Global permissions updated successfully'), | |
263 | category='success') |
|
263 | category='success') | |
264 |
|
264 | |||
265 | except formencode.Invalid as errors: |
|
265 | except formencode.Invalid as errors: | |
266 | defaults = errors.value |
|
266 | defaults = errors.value | |
267 |
|
267 | |||
268 | data = render( |
|
268 | data = render( | |
269 | 'rhodecode:templates/admin/permissions/permissions.mako', |
|
269 | 'rhodecode:templates/admin/permissions/permissions.mako', | |
270 | self._get_template_context(c), self.request) |
|
270 | self._get_template_context(c), self.request) | |
271 | html = formencode.htmlfill.render( |
|
271 | html = formencode.htmlfill.render( | |
272 | data, |
|
272 | data, | |
273 | defaults=defaults, |
|
273 | defaults=defaults, | |
274 | errors=errors.error_dict or {}, |
|
274 | errors=errors.error_dict or {}, | |
275 | prefix_error=False, |
|
275 | prefix_error=False, | |
276 | encoding="UTF-8", |
|
276 | encoding="UTF-8", | |
277 | force_defaults=False |
|
277 | force_defaults=False | |
278 | ) |
|
278 | ) | |
279 | return Response(html) |
|
279 | return Response(html) | |
280 | except Exception: |
|
280 | except Exception: | |
281 | log.exception("Exception during update of permissions") |
|
281 | log.exception("Exception during update of permissions") | |
282 | h.flash(_('Error occurred during update of permissions'), |
|
282 | h.flash(_('Error occurred during update of permissions'), | |
283 | category='error') |
|
283 | category='error') | |
284 |
|
284 | |||
285 | raise HTTPFound(h.route_path('admin_permissions_global')) |
|
285 | raise HTTPFound(h.route_path('admin_permissions_global')) | |
286 |
|
286 | |||
287 | @LoginRequired() |
|
287 | @LoginRequired() | |
288 | @HasPermissionAllDecorator('hg.admin') |
|
288 | @HasPermissionAllDecorator('hg.admin') | |
289 | @view_config( |
|
289 | @view_config( | |
290 | route_name='admin_permissions_ips', request_method='GET', |
|
290 | route_name='admin_permissions_ips', request_method='GET', | |
291 | renderer='rhodecode:templates/admin/permissions/permissions.mako') |
|
291 | renderer='rhodecode:templates/admin/permissions/permissions.mako') | |
292 | def permissions_ips(self): |
|
292 | def permissions_ips(self): | |
293 | c = self.load_default_context() |
|
293 | c = self.load_default_context() | |
294 | c.active = 'ips' |
|
294 | c.active = 'ips' | |
295 |
|
295 | |||
296 | c.user = User.get_default_user(refresh=True) |
|
296 | c.user = User.get_default_user(refresh=True) | |
297 | c.user_ip_map = ( |
|
297 | c.user_ip_map = ( | |
298 | UserIpMap.query().filter(UserIpMap.user == c.user).all()) |
|
298 | UserIpMap.query().filter(UserIpMap.user == c.user).all()) | |
299 |
|
299 | |||
300 | return self._get_template_context(c) |
|
300 | return self._get_template_context(c) | |
301 |
|
301 | |||
302 | @LoginRequired() |
|
302 | @LoginRequired() | |
303 | @HasPermissionAllDecorator('hg.admin') |
|
303 | @HasPermissionAllDecorator('hg.admin') | |
304 | @view_config( |
|
304 | @view_config( | |
305 | route_name='admin_permissions_overview', request_method='GET', |
|
305 | route_name='admin_permissions_overview', request_method='GET', | |
306 | renderer='rhodecode:templates/admin/permissions/permissions.mako') |
|
306 | renderer='rhodecode:templates/admin/permissions/permissions.mako') | |
307 | def permissions_overview(self): |
|
307 | def permissions_overview(self): | |
308 | c = self.load_default_context() |
|
308 | c = self.load_default_context() | |
309 | c.active = 'perms' |
|
309 | c.active = 'perms' | |
310 |
|
310 | |||
311 | c.user = User.get_default_user(refresh=True) |
|
311 | c.user = User.get_default_user(refresh=True) | |
312 | c.perm_user = c.user.AuthUser |
|
312 | c.perm_user = c.user.AuthUser | |
313 | return self._get_template_context(c) |
|
313 | return self._get_template_context(c) | |
314 |
|
314 | |||
315 | @LoginRequired() |
|
315 | @LoginRequired() | |
316 | @HasPermissionAllDecorator('hg.admin') |
|
316 | @HasPermissionAllDecorator('hg.admin') | |
317 | @view_config( |
|
317 | @view_config( | |
318 | route_name='admin_permissions_auth_token_access', request_method='GET', |
|
318 | route_name='admin_permissions_auth_token_access', request_method='GET', | |
319 | renderer='rhodecode:templates/admin/permissions/permissions.mako') |
|
319 | renderer='rhodecode:templates/admin/permissions/permissions.mako') | |
320 | def auth_token_access(self): |
|
320 | def auth_token_access(self): | |
321 | from rhodecode import CONFIG |
|
321 | from rhodecode import CONFIG | |
322 |
|
322 | |||
323 | c = self.load_default_context() |
|
323 | c = self.load_default_context() | |
324 | c.active = 'auth_token_access' |
|
324 | c.active = 'auth_token_access' | |
325 |
|
325 | |||
326 | c.user = User.get_default_user(refresh=True) |
|
326 | c.user = User.get_default_user(refresh=True) | |
327 | c.perm_user = c.user.AuthUser |
|
327 | c.perm_user = c.user.AuthUser | |
328 |
|
328 | |||
329 | mapper = self.request.registry.queryUtility(IRoutesMapper) |
|
329 | mapper = self.request.registry.queryUtility(IRoutesMapper) | |
330 | c.view_data = [] |
|
330 | c.view_data = [] | |
331 |
|
331 | |||
332 | _argument_prog = re.compile('\{(.*?)\}|:\((.*)\)') |
|
332 | _argument_prog = re.compile('\{(.*?)\}|:\((.*)\)') | |
333 | introspector = self.request.registry.introspector |
|
333 | introspector = self.request.registry.introspector | |
334 |
|
334 | |||
335 | view_intr = {} |
|
335 | view_intr = {} | |
336 | for view_data in introspector.get_category('views'): |
|
336 | for view_data in introspector.get_category('views'): | |
337 | intr = view_data['introspectable'] |
|
337 | intr = view_data['introspectable'] | |
338 |
|
338 | |||
339 | if 'route_name' in intr and intr['attr']: |
|
339 | if 'route_name' in intr and intr['attr']: | |
340 |
view_intr[intr['route_name']] = '{} |
|
340 | view_intr[intr['route_name']] = '{}:{}'.format( | |
341 | str(intr['derived_callable'].func_name), intr['attr'] |
|
341 | str(intr['derived_callable'].func_name), intr['attr'] | |
342 | ) |
|
342 | ) | |
343 |
|
343 | |||
344 | c.whitelist_key = 'api_access_controllers_whitelist' |
|
344 | c.whitelist_key = 'api_access_controllers_whitelist' | |
345 | c.whitelist_file = CONFIG.get('__file__') |
|
345 | c.whitelist_file = CONFIG.get('__file__') | |
346 | whitelist_views = aslist( |
|
346 | whitelist_views = aslist( | |
347 | CONFIG.get(c.whitelist_key), sep=',') |
|
347 | CONFIG.get(c.whitelist_key), sep=',') | |
348 |
|
348 | |||
349 | for route_info in mapper.get_routes(): |
|
349 | for route_info in mapper.get_routes(): | |
350 | if not route_info.name.startswith('__'): |
|
350 | if not route_info.name.startswith('__'): | |
351 | routepath = route_info.pattern |
|
351 | routepath = route_info.pattern | |
352 |
|
352 | |||
353 | def replace(matchobj): |
|
353 | def replace(matchobj): | |
354 | if matchobj.group(1): |
|
354 | if matchobj.group(1): | |
355 | return "{%s}" % matchobj.group(1).split(':')[0] |
|
355 | return "{%s}" % matchobj.group(1).split(':')[0] | |
356 | else: |
|
356 | else: | |
357 | return "{%s}" % matchobj.group(2) |
|
357 | return "{%s}" % matchobj.group(2) | |
358 |
|
358 | |||
359 | routepath = _argument_prog.sub(replace, routepath) |
|
359 | routepath = _argument_prog.sub(replace, routepath) | |
360 |
|
360 | |||
361 | if not routepath.startswith('/'): |
|
361 | if not routepath.startswith('/'): | |
362 | routepath = '/' + routepath |
|
362 | routepath = '/' + routepath | |
363 |
|
363 | |||
364 | view_fqn = view_intr.get(route_info.name, 'NOT AVAILABLE') |
|
364 | view_fqn = view_intr.get(route_info.name, 'NOT AVAILABLE') | |
365 | active = view_fqn in whitelist_views |
|
365 | active = view_fqn in whitelist_views | |
366 | c.view_data.append((route_info.name, view_fqn, routepath, active)) |
|
366 | c.view_data.append((route_info.name, view_fqn, routepath, active)) | |
367 |
|
367 | |||
368 | c.whitelist_views = whitelist_views |
|
368 | c.whitelist_views = whitelist_views | |
369 | return self._get_template_context(c) |
|
369 | return self._get_template_context(c) |
General Comments 0
You need to be logged in to leave comments.
Login now