Show More
@@ -0,0 +1,111 b'' | |||
|
1 | # -*- coding: utf-8 -*- | |
|
2 | ||
|
3 | # Copyright (C) 2016-2017 RhodeCode GmbH | |
|
4 | # | |
|
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 | |
|
7 | # (only), as published by the Free Software Foundation. | |
|
8 | # | |
|
9 | # This program is distributed in the hope that it will be useful, | |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
12 | # GNU General Public License for more details. | |
|
13 | # | |
|
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/>. | |
|
16 | # | |
|
17 | # This program is dual-licensed. If you wish to learn more about the | |
|
18 | # RhodeCode Enterprise Edition, including its added features, Support services, | |
|
19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
|
20 | ||
|
21 | import logging | |
|
22 | ||
|
23 | import formencode | |
|
24 | import formencode.htmlfill | |
|
25 | ||
|
26 | from pyramid.view import view_config | |
|
27 | from pyramid.httpexceptions import HTTPFound | |
|
28 | from pyramid.renderers import render | |
|
29 | from pyramid.response import Response | |
|
30 | ||
|
31 | from rhodecode.apps._base import BaseAppView | |
|
32 | from rhodecode.lib.auth import ( | |
|
33 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) | |
|
34 | from rhodecode.lib import helpers as h | |
|
35 | from rhodecode.model.forms import DefaultsForm | |
|
36 | from rhodecode.model.meta import Session | |
|
37 | from rhodecode import BACKENDS | |
|
38 | from rhodecode.model.settings import SettingsModel | |
|
39 | ||
|
40 | log = logging.getLogger(__name__) | |
|
41 | ||
|
42 | ||
|
43 | class AdminDefaultSettingsView(BaseAppView): | |
|
44 | def load_default_context(self): | |
|
45 | c = self._get_local_tmpl_context() | |
|
46 | ||
|
47 | self._register_global_c(c) | |
|
48 | return c | |
|
49 | ||
|
50 | @LoginRequired() | |
|
51 | @HasPermissionAllDecorator('hg.admin') | |
|
52 | @view_config( | |
|
53 | route_name='admin_defaults_repositories', request_method='GET', | |
|
54 | renderer='rhodecode:templates/admin/defaults/defaults.mako') | |
|
55 | def defaults_repository_show(self): | |
|
56 | c = self.load_default_context() | |
|
57 | c.backends = BACKENDS.keys() | |
|
58 | c.active = 'repositories' | |
|
59 | defaults = SettingsModel().get_default_repo_settings() | |
|
60 | ||
|
61 | data = render( | |
|
62 | 'rhodecode:templates/admin/defaults/defaults.mako', | |
|
63 | self._get_template_context(c), self.request) | |
|
64 | html = formencode.htmlfill.render( | |
|
65 | data, | |
|
66 | defaults=defaults, | |
|
67 | encoding="UTF-8", | |
|
68 | force_defaults=False | |
|
69 | ) | |
|
70 | return Response(html) | |
|
71 | ||
|
72 | @LoginRequired() | |
|
73 | @HasPermissionAllDecorator('hg.admin') | |
|
74 | @CSRFRequired() | |
|
75 | @view_config( | |
|
76 | route_name='admin_defaults_repositories_update', request_method='POST', | |
|
77 | renderer='rhodecode:templates/admin/defaults/defaults.mako') | |
|
78 | def defaults_repository_update(self): | |
|
79 | _ = self.request.translate | |
|
80 | c = self.load_default_context() | |
|
81 | c.active = 'repositories' | |
|
82 | form = DefaultsForm()() | |
|
83 | ||
|
84 | try: | |
|
85 | form_result = form.to_python(dict(self.request.POST)) | |
|
86 | for k, v in form_result.iteritems(): | |
|
87 | setting = SettingsModel().create_or_update_setting(k, v) | |
|
88 | Session().add(setting) | |
|
89 | Session().commit() | |
|
90 | h.flash(_('Default settings updated successfully'), | |
|
91 | category='success') | |
|
92 | ||
|
93 | except formencode.Invalid as errors: | |
|
94 | data = render( | |
|
95 | 'rhodecode:templates/admin/defaults/defaults.mako', | |
|
96 | self._get_template_context(c), self.request) | |
|
97 | html = formencode.htmlfill.render( | |
|
98 | data, | |
|
99 | defaults=errors.value, | |
|
100 | errors=errors.error_dict or {}, | |
|
101 | prefix_error=False, | |
|
102 | encoding="UTF-8", | |
|
103 | force_defaults=False | |
|
104 | ) | |
|
105 | return Response(html) | |
|
106 | except Exception: | |
|
107 | log.exception('Exception in update action') | |
|
108 | h.flash(_('Error occurred during update of default values'), | |
|
109 | category='error') | |
|
110 | ||
|
111 | raise HTTPFound(h.route_path('admin_defaults_repositories')) |
@@ -71,6 +71,14 b' def admin_routes(config):' | |||
|
71 | 71 | name='admin_settings_process_management_signal', |
|
72 | 72 | pattern='/settings/process_management/signal') |
|
73 | 73 | |
|
74 | # default settings | |
|
75 | config.add_route( | |
|
76 | name='admin_defaults_repositories', | |
|
77 | pattern='/defaults/repositories') | |
|
78 | config.add_route( | |
|
79 | name='admin_defaults_repositories_update', | |
|
80 | pattern='/defaults/repositories/update') | |
|
81 | ||
|
74 | 82 | # global permissions |
|
75 | 83 | |
|
76 | 84 | config.add_route( |
@@ -20,15 +20,31 b'' | |||
|
20 | 20 | |
|
21 | 21 | import pytest |
|
22 | 22 | |
|
23 |
from rhodecode.tests import assert_session_flash |
|
|
23 | from rhodecode.tests import assert_session_flash | |
|
24 | 24 | from rhodecode.model.settings import SettingsModel |
|
25 | 25 | |
|
26 | 26 | |
|
27 | def route_path(name, params=None, **kwargs): | |
|
28 | import urllib | |
|
29 | from rhodecode.apps._base import ADMIN_PREFIX | |
|
30 | ||
|
31 | base_url = { | |
|
32 | 'admin_defaults_repositories': | |
|
33 | ADMIN_PREFIX + '/defaults/repositories', | |
|
34 | 'admin_defaults_repositories_update': | |
|
35 | ADMIN_PREFIX + '/defaults/repositories/update', | |
|
36 | }[name].format(**kwargs) | |
|
37 | ||
|
38 | if params: | |
|
39 | base_url = '{}?{}'.format(base_url, urllib.urlencode(params)) | |
|
40 | return base_url | |
|
41 | ||
|
42 | ||
|
27 | 43 | @pytest.mark.usefixtures("app") |
|
28 | class TestDefaultsController: | |
|
44 | class TestDefaultsController(object): | |
|
29 | 45 | |
|
30 | 46 | def test_index(self, autologin_user): |
|
31 |
response = self.app.get( |
|
|
47 | response = self.app.get(route_path('admin_defaults_repositories')) | |
|
32 | 48 | response.mustcontain('default_repo_private') |
|
33 | 49 | response.mustcontain('default_repo_enable_statistics') |
|
34 | 50 | response.mustcontain('default_repo_enable_downloads') |
@@ -44,7 +60,7 b' class TestDefaultsController:' | |||
|
44 | 60 | 'csrf_token': csrf_token, |
|
45 | 61 | } |
|
46 | 62 | response = self.app.post( |
|
47 |
|
|
|
63 | route_path('admin_defaults_repositories_update'), params=params) | |
|
48 | 64 | assert_session_flash(response, 'Default settings updated successfully') |
|
49 | 65 | |
|
50 | 66 | defs = SettingsModel().get_default_repo_settings() |
@@ -61,8 +77,9 b' class TestDefaultsController:' | |||
|
61 | 77 | 'csrf_token': csrf_token, |
|
62 | 78 | } |
|
63 | 79 | response = self.app.post( |
|
64 |
|
|
|
80 | route_path('admin_defaults_repositories_update'), params=params) | |
|
65 | 81 | assert_session_flash(response, 'Default settings updated successfully') |
|
82 | ||
|
66 | 83 | defs = SettingsModel().get_default_repo_settings() |
|
67 | 84 | del params['csrf_token'] |
|
68 | 85 | assert params == defs |
@@ -254,14 +254,6 b' def make_map(config):' | |||
|
254 | 254 | m.connect('edit_user_global_perms', '/users/{user_id}/edit/global_permissions', |
|
255 | 255 | action='update_global_perms', conditions={'method': ['PUT']}) |
|
256 | 256 | |
|
257 | # ADMIN DEFAULTS REST ROUTES | |
|
258 | with rmap.submapper(path_prefix=ADMIN_PREFIX, | |
|
259 | controller='admin/defaults') as m: | |
|
260 | m.connect('admin_defaults_repositories', '/defaults/repositories', | |
|
261 | action='update_repository_defaults', conditions={'method': ['POST']}) | |
|
262 | m.connect('admin_defaults_repositories', '/defaults/repositories', | |
|
263 | action='index', conditions={'method': ['GET']}) | |
|
264 | ||
|
265 | 257 | # ADMIN SETTINGS ROUTES |
|
266 | 258 | with rmap.submapper(path_prefix=ADMIN_PREFIX, |
|
267 | 259 | controller='admin/settings') as m: |
@@ -47,6 +47,8 b' function registerRCRoutes() {' | |||
|
47 | 47 | pyroutes.register('admin_settings_sessions_cleanup', '/_admin/settings/sessions/cleanup', []); |
|
48 | 48 | pyroutes.register('admin_settings_process_management', '/_admin/settings/process_management', []); |
|
49 | 49 | pyroutes.register('admin_settings_process_management_signal', '/_admin/settings/process_management/signal', []); |
|
50 | pyroutes.register('admin_defaults_repositories', '/_admin/defaults/repositories', []); | |
|
51 | pyroutes.register('admin_defaults_repositories_update', '/_admin/defaults/repositories/update', []); | |
|
50 | 52 | pyroutes.register('admin_permissions_application', '/_admin/permissions/application', []); |
|
51 | 53 | pyroutes.register('admin_permissions_application_update', '/_admin/permissions/application/update', []); |
|
52 | 54 | pyroutes.register('admin_permissions_global', '/_admin/permissions/global', []); |
@@ -28,7 +28,7 b'' | |||
|
28 | 28 | <div class="sidebar-col-wrapper"> |
|
29 | 29 | <div class="sidebar"> |
|
30 | 30 | <ul class="nav nav-pills nav-stacked"> |
|
31 |
<li class="${'active' if c.active=='repositories' else ''}"><a href="${h. |
|
|
31 | <li class="${'active' if c.active=='repositories' else ''}"><a href="${h.route_path('admin_defaults_repositories')}">${_('Repository')}</a></li> | |
|
32 | 32 | </ul> |
|
33 | 33 | </div> |
|
34 | 34 |
@@ -3,7 +3,7 b'' | |||
|
3 | 3 | <h3 class="panel-title">${_('Default Settings For New Repositories')}</h3> |
|
4 | 4 | </div> |
|
5 | 5 | <div class="panel-body"> |
|
6 |
${h.secure_form(h. |
|
|
6 | ${h.secure_form(h.route_path('admin_defaults_repositories_update'), method='POST', request=request)} | |
|
7 | 7 | <div class="form"> |
|
8 | 8 | <!-- fields --> |
|
9 | 9 |
@@ -80,7 +80,7 b'' | |||
|
80 | 80 | <li><a href="${h.route_path('admin_permissions_application')}">${_('Permissions')}</a></li> |
|
81 | 81 | <li><a href="${h.route_path('auth_home', traverse='')}">${_('Authentication')}</a></li> |
|
82 | 82 | <li><a href="${h.route_path('global_integrations_home')}">${_('Integrations')}</a></li> |
|
83 |
<li><a href="${h. |
|
|
83 | <li><a href="${h.route_path('admin_defaults_repositories')}">${_('Defaults')}</a></li> | |
|
84 | 84 | <li class="last"><a href="${h.url('admin_settings')}">${_('Settings')}</a></li> |
|
85 | 85 | </ul> |
|
86 | 86 | </%def> |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now