##// END OF EJS Templates
automation: add EE feature placeholder
marcink -
r2637:96836581 default
parent child Browse files
Show More
1 NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,9 b''
1 <div class="panel panel-default">
2 <div class="panel-heading">
3 <h3 class="panel-title">${_('Admin Automation')}</h3>
4 </div>
5 <div class="panel-body">
6 <h4>${_('This feature is available in RhodeCode EE edition only. Contact {sales_email} to obtain a trial license.').format(sales_email='<a href="mailto:sales@rhodecode.com">sales@rhodecode.com</a>')|n}</h4>
7 <img style="width: 100%; height: 100%" src="${h.asset('images/ee_features/admin_automation.png')}"/>
8 </div>
9 </div>
@@ -1,409 +1,414 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2018 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21
22 22 from rhodecode.apps._base import ADMIN_PREFIX
23 23
24 24
25 25 def admin_routes(config):
26 26 """
27 27 Admin prefixed routes
28 28 """
29 29
30 30 config.add_route(
31 31 name='admin_audit_logs',
32 32 pattern='/audit_logs')
33 33
34 34 config.add_route(
35 35 name='admin_audit_log_entry',
36 36 pattern='/audit_logs/{audit_log_id}')
37 37
38 38 config.add_route(
39 39 name='pull_requests_global_0', # backward compat
40 40 pattern='/pull_requests/{pull_request_id:\d+}')
41 41 config.add_route(
42 42 name='pull_requests_global_1', # backward compat
43 43 pattern='/pull-requests/{pull_request_id:\d+}')
44 44 config.add_route(
45 45 name='pull_requests_global',
46 46 pattern='/pull-request/{pull_request_id:\d+}')
47 47
48 48 config.add_route(
49 49 name='admin_settings_open_source',
50 50 pattern='/settings/open_source')
51 51 config.add_route(
52 52 name='admin_settings_vcs_svn_generate_cfg',
53 53 pattern='/settings/vcs/svn_generate_cfg')
54 54
55 55 config.add_route(
56 56 name='admin_settings_system',
57 57 pattern='/settings/system')
58 58 config.add_route(
59 59 name='admin_settings_system_update',
60 60 pattern='/settings/system/updates')
61 61
62 62 config.add_route(
63 63 name='admin_settings_sessions',
64 64 pattern='/settings/sessions')
65 65 config.add_route(
66 66 name='admin_settings_sessions_cleanup',
67 67 pattern='/settings/sessions/cleanup')
68 68
69 69 config.add_route(
70 70 name='admin_settings_process_management',
71 71 pattern='/settings/process_management')
72 72 config.add_route(
73 73 name='admin_settings_process_management_data',
74 74 pattern='/settings/process_management/data')
75 75 config.add_route(
76 76 name='admin_settings_process_management_signal',
77 77 pattern='/settings/process_management/signal')
78 78 config.add_route(
79 79 name='admin_settings_process_management_master_signal',
80 80 pattern='/settings/process_management/master_signal')
81 81
82 82 # default settings
83 83 config.add_route(
84 84 name='admin_defaults_repositories',
85 85 pattern='/defaults/repositories')
86 86 config.add_route(
87 87 name='admin_defaults_repositories_update',
88 88 pattern='/defaults/repositories/update')
89 89
90 90 # admin settings
91 91
92 92 config.add_route(
93 93 name='admin_settings',
94 94 pattern='/settings')
95 95 config.add_route(
96 96 name='admin_settings_update',
97 97 pattern='/settings/update')
98 98
99 99 config.add_route(
100 100 name='admin_settings_global',
101 101 pattern='/settings/global')
102 102 config.add_route(
103 103 name='admin_settings_global_update',
104 104 pattern='/settings/global/update')
105 105
106 106 config.add_route(
107 107 name='admin_settings_vcs',
108 108 pattern='/settings/vcs')
109 109 config.add_route(
110 110 name='admin_settings_vcs_update',
111 111 pattern='/settings/vcs/update')
112 112 config.add_route(
113 113 name='admin_settings_vcs_svn_pattern_delete',
114 114 pattern='/settings/vcs/svn_pattern_delete')
115 115
116 116 config.add_route(
117 117 name='admin_settings_mapping',
118 118 pattern='/settings/mapping')
119 119 config.add_route(
120 120 name='admin_settings_mapping_update',
121 121 pattern='/settings/mapping/update')
122 122
123 123 config.add_route(
124 124 name='admin_settings_visual',
125 125 pattern='/settings/visual')
126 126 config.add_route(
127 127 name='admin_settings_visual_update',
128 128 pattern='/settings/visual/update')
129 129
130 130
131 131 config.add_route(
132 132 name='admin_settings_issuetracker',
133 133 pattern='/settings/issue-tracker')
134 134 config.add_route(
135 135 name='admin_settings_issuetracker_update',
136 136 pattern='/settings/issue-tracker/update')
137 137 config.add_route(
138 138 name='admin_settings_issuetracker_test',
139 139 pattern='/settings/issue-tracker/test')
140 140 config.add_route(
141 141 name='admin_settings_issuetracker_delete',
142 142 pattern='/settings/issue-tracker/delete')
143 143
144 144 config.add_route(
145 145 name='admin_settings_email',
146 146 pattern='/settings/email')
147 147 config.add_route(
148 148 name='admin_settings_email_update',
149 149 pattern='/settings/email/update')
150 150
151 151 config.add_route(
152 152 name='admin_settings_hooks',
153 153 pattern='/settings/hooks')
154 154 config.add_route(
155 155 name='admin_settings_hooks_update',
156 156 pattern='/settings/hooks/update')
157 157 config.add_route(
158 158 name='admin_settings_hooks_delete',
159 159 pattern='/settings/hooks/delete')
160 160
161 161 config.add_route(
162 162 name='admin_settings_search',
163 163 pattern='/settings/search')
164 164
165 165 config.add_route(
166 166 name='admin_settings_labs',
167 167 pattern='/settings/labs')
168 168 config.add_route(
169 169 name='admin_settings_labs_update',
170 170 pattern='/settings/labs/update')
171 171
172 # Automation EE feature
173 config.add_route(
174 'admin_settings_automation',
175 pattern=ADMIN_PREFIX + '/settings/automation')
176
172 177 # global permissions
173 178
174 179 config.add_route(
175 180 name='admin_permissions_application',
176 181 pattern='/permissions/application')
177 182 config.add_route(
178 183 name='admin_permissions_application_update',
179 184 pattern='/permissions/application/update')
180 185
181 186 config.add_route(
182 187 name='admin_permissions_global',
183 188 pattern='/permissions/global')
184 189 config.add_route(
185 190 name='admin_permissions_global_update',
186 191 pattern='/permissions/global/update')
187 192
188 193 config.add_route(
189 194 name='admin_permissions_object',
190 195 pattern='/permissions/object')
191 196 config.add_route(
192 197 name='admin_permissions_object_update',
193 198 pattern='/permissions/object/update')
194 199
195 200 config.add_route(
196 201 name='admin_permissions_ips',
197 202 pattern='/permissions/ips')
198 203
199 204 config.add_route(
200 205 name='admin_permissions_overview',
201 206 pattern='/permissions/overview')
202 207
203 208 config.add_route(
204 209 name='admin_permissions_auth_token_access',
205 210 pattern='/permissions/auth_token_access')
206 211
207 212 config.add_route(
208 213 name='admin_permissions_ssh_keys',
209 214 pattern='/permissions/ssh_keys')
210 215 config.add_route(
211 216 name='admin_permissions_ssh_keys_data',
212 217 pattern='/permissions/ssh_keys/data')
213 218 config.add_route(
214 219 name='admin_permissions_ssh_keys_update',
215 220 pattern='/permissions/ssh_keys/update')
216 221
217 222 # users admin
218 223 config.add_route(
219 224 name='users',
220 225 pattern='/users')
221 226
222 227 config.add_route(
223 228 name='users_data',
224 229 pattern='/users_data')
225 230
226 231 config.add_route(
227 232 name='users_create',
228 233 pattern='/users/create')
229 234
230 235 config.add_route(
231 236 name='users_new',
232 237 pattern='/users/new')
233 238
234 239 # user management
235 240 config.add_route(
236 241 name='user_edit',
237 242 pattern='/users/{user_id:\d+}/edit',
238 243 user_route=True)
239 244 config.add_route(
240 245 name='user_edit_advanced',
241 246 pattern='/users/{user_id:\d+}/edit/advanced',
242 247 user_route=True)
243 248 config.add_route(
244 249 name='user_edit_global_perms',
245 250 pattern='/users/{user_id:\d+}/edit/global_permissions',
246 251 user_route=True)
247 252 config.add_route(
248 253 name='user_edit_global_perms_update',
249 254 pattern='/users/{user_id:\d+}/edit/global_permissions/update',
250 255 user_route=True)
251 256 config.add_route(
252 257 name='user_update',
253 258 pattern='/users/{user_id:\d+}/update',
254 259 user_route=True)
255 260 config.add_route(
256 261 name='user_delete',
257 262 pattern='/users/{user_id:\d+}/delete',
258 263 user_route=True)
259 264 config.add_route(
260 265 name='user_force_password_reset',
261 266 pattern='/users/{user_id:\d+}/password_reset',
262 267 user_route=True)
263 268 config.add_route(
264 269 name='user_create_personal_repo_group',
265 270 pattern='/users/{user_id:\d+}/create_repo_group',
266 271 user_route=True)
267 272
268 273 # user auth tokens
269 274 config.add_route(
270 275 name='edit_user_auth_tokens',
271 276 pattern='/users/{user_id:\d+}/edit/auth_tokens',
272 277 user_route=True)
273 278 config.add_route(
274 279 name='edit_user_auth_tokens_add',
275 280 pattern='/users/{user_id:\d+}/edit/auth_tokens/new',
276 281 user_route=True)
277 282 config.add_route(
278 283 name='edit_user_auth_tokens_delete',
279 284 pattern='/users/{user_id:\d+}/edit/auth_tokens/delete',
280 285 user_route=True)
281 286
282 287 # user ssh keys
283 288 config.add_route(
284 289 name='edit_user_ssh_keys',
285 290 pattern='/users/{user_id:\d+}/edit/ssh_keys',
286 291 user_route=True)
287 292 config.add_route(
288 293 name='edit_user_ssh_keys_generate_keypair',
289 294 pattern='/users/{user_id:\d+}/edit/ssh_keys/generate',
290 295 user_route=True)
291 296 config.add_route(
292 297 name='edit_user_ssh_keys_add',
293 298 pattern='/users/{user_id:\d+}/edit/ssh_keys/new',
294 299 user_route=True)
295 300 config.add_route(
296 301 name='edit_user_ssh_keys_delete',
297 302 pattern='/users/{user_id:\d+}/edit/ssh_keys/delete',
298 303 user_route=True)
299 304
300 305 # user emails
301 306 config.add_route(
302 307 name='edit_user_emails',
303 308 pattern='/users/{user_id:\d+}/edit/emails',
304 309 user_route=True)
305 310 config.add_route(
306 311 name='edit_user_emails_add',
307 312 pattern='/users/{user_id:\d+}/edit/emails/new',
308 313 user_route=True)
309 314 config.add_route(
310 315 name='edit_user_emails_delete',
311 316 pattern='/users/{user_id:\d+}/edit/emails/delete',
312 317 user_route=True)
313 318
314 319 # user IPs
315 320 config.add_route(
316 321 name='edit_user_ips',
317 322 pattern='/users/{user_id:\d+}/edit/ips',
318 323 user_route=True)
319 324 config.add_route(
320 325 name='edit_user_ips_add',
321 326 pattern='/users/{user_id:\d+}/edit/ips/new',
322 327 user_route_with_default=True) # enabled for default user too
323 328 config.add_route(
324 329 name='edit_user_ips_delete',
325 330 pattern='/users/{user_id:\d+}/edit/ips/delete',
326 331 user_route_with_default=True) # enabled for default user too
327 332
328 333 # user perms
329 334 config.add_route(
330 335 name='edit_user_perms_summary',
331 336 pattern='/users/{user_id:\d+}/edit/permissions_summary',
332 337 user_route=True)
333 338 config.add_route(
334 339 name='edit_user_perms_summary_json',
335 340 pattern='/users/{user_id:\d+}/edit/permissions_summary/json',
336 341 user_route=True)
337 342
338 343 # user user groups management
339 344 config.add_route(
340 345 name='edit_user_groups_management',
341 346 pattern='/users/{user_id:\d+}/edit/groups_management',
342 347 user_route=True)
343 348
344 349 config.add_route(
345 350 name='edit_user_groups_management_updates',
346 351 pattern='/users/{user_id:\d+}/edit/edit_user_groups_management/updates',
347 352 user_route=True)
348 353
349 354 # user audit logs
350 355 config.add_route(
351 356 name='edit_user_audit_logs',
352 357 pattern='/users/{user_id:\d+}/edit/audit', user_route=True)
353 358
354 359 # user-groups admin
355 360 config.add_route(
356 361 name='user_groups',
357 362 pattern='/user_groups')
358 363
359 364 config.add_route(
360 365 name='user_groups_data',
361 366 pattern='/user_groups_data')
362 367
363 368 config.add_route(
364 369 name='user_groups_new',
365 370 pattern='/user_groups/new')
366 371
367 372 config.add_route(
368 373 name='user_groups_create',
369 374 pattern='/user_groups/create')
370 375
371 376 # repos admin
372 377 config.add_route(
373 378 name='repos',
374 379 pattern='/repos')
375 380
376 381 config.add_route(
377 382 name='repo_new',
378 383 pattern='/repos/new')
379 384
380 385 config.add_route(
381 386 name='repo_create',
382 387 pattern='/repos/create')
383 388
384 389 # repo groups admin
385 390 config.add_route(
386 391 name='repo_groups',
387 392 pattern='/repo_groups')
388 393
389 394 config.add_route(
390 395 name='repo_group_new',
391 396 pattern='/repo_group/new')
392 397
393 398 config.add_route(
394 399 name='repo_group_create',
395 400 pattern='/repo_group/create')
396 401
397 402
398 403 def includeme(config):
399 404 from rhodecode.apps.admin.navigation import includeme as nav_includeme
400 405
401 406 # Create admin navigation registry and add it to the pyramid registry.
402 407 nav_includeme(config)
403 408
404 409 # main admin routes
405 410 config.add_route(name='admin_home', pattern=ADMIN_PREFIX)
406 411 config.include(admin_routes, route_prefix=ADMIN_PREFIX)
407 412
408 413 # Scan module for configuration decorators.
409 414 config.scan('.views', ignore='.tests')
@@ -1,143 +1,144 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2018 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21
22 22 import logging
23 23 import collections
24 24
25 25 from zope.interface import implementer
26 26
27 27 from rhodecode.apps.admin.interfaces import IAdminNavigationRegistry
28 28 from rhodecode.lib.utils2 import str2bool
29 29 from rhodecode.translation import _
30 30
31 31
32 32 log = logging.getLogger(__name__)
33 33
34 34 NavListEntry = collections.namedtuple(
35 35 'NavListEntry', ['key', 'name', 'url', 'active_list'])
36 36
37 37
38 38 class NavEntry(object):
39 39 """
40 40 Represents an entry in the admin navigation.
41 41
42 42 :param key: Unique identifier used to store reference in an OrderedDict.
43 43 :param name: Display name, usually a translation string.
44 44 :param view_name: Name of the view, used generate the URL.
45 45 :param active_list: list of urls that we select active for this element
46 46 """
47 47
48 48 def __init__(self, key, name, view_name, active_list=None):
49 49 self.key = key
50 50 self.name = name
51 51 self.view_name = view_name
52 52 self._active_list = active_list or []
53 53
54 54 def generate_url(self, request):
55 55 return request.route_path(self.view_name)
56 56
57 57 def get_localized_name(self, request):
58 58 return request.translate(self.name)
59 59
60 60 @property
61 61 def active_list(self):
62 62 active_list = [self.key]
63 63 if self._active_list:
64 64 active_list = self._active_list
65 65 return active_list
66 66
67 67
68 68 @implementer(IAdminNavigationRegistry)
69 69 class NavigationRegistry(object):
70 70
71 71 _base_entries = [
72 72 NavEntry('global', _('Global'),
73 73 'admin_settings_global'),
74 74 NavEntry('vcs', _('VCS'),
75 75 'admin_settings_vcs'),
76 76 NavEntry('visual', _('Visual'),
77 77 'admin_settings_visual'),
78 78 NavEntry('mapping', _('Remap and Rescan'),
79 79 'admin_settings_mapping'),
80 80 NavEntry('issuetracker', _('Issue Tracker'),
81 81 'admin_settings_issuetracker'),
82 82 NavEntry('email', _('Email'),
83 83 'admin_settings_email'),
84 84 NavEntry('hooks', _('Hooks'),
85 85 'admin_settings_hooks'),
86 86 NavEntry('search', _('Full Text Search'),
87 87 'admin_settings_search'),
88 88 NavEntry('integrations', _('Integrations'),
89 89 'global_integrations_home'),
90 90 NavEntry('system', _('System Info'),
91 91 'admin_settings_system'),
92 92 NavEntry('process_management', _('Processes'),
93 93 'admin_settings_process_management'),
94 94 NavEntry('sessions', _('User Sessions'),
95 95 'admin_settings_sessions'),
96 96 NavEntry('open_source', _('Open Source Licenses'),
97 97 'admin_settings_open_source'),
98
98 NavEntry('automation', _('Automation'),
99 'admin_settings_automation')
99 100 ]
100 101
101 102 _labs_entry = NavEntry('labs', _('Labs'),
102 103 'admin_settings_labs')
103 104
104 105 def __init__(self, labs_active=False):
105 106 self._registered_entries = collections.OrderedDict()
106 107 for item in self.__class__._base_entries:
107 108 self._registered_entries[item.key] = item
108 109
109 110 if labs_active:
110 111 self.add_entry(self._labs_entry)
111 112
112 113 def add_entry(self, entry):
113 114 self._registered_entries[entry.key] = entry
114 115
115 116 def get_navlist(self, request):
116 117 navlist = [NavListEntry(i.key, i.get_localized_name(request),
117 118 i.generate_url(request), i.active_list)
118 119 for i in self._registered_entries.values()]
119 120 return navlist
120 121
121 122
122 123 def navigation_registry(request, registry=None):
123 124 """
124 125 Helper that returns the admin navigation registry.
125 126 """
126 127 pyramid_registry = registry or request.registry
127 128 nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry)
128 129 return nav_registry
129 130
130 131
131 132 def navigation_list(request):
132 133 """
133 134 Helper that returns the admin navigation as list of NavListEntry objects.
134 135 """
135 136 return navigation_registry(request).get_navlist(request)
136 137
137 138
138 139 def includeme(config):
139 140 # Create admin navigation registry and add it to the pyramid registry.
140 141 settings = config.get_settings()
141 142 labs_active = str2bool(settings.get('labs_settings_active', False))
142 143 navigation_registry = NavigationRegistry(labs_active=labs_active)
143 144 config.registry.registerUtility(navigation_registry) No newline at end of file
@@ -1,770 +1,781 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2018 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21
22 22 import logging
23 23 import collections
24 24
25 25 import datetime
26 26 import formencode
27 27 import formencode.htmlfill
28 28
29 29 import rhodecode
30 30 from pyramid.view import view_config
31 31 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
32 32 from pyramid.renderers import render
33 33 from pyramid.response import Response
34 34
35 35 from rhodecode.apps._base import BaseAppView
36 36 from rhodecode.apps.admin.navigation import navigation_list
37 37 from rhodecode.apps.svn_support.config_keys import generate_config
38 38 from rhodecode.lib import helpers as h
39 39 from rhodecode.lib.auth import (
40 40 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
41 41 from rhodecode.lib.celerylib import tasks, run_task
42 42 from rhodecode.lib.utils import repo2db_mapper
43 43 from rhodecode.lib.utils2 import str2bool, safe_unicode, AttributeDict
44 44 from rhodecode.lib.index import searcher_from_config
45 45
46 46 from rhodecode.model.db import RhodeCodeUi, Repository
47 47 from rhodecode.model.forms import (ApplicationSettingsForm,
48 48 ApplicationUiSettingsForm, ApplicationVisualisationForm,
49 49 LabsSettingsForm, IssueTrackerPatternsForm)
50 50 from rhodecode.model.repo_group import RepoGroupModel
51 51
52 52 from rhodecode.model.scm import ScmModel
53 53 from rhodecode.model.notification import EmailNotificationModel
54 54 from rhodecode.model.meta import Session
55 55 from rhodecode.model.settings import (
56 56 IssueTrackerSettingsModel, VcsSettingsModel, SettingNotFound,
57 57 SettingsModel)
58 58
59 59
60 60 log = logging.getLogger(__name__)
61 61
62 62
63 63 class AdminSettingsView(BaseAppView):
64 64
65 65 def load_default_context(self):
66 66 c = self._get_local_tmpl_context()
67 67 c.labs_active = str2bool(
68 68 rhodecode.CONFIG.get('labs_settings_active', 'true'))
69 69 c.navlist = navigation_list(self.request)
70 70
71 71 return c
72 72
73 73 @classmethod
74 74 def _get_ui_settings(cls):
75 75 ret = RhodeCodeUi.query().all()
76 76
77 77 if not ret:
78 78 raise Exception('Could not get application ui settings !')
79 79 settings = {}
80 80 for each in ret:
81 81 k = each.ui_key
82 82 v = each.ui_value
83 83 if k == '/':
84 84 k = 'root_path'
85 85
86 86 if k in ['push_ssl', 'publish', 'enabled']:
87 87 v = str2bool(v)
88 88
89 89 if k.find('.') != -1:
90 90 k = k.replace('.', '_')
91 91
92 92 if each.ui_section in ['hooks', 'extensions']:
93 93 v = each.ui_active
94 94
95 95 settings[each.ui_section + '_' + k] = v
96 96 return settings
97 97
98 98 @classmethod
99 99 def _form_defaults(cls):
100 100 defaults = SettingsModel().get_all_settings()
101 101 defaults.update(cls._get_ui_settings())
102 102
103 103 defaults.update({
104 104 'new_svn_branch': '',
105 105 'new_svn_tag': '',
106 106 })
107 107 return defaults
108 108
109 109 @LoginRequired()
110 110 @HasPermissionAllDecorator('hg.admin')
111 111 @view_config(
112 112 route_name='admin_settings_vcs', request_method='GET',
113 113 renderer='rhodecode:templates/admin/settings/settings.mako')
114 114 def settings_vcs(self):
115 115 c = self.load_default_context()
116 116 c.active = 'vcs'
117 117 model = VcsSettingsModel()
118 118 c.svn_branch_patterns = model.get_global_svn_branch_patterns()
119 119 c.svn_tag_patterns = model.get_global_svn_tag_patterns()
120 120
121 121 settings = self.request.registry.settings
122 122 c.svn_proxy_generate_config = settings[generate_config]
123 123
124 124 defaults = self._form_defaults()
125 125
126 126 model.create_largeobjects_dirs_if_needed(defaults['paths_root_path'])
127 127
128 128 data = render('rhodecode:templates/admin/settings/settings.mako',
129 129 self._get_template_context(c), self.request)
130 130 html = formencode.htmlfill.render(
131 131 data,
132 132 defaults=defaults,
133 133 encoding="UTF-8",
134 134 force_defaults=False
135 135 )
136 136 return Response(html)
137 137
138 138 @LoginRequired()
139 139 @HasPermissionAllDecorator('hg.admin')
140 140 @CSRFRequired()
141 141 @view_config(
142 142 route_name='admin_settings_vcs_update', request_method='POST',
143 143 renderer='rhodecode:templates/admin/settings/settings.mako')
144 144 def settings_vcs_update(self):
145 145 _ = self.request.translate
146 146 c = self.load_default_context()
147 147 c.active = 'vcs'
148 148
149 149 model = VcsSettingsModel()
150 150 c.svn_branch_patterns = model.get_global_svn_branch_patterns()
151 151 c.svn_tag_patterns = model.get_global_svn_tag_patterns()
152 152
153 153 settings = self.request.registry.settings
154 154 c.svn_proxy_generate_config = settings[generate_config]
155 155
156 156 application_form = ApplicationUiSettingsForm(self.request.translate)()
157 157
158 158 try:
159 159 form_result = application_form.to_python(dict(self.request.POST))
160 160 except formencode.Invalid as errors:
161 161 h.flash(
162 162 _("Some form inputs contain invalid data."),
163 163 category='error')
164 164 data = render('rhodecode:templates/admin/settings/settings.mako',
165 165 self._get_template_context(c), self.request)
166 166 html = formencode.htmlfill.render(
167 167 data,
168 168 defaults=errors.value,
169 169 errors=errors.error_dict or {},
170 170 prefix_error=False,
171 171 encoding="UTF-8",
172 172 force_defaults=False
173 173 )
174 174 return Response(html)
175 175
176 176 try:
177 177 if c.visual.allow_repo_location_change:
178 178 model.update_global_path_setting(
179 179 form_result['paths_root_path'])
180 180
181 181 model.update_global_ssl_setting(form_result['web_push_ssl'])
182 182 model.update_global_hook_settings(form_result)
183 183
184 184 model.create_or_update_global_svn_settings(form_result)
185 185 model.create_or_update_global_hg_settings(form_result)
186 186 model.create_or_update_global_git_settings(form_result)
187 187 model.create_or_update_global_pr_settings(form_result)
188 188 except Exception:
189 189 log.exception("Exception while updating settings")
190 190 h.flash(_('Error occurred during updating '
191 191 'application settings'), category='error')
192 192 else:
193 193 Session().commit()
194 194 h.flash(_('Updated VCS settings'), category='success')
195 195 raise HTTPFound(h.route_path('admin_settings_vcs'))
196 196
197 197 data = render('rhodecode:templates/admin/settings/settings.mako',
198 198 self._get_template_context(c), self.request)
199 199 html = formencode.htmlfill.render(
200 200 data,
201 201 defaults=self._form_defaults(),
202 202 encoding="UTF-8",
203 203 force_defaults=False
204 204 )
205 205 return Response(html)
206 206
207 207 @LoginRequired()
208 208 @HasPermissionAllDecorator('hg.admin')
209 209 @CSRFRequired()
210 210 @view_config(
211 211 route_name='admin_settings_vcs_svn_pattern_delete', request_method='POST',
212 212 renderer='json_ext', xhr=True)
213 213 def settings_vcs_delete_svn_pattern(self):
214 214 delete_pattern_id = self.request.POST.get('delete_svn_pattern')
215 215 model = VcsSettingsModel()
216 216 try:
217 217 model.delete_global_svn_pattern(delete_pattern_id)
218 218 except SettingNotFound:
219 219 log.exception(
220 220 'Failed to delete svn_pattern with id %s', delete_pattern_id)
221 221 raise HTTPNotFound()
222 222
223 223 Session().commit()
224 224 return True
225 225
226 226 @LoginRequired()
227 227 @HasPermissionAllDecorator('hg.admin')
228 228 @view_config(
229 229 route_name='admin_settings_mapping', request_method='GET',
230 230 renderer='rhodecode:templates/admin/settings/settings.mako')
231 231 def settings_mapping(self):
232 232 c = self.load_default_context()
233 233 c.active = 'mapping'
234 234
235 235 data = render('rhodecode:templates/admin/settings/settings.mako',
236 236 self._get_template_context(c), self.request)
237 237 html = formencode.htmlfill.render(
238 238 data,
239 239 defaults=self._form_defaults(),
240 240 encoding="UTF-8",
241 241 force_defaults=False
242 242 )
243 243 return Response(html)
244 244
245 245 @LoginRequired()
246 246 @HasPermissionAllDecorator('hg.admin')
247 247 @CSRFRequired()
248 248 @view_config(
249 249 route_name='admin_settings_mapping_update', request_method='POST',
250 250 renderer='rhodecode:templates/admin/settings/settings.mako')
251 251 def settings_mapping_update(self):
252 252 _ = self.request.translate
253 253 c = self.load_default_context()
254 254 c.active = 'mapping'
255 255 rm_obsolete = self.request.POST.get('destroy', False)
256 256 invalidate_cache = self.request.POST.get('invalidate', False)
257 257 log.debug(
258 258 'rescanning repo location with destroy obsolete=%s', rm_obsolete)
259 259
260 260 if invalidate_cache:
261 261 log.debug('invalidating all repositories cache')
262 262 for repo in Repository.get_all():
263 263 ScmModel().mark_for_invalidation(repo.repo_name, delete=True)
264 264
265 265 filesystem_repos = ScmModel().repo_scan()
266 266 added, removed = repo2db_mapper(filesystem_repos, rm_obsolete)
267 267 _repr = lambda l: ', '.join(map(safe_unicode, l)) or '-'
268 268 h.flash(_('Repositories successfully '
269 269 'rescanned added: %s ; removed: %s') %
270 270 (_repr(added), _repr(removed)),
271 271 category='success')
272 272 raise HTTPFound(h.route_path('admin_settings_mapping'))
273 273
274 274 @LoginRequired()
275 275 @HasPermissionAllDecorator('hg.admin')
276 276 @view_config(
277 277 route_name='admin_settings', request_method='GET',
278 278 renderer='rhodecode:templates/admin/settings/settings.mako')
279 279 @view_config(
280 280 route_name='admin_settings_global', request_method='GET',
281 281 renderer='rhodecode:templates/admin/settings/settings.mako')
282 282 def settings_global(self):
283 283 c = self.load_default_context()
284 284 c.active = 'global'
285 285 c.personal_repo_group_default_pattern = RepoGroupModel()\
286 286 .get_personal_group_name_pattern()
287 287
288 288 data = render('rhodecode:templates/admin/settings/settings.mako',
289 289 self._get_template_context(c), self.request)
290 290 html = formencode.htmlfill.render(
291 291 data,
292 292 defaults=self._form_defaults(),
293 293 encoding="UTF-8",
294 294 force_defaults=False
295 295 )
296 296 return Response(html)
297 297
298 298 @LoginRequired()
299 299 @HasPermissionAllDecorator('hg.admin')
300 300 @CSRFRequired()
301 301 @view_config(
302 302 route_name='admin_settings_update', request_method='POST',
303 303 renderer='rhodecode:templates/admin/settings/settings.mako')
304 304 @view_config(
305 305 route_name='admin_settings_global_update', request_method='POST',
306 306 renderer='rhodecode:templates/admin/settings/settings.mako')
307 307 def settings_global_update(self):
308 308 _ = self.request.translate
309 309 c = self.load_default_context()
310 310 c.active = 'global'
311 311 c.personal_repo_group_default_pattern = RepoGroupModel()\
312 312 .get_personal_group_name_pattern()
313 313 application_form = ApplicationSettingsForm(self.request.translate)()
314 314 try:
315 315 form_result = application_form.to_python(dict(self.request.POST))
316 316 except formencode.Invalid as errors:
317 317 h.flash(
318 318 _("Some form inputs contain invalid data."),
319 319 category='error')
320 320 data = render('rhodecode:templates/admin/settings/settings.mako',
321 321 self._get_template_context(c), self.request)
322 322 html = formencode.htmlfill.render(
323 323 data,
324 324 defaults=errors.value,
325 325 errors=errors.error_dict or {},
326 326 prefix_error=False,
327 327 encoding="UTF-8",
328 328 force_defaults=False
329 329 )
330 330 return Response(html)
331 331
332 332 settings = [
333 333 ('title', 'rhodecode_title', 'unicode'),
334 334 ('realm', 'rhodecode_realm', 'unicode'),
335 335 ('pre_code', 'rhodecode_pre_code', 'unicode'),
336 336 ('post_code', 'rhodecode_post_code', 'unicode'),
337 337 ('captcha_public_key', 'rhodecode_captcha_public_key', 'unicode'),
338 338 ('captcha_private_key', 'rhodecode_captcha_private_key', 'unicode'),
339 339 ('create_personal_repo_group', 'rhodecode_create_personal_repo_group', 'bool'),
340 340 ('personal_repo_group_pattern', 'rhodecode_personal_repo_group_pattern', 'unicode'),
341 341 ]
342 342 try:
343 343 for setting, form_key, type_ in settings:
344 344 sett = SettingsModel().create_or_update_setting(
345 345 setting, form_result[form_key], type_)
346 346 Session().add(sett)
347 347
348 348 Session().commit()
349 349 SettingsModel().invalidate_settings_cache()
350 350 h.flash(_('Updated application settings'), category='success')
351 351 except Exception:
352 352 log.exception("Exception while updating application settings")
353 353 h.flash(
354 354 _('Error occurred during updating application settings'),
355 355 category='error')
356 356
357 357 raise HTTPFound(h.route_path('admin_settings_global'))
358 358
359 359 @LoginRequired()
360 360 @HasPermissionAllDecorator('hg.admin')
361 361 @view_config(
362 362 route_name='admin_settings_visual', request_method='GET',
363 363 renderer='rhodecode:templates/admin/settings/settings.mako')
364 364 def settings_visual(self):
365 365 c = self.load_default_context()
366 366 c.active = 'visual'
367 367
368 368 data = render('rhodecode:templates/admin/settings/settings.mako',
369 369 self._get_template_context(c), self.request)
370 370 html = formencode.htmlfill.render(
371 371 data,
372 372 defaults=self._form_defaults(),
373 373 encoding="UTF-8",
374 374 force_defaults=False
375 375 )
376 376 return Response(html)
377 377
378 378 @LoginRequired()
379 379 @HasPermissionAllDecorator('hg.admin')
380 380 @CSRFRequired()
381 381 @view_config(
382 382 route_name='admin_settings_visual_update', request_method='POST',
383 383 renderer='rhodecode:templates/admin/settings/settings.mako')
384 384 def settings_visual_update(self):
385 385 _ = self.request.translate
386 386 c = self.load_default_context()
387 387 c.active = 'visual'
388 388 application_form = ApplicationVisualisationForm(self.request.translate)()
389 389 try:
390 390 form_result = application_form.to_python(dict(self.request.POST))
391 391 except formencode.Invalid as errors:
392 392 h.flash(
393 393 _("Some form inputs contain invalid data."),
394 394 category='error')
395 395 data = render('rhodecode:templates/admin/settings/settings.mako',
396 396 self._get_template_context(c), self.request)
397 397 html = formencode.htmlfill.render(
398 398 data,
399 399 defaults=errors.value,
400 400 errors=errors.error_dict or {},
401 401 prefix_error=False,
402 402 encoding="UTF-8",
403 403 force_defaults=False
404 404 )
405 405 return Response(html)
406 406
407 407 try:
408 408 settings = [
409 409 ('show_public_icon', 'rhodecode_show_public_icon', 'bool'),
410 410 ('show_private_icon', 'rhodecode_show_private_icon', 'bool'),
411 411 ('stylify_metatags', 'rhodecode_stylify_metatags', 'bool'),
412 412 ('repository_fields', 'rhodecode_repository_fields', 'bool'),
413 413 ('dashboard_items', 'rhodecode_dashboard_items', 'int'),
414 414 ('admin_grid_items', 'rhodecode_admin_grid_items', 'int'),
415 415 ('show_version', 'rhodecode_show_version', 'bool'),
416 416 ('use_gravatar', 'rhodecode_use_gravatar', 'bool'),
417 417 ('markup_renderer', 'rhodecode_markup_renderer', 'unicode'),
418 418 ('gravatar_url', 'rhodecode_gravatar_url', 'unicode'),
419 419 ('clone_uri_tmpl', 'rhodecode_clone_uri_tmpl', 'unicode'),
420 420 ('clone_uri_ssh_tmpl', 'rhodecode_clone_uri_ssh_tmpl', 'unicode'),
421 421 ('support_url', 'rhodecode_support_url', 'unicode'),
422 422 ('show_revision_number', 'rhodecode_show_revision_number', 'bool'),
423 423 ('show_sha_length', 'rhodecode_show_sha_length', 'int'),
424 424 ]
425 425 for setting, form_key, type_ in settings:
426 426 sett = SettingsModel().create_or_update_setting(
427 427 setting, form_result[form_key], type_)
428 428 Session().add(sett)
429 429
430 430 Session().commit()
431 431 SettingsModel().invalidate_settings_cache()
432 432 h.flash(_('Updated visualisation settings'), category='success')
433 433 except Exception:
434 434 log.exception("Exception updating visualization settings")
435 435 h.flash(_('Error occurred during updating '
436 436 'visualisation settings'),
437 437 category='error')
438 438
439 439 raise HTTPFound(h.route_path('admin_settings_visual'))
440 440
441 441 @LoginRequired()
442 442 @HasPermissionAllDecorator('hg.admin')
443 443 @view_config(
444 444 route_name='admin_settings_issuetracker', request_method='GET',
445 445 renderer='rhodecode:templates/admin/settings/settings.mako')
446 446 def settings_issuetracker(self):
447 447 c = self.load_default_context()
448 448 c.active = 'issuetracker'
449 449 defaults = SettingsModel().get_all_settings()
450 450
451 451 entry_key = 'rhodecode_issuetracker_pat_'
452 452
453 453 c.issuetracker_entries = {}
454 454 for k, v in defaults.items():
455 455 if k.startswith(entry_key):
456 456 uid = k[len(entry_key):]
457 457 c.issuetracker_entries[uid] = None
458 458
459 459 for uid in c.issuetracker_entries:
460 460 c.issuetracker_entries[uid] = AttributeDict({
461 461 'pat': defaults.get('rhodecode_issuetracker_pat_' + uid),
462 462 'url': defaults.get('rhodecode_issuetracker_url_' + uid),
463 463 'pref': defaults.get('rhodecode_issuetracker_pref_' + uid),
464 464 'desc': defaults.get('rhodecode_issuetracker_desc_' + uid),
465 465 })
466 466
467 467 return self._get_template_context(c)
468 468
469 469 @LoginRequired()
470 470 @HasPermissionAllDecorator('hg.admin')
471 471 @CSRFRequired()
472 472 @view_config(
473 473 route_name='admin_settings_issuetracker_test', request_method='POST',
474 474 renderer='string', xhr=True)
475 475 def settings_issuetracker_test(self):
476 476 return h.urlify_commit_message(
477 477 self.request.POST.get('test_text', ''),
478 478 'repo_group/test_repo1')
479 479
480 480 @LoginRequired()
481 481 @HasPermissionAllDecorator('hg.admin')
482 482 @CSRFRequired()
483 483 @view_config(
484 484 route_name='admin_settings_issuetracker_update', request_method='POST',
485 485 renderer='rhodecode:templates/admin/settings/settings.mako')
486 486 def settings_issuetracker_update(self):
487 487 _ = self.request.translate
488 488 self.load_default_context()
489 489 settings_model = IssueTrackerSettingsModel()
490 490
491 491 try:
492 492 form = IssueTrackerPatternsForm(self.request.translate)()
493 493 data = form.to_python(self.request.POST)
494 494 except formencode.Invalid as errors:
495 495 log.exception('Failed to add new pattern')
496 496 error = errors
497 497 h.flash(_('Invalid issue tracker pattern: {}'.format(error)),
498 498 category='error')
499 499 raise HTTPFound(h.route_path('admin_settings_issuetracker'))
500 500
501 501 if data:
502 502 for uid in data.get('delete_patterns', []):
503 503 settings_model.delete_entries(uid)
504 504
505 505 for pattern in data.get('patterns', []):
506 506 for setting, value, type_ in pattern:
507 507 sett = settings_model.create_or_update_setting(
508 508 setting, value, type_)
509 509 Session().add(sett)
510 510
511 511 Session().commit()
512 512
513 513 SettingsModel().invalidate_settings_cache()
514 514 h.flash(_('Updated issue tracker entries'), category='success')
515 515 raise HTTPFound(h.route_path('admin_settings_issuetracker'))
516 516
517 517 @LoginRequired()
518 518 @HasPermissionAllDecorator('hg.admin')
519 519 @CSRFRequired()
520 520 @view_config(
521 521 route_name='admin_settings_issuetracker_delete', request_method='POST',
522 522 renderer='rhodecode:templates/admin/settings/settings.mako')
523 523 def settings_issuetracker_delete(self):
524 524 _ = self.request.translate
525 525 self.load_default_context()
526 526 uid = self.request.POST.get('uid')
527 527 try:
528 528 IssueTrackerSettingsModel().delete_entries(uid)
529 529 except Exception:
530 530 log.exception('Failed to delete issue tracker setting %s', uid)
531 531 raise HTTPNotFound()
532 532 h.flash(_('Removed issue tracker entry'), category='success')
533 533 raise HTTPFound(h.route_path('admin_settings_issuetracker'))
534 534
535 535 @LoginRequired()
536 536 @HasPermissionAllDecorator('hg.admin')
537 537 @view_config(
538 538 route_name='admin_settings_email', request_method='GET',
539 539 renderer='rhodecode:templates/admin/settings/settings.mako')
540 540 def settings_email(self):
541 541 c = self.load_default_context()
542 542 c.active = 'email'
543 543 c.rhodecode_ini = rhodecode.CONFIG
544 544
545 545 data = render('rhodecode:templates/admin/settings/settings.mako',
546 546 self._get_template_context(c), self.request)
547 547 html = formencode.htmlfill.render(
548 548 data,
549 549 defaults=self._form_defaults(),
550 550 encoding="UTF-8",
551 551 force_defaults=False
552 552 )
553 553 return Response(html)
554 554
555 555 @LoginRequired()
556 556 @HasPermissionAllDecorator('hg.admin')
557 557 @CSRFRequired()
558 558 @view_config(
559 559 route_name='admin_settings_email_update', request_method='POST',
560 560 renderer='rhodecode:templates/admin/settings/settings.mako')
561 561 def settings_email_update(self):
562 562 _ = self.request.translate
563 563 c = self.load_default_context()
564 564 c.active = 'email'
565 565
566 566 test_email = self.request.POST.get('test_email')
567 567
568 568 if not test_email:
569 569 h.flash(_('Please enter email address'), category='error')
570 570 raise HTTPFound(h.route_path('admin_settings_email'))
571 571
572 572 email_kwargs = {
573 573 'date': datetime.datetime.now(),
574 574 'user': c.rhodecode_user,
575 575 'rhodecode_version': c.rhodecode_version
576 576 }
577 577
578 578 (subject, headers, email_body,
579 579 email_body_plaintext) = EmailNotificationModel().render_email(
580 580 EmailNotificationModel.TYPE_EMAIL_TEST, **email_kwargs)
581 581
582 582 recipients = [test_email] if test_email else None
583 583
584 584 run_task(tasks.send_email, recipients, subject,
585 585 email_body_plaintext, email_body)
586 586
587 587 h.flash(_('Send email task created'), category='success')
588 588 raise HTTPFound(h.route_path('admin_settings_email'))
589 589
590 590 @LoginRequired()
591 591 @HasPermissionAllDecorator('hg.admin')
592 592 @view_config(
593 593 route_name='admin_settings_hooks', request_method='GET',
594 594 renderer='rhodecode:templates/admin/settings/settings.mako')
595 595 def settings_hooks(self):
596 596 c = self.load_default_context()
597 597 c.active = 'hooks'
598 598
599 599 model = SettingsModel()
600 600 c.hooks = model.get_builtin_hooks()
601 601 c.custom_hooks = model.get_custom_hooks()
602 602
603 603 data = render('rhodecode:templates/admin/settings/settings.mako',
604 604 self._get_template_context(c), self.request)
605 605 html = formencode.htmlfill.render(
606 606 data,
607 607 defaults=self._form_defaults(),
608 608 encoding="UTF-8",
609 609 force_defaults=False
610 610 )
611 611 return Response(html)
612 612
613 613 @LoginRequired()
614 614 @HasPermissionAllDecorator('hg.admin')
615 615 @CSRFRequired()
616 616 @view_config(
617 617 route_name='admin_settings_hooks_update', request_method='POST',
618 618 renderer='rhodecode:templates/admin/settings/settings.mako')
619 619 @view_config(
620 620 route_name='admin_settings_hooks_delete', request_method='POST',
621 621 renderer='rhodecode:templates/admin/settings/settings.mako')
622 622 def settings_hooks_update(self):
623 623 _ = self.request.translate
624 624 c = self.load_default_context()
625 625 c.active = 'hooks'
626 626 if c.visual.allow_custom_hooks_settings:
627 627 ui_key = self.request.POST.get('new_hook_ui_key')
628 628 ui_value = self.request.POST.get('new_hook_ui_value')
629 629
630 630 hook_id = self.request.POST.get('hook_id')
631 631 new_hook = False
632 632
633 633 model = SettingsModel()
634 634 try:
635 635 if ui_value and ui_key:
636 636 model.create_or_update_hook(ui_key, ui_value)
637 637 h.flash(_('Added new hook'), category='success')
638 638 new_hook = True
639 639 elif hook_id:
640 640 RhodeCodeUi.delete(hook_id)
641 641 Session().commit()
642 642
643 643 # check for edits
644 644 update = False
645 645 _d = self.request.POST.dict_of_lists()
646 646 for k, v in zip(_d.get('hook_ui_key', []),
647 647 _d.get('hook_ui_value_new', [])):
648 648 model.create_or_update_hook(k, v)
649 649 update = True
650 650
651 651 if update and not new_hook:
652 652 h.flash(_('Updated hooks'), category='success')
653 653 Session().commit()
654 654 except Exception:
655 655 log.exception("Exception during hook creation")
656 656 h.flash(_('Error occurred during hook creation'),
657 657 category='error')
658 658
659 659 raise HTTPFound(h.route_path('admin_settings_hooks'))
660 660
661 661 @LoginRequired()
662 662 @HasPermissionAllDecorator('hg.admin')
663 663 @view_config(
664 664 route_name='admin_settings_search', request_method='GET',
665 665 renderer='rhodecode:templates/admin/settings/settings.mako')
666 666 def settings_search(self):
667 667 c = self.load_default_context()
668 668 c.active = 'search'
669 669
670 670 searcher = searcher_from_config(self.request.registry.settings)
671 671 c.statistics = searcher.statistics(self.request.translate)
672 672
673 673 return self._get_template_context(c)
674 674
675 675 @LoginRequired()
676 676 @HasPermissionAllDecorator('hg.admin')
677 677 @view_config(
678 route_name='admin_settings_automation', request_method='GET',
679 renderer='rhodecode:templates/admin/settings/settings.mako')
680 def settings_automation(self):
681 c = self.load_default_context()
682 c.active = 'automation'
683
684 return self._get_template_context(c)
685
686 @LoginRequired()
687 @HasPermissionAllDecorator('hg.admin')
688 @view_config(
678 689 route_name='admin_settings_labs', request_method='GET',
679 690 renderer='rhodecode:templates/admin/settings/settings.mako')
680 691 def settings_labs(self):
681 692 c = self.load_default_context()
682 693 if not c.labs_active:
683 694 raise HTTPFound(h.route_path('admin_settings'))
684 695
685 696 c.active = 'labs'
686 697 c.lab_settings = _LAB_SETTINGS
687 698
688 699 data = render('rhodecode:templates/admin/settings/settings.mako',
689 700 self._get_template_context(c), self.request)
690 701 html = formencode.htmlfill.render(
691 702 data,
692 703 defaults=self._form_defaults(),
693 704 encoding="UTF-8",
694 705 force_defaults=False
695 706 )
696 707 return Response(html)
697 708
698 709 @LoginRequired()
699 710 @HasPermissionAllDecorator('hg.admin')
700 711 @CSRFRequired()
701 712 @view_config(
702 713 route_name='admin_settings_labs_update', request_method='POST',
703 714 renderer='rhodecode:templates/admin/settings/settings.mako')
704 715 def settings_labs_update(self):
705 716 _ = self.request.translate
706 717 c = self.load_default_context()
707 718 c.active = 'labs'
708 719
709 720 application_form = LabsSettingsForm(self.request.translate)()
710 721 try:
711 722 form_result = application_form.to_python(dict(self.request.POST))
712 723 except formencode.Invalid as errors:
713 724 h.flash(
714 725 _("Some form inputs contain invalid data."),
715 726 category='error')
716 727 data = render('rhodecode:templates/admin/settings/settings.mako',
717 728 self._get_template_context(c), self.request)
718 729 html = formencode.htmlfill.render(
719 730 data,
720 731 defaults=errors.value,
721 732 errors=errors.error_dict or {},
722 733 prefix_error=False,
723 734 encoding="UTF-8",
724 735 force_defaults=False
725 736 )
726 737 return Response(html)
727 738
728 739 try:
729 740 session = Session()
730 741 for setting in _LAB_SETTINGS:
731 742 setting_name = setting.key[len('rhodecode_'):]
732 743 sett = SettingsModel().create_or_update_setting(
733 744 setting_name, form_result[setting.key], setting.type)
734 745 session.add(sett)
735 746
736 747 except Exception:
737 748 log.exception('Exception while updating lab settings')
738 749 h.flash(_('Error occurred during updating labs settings'),
739 750 category='error')
740 751 else:
741 752 Session().commit()
742 753 SettingsModel().invalidate_settings_cache()
743 754 h.flash(_('Updated Labs settings'), category='success')
744 755 raise HTTPFound(h.route_path('admin_settings_labs'))
745 756
746 757 data = render('rhodecode:templates/admin/settings/settings.mako',
747 758 self._get_template_context(c), self.request)
748 759 html = formencode.htmlfill.render(
749 760 data,
750 761 defaults=self._form_defaults(),
751 762 encoding="UTF-8",
752 763 force_defaults=False
753 764 )
754 765 return Response(html)
755 766
756 767
757 768 # :param key: name of the setting including the 'rhodecode_' prefix
758 769 # :param type: the RhodeCodeSetting type to use.
759 770 # :param group: the i18ned group in which we should dispaly this setting
760 771 # :param label: the i18ned label we should display for this setting
761 772 # :param help: the i18ned help we should dispaly for this setting
762 773 LabSetting = collections.namedtuple(
763 774 'LabSetting', ('key', 'type', 'group', 'label', 'help'))
764 775
765 776
766 777 # This list has to be kept in sync with the form
767 778 # rhodecode.model.forms.LabsSettingsForm.
768 779 _LAB_SETTINGS = [
769 780
770 781 ]
General Comments 0
You need to be logged in to leave comments. Login now