Show More
@@ -1,133 +1,140 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 |
|
21 | |||
22 | import logging |
|
22 | import logging | |
23 | import collections |
|
23 | import collections | |
24 |
|
24 | |||
25 | from pylons import url |
|
25 | from pylons import url | |
26 | from zope.interface import implementer |
|
26 | from zope.interface import implementer | |
27 |
|
27 | |||
28 | from rhodecode.admin.interfaces import IAdminNavigationRegistry |
|
28 | from rhodecode.admin.interfaces import IAdminNavigationRegistry | |
29 | from rhodecode.lib.utils import get_registry |
|
29 | from rhodecode.lib.utils import get_registry | |
30 | from rhodecode.translation import _ |
|
30 | from rhodecode.translation import _ | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | log = logging.getLogger(__name__) |
|
33 | log = logging.getLogger(__name__) | |
34 |
|
34 | |||
35 | NavListEntry = collections.namedtuple('NavListEntry', ['key', 'name', 'url']) |
|
35 | NavListEntry = collections.namedtuple('NavListEntry', ['key', 'name', 'url']) | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | class NavEntry(object): |
|
38 | class NavEntry(object): | |
39 | """ |
|
39 | """ | |
40 | Represents an entry in the admin navigation. |
|
40 | Represents an entry in the admin navigation. | |
41 |
|
41 | |||
42 | :param key: Unique identifier used to store reference in an OrderedDict. |
|
42 | :param key: Unique identifier used to store reference in an OrderedDict. | |
43 | :param name: Display name, usually a translation string. |
|
43 | :param name: Display name, usually a translation string. | |
44 | :param view_name: Name of the view, used generate the URL. |
|
44 | :param view_name: Name of the view, used generate the URL. | |
45 | :param pyramid: Indicator to use pyramid for URL generation. This should |
|
45 | :param pyramid: Indicator to use pyramid for URL generation. This should | |
46 | be removed as soon as we are fully migrated to pyramid. |
|
46 | be removed as soon as we are fully migrated to pyramid. | |
47 | """ |
|
47 | """ | |
48 |
|
48 | |||
49 | def __init__(self, key, name, view_name, pyramid=False): |
|
49 | def __init__(self, key, name, view_name, pyramid=False): | |
50 | self.key = key |
|
50 | self.key = key | |
51 | self.name = name |
|
51 | self.name = name | |
52 | self.view_name = view_name |
|
52 | self.view_name = view_name | |
53 | self.pyramid = pyramid |
|
53 | self.pyramid = pyramid | |
54 |
|
54 | |||
55 | def generate_url(self, request): |
|
55 | def generate_url(self, request): | |
56 | if self.pyramid: |
|
56 | if self.pyramid: | |
57 | if hasattr(request, 'route_path'): |
|
57 | if hasattr(request, 'route_path'): | |
58 | return request.route_path(self.view_name) |
|
58 | return request.route_path(self.view_name) | |
59 | else: |
|
59 | else: | |
60 | # TODO: johbo: Remove this after migrating to pyramid. |
|
60 | # TODO: johbo: Remove this after migrating to pyramid. | |
61 | # We need the pyramid request here to generate URLs to pyramid |
|
61 | # We need the pyramid request here to generate URLs to pyramid | |
62 | # views from within pylons views. |
|
62 | # views from within pylons views. | |
63 | from pyramid.threadlocal import get_current_request |
|
63 | from pyramid.threadlocal import get_current_request | |
64 | pyramid_request = get_current_request() |
|
64 | pyramid_request = get_current_request() | |
65 | return pyramid_request.route_path(self.view_name) |
|
65 | return pyramid_request.route_path(self.view_name) | |
66 | else: |
|
66 | else: | |
67 | return url(self.view_name) |
|
67 | return url(self.view_name) | |
68 |
|
68 | |||
|
69 | def get_localized_name(self, request): | |||
|
70 | if hasattr(request, 'translate'): | |||
|
71 | return request.translate(self.name) | |||
|
72 | else: | |||
|
73 | # TODO(marcink): Remove this after migrating to pyramid | |||
|
74 | from pyramid.threadlocal import get_current_request | |||
|
75 | pyramid_request = get_current_request() | |||
|
76 | return pyramid_request.translate(self.name) | |||
|
77 | ||||
69 |
|
78 | |||
70 | @implementer(IAdminNavigationRegistry) |
|
79 | @implementer(IAdminNavigationRegistry) | |
71 | class NavigationRegistry(object): |
|
80 | class NavigationRegistry(object): | |
72 |
|
81 | |||
73 | _base_entries = [ |
|
82 | _base_entries = [ | |
74 | NavEntry('global', _('Global'), 'admin_settings_global'), |
|
83 | NavEntry('global', _('Global'), 'admin_settings_global'), | |
75 | NavEntry('vcs', _('VCS'), 'admin_settings_vcs'), |
|
84 | NavEntry('vcs', _('VCS'), 'admin_settings_vcs'), | |
76 | NavEntry('visual', _('Visual'), 'admin_settings_visual'), |
|
85 | NavEntry('visual', _('Visual'), 'admin_settings_visual'), | |
77 | NavEntry('mapping', _('Remap and Rescan'), 'admin_settings_mapping'), |
|
86 | NavEntry('mapping', _('Remap and Rescan'), 'admin_settings_mapping'), | |
78 | NavEntry('issuetracker', _('Issue Tracker'), |
|
87 | NavEntry('issuetracker', _('Issue Tracker'), | |
79 | 'admin_settings_issuetracker'), |
|
88 | 'admin_settings_issuetracker'), | |
80 | NavEntry('email', _('Email'), 'admin_settings_email'), |
|
89 | NavEntry('email', _('Email'), 'admin_settings_email'), | |
81 | NavEntry('hooks', _('Hooks'), 'admin_settings_hooks'), |
|
90 | NavEntry('hooks', _('Hooks'), 'admin_settings_hooks'), | |
82 | NavEntry('search', _('Full Text Search'), 'admin_settings_search'), |
|
91 | NavEntry('search', _('Full Text Search'), 'admin_settings_search'), | |
83 |
|
92 | |||
84 |
|
||||
85 | NavEntry('integrations', _('Integrations'), |
|
93 | NavEntry('integrations', _('Integrations'), | |
86 | 'global_integrations_home', pyramid=True), |
|
94 | 'global_integrations_home', pyramid=True), | |
87 |
NavEntry('system', _('System Info'), |
|
95 | NavEntry('system', _('System Info'), | |
88 |
|
96 | 'admin_settings_system', pyramid=True), | ||
89 |
|
97 | NavEntry('sessions', _('User Sessions'), | ||
90 | NavEntry('session', _('User Sessions'), |
|
|||
91 | 'admin_settings_sessions', pyramid=True), |
|
98 | 'admin_settings_sessions', pyramid=True), | |
92 | NavEntry('open_source', _('Open Source Licenses'), |
|
99 | NavEntry('open_source', _('Open Source Licenses'), | |
93 | 'admin_settings_open_source', pyramid=True), |
|
100 | 'admin_settings_open_source', pyramid=True), | |
94 |
|
101 | |||
95 | # TODO: marcink: we disable supervisor now until the supervisor stats |
|
102 | # TODO: marcink: we disable supervisor now until the supervisor stats | |
96 | # page is fixed in the nix configuration |
|
103 | # page is fixed in the nix configuration | |
97 | # NavEntry('supervisor', _('Supervisor'), 'admin_settings_supervisor'), |
|
104 | # NavEntry('supervisor', _('Supervisor'), 'admin_settings_supervisor'), | |
98 | ] |
|
105 | ] | |
99 |
|
106 | |||
100 | _labs_entry = NavEntry('labs', _('Labs'), |
|
107 | _labs_entry = NavEntry('labs', _('Labs'), 'admin_settings_labs') | |
101 | 'admin_settings_labs') |
|
|||
102 |
|
108 | |||
103 | def __init__(self, labs_active=False): |
|
109 | def __init__(self, labs_active=False): | |
104 | self._registered_entries = collections.OrderedDict([ |
|
110 | self._registered_entries = collections.OrderedDict([ | |
105 | (item.key, item) for item in self.__class__._base_entries |
|
111 | (item.key, item) for item in self.__class__._base_entries | |
106 | ]) |
|
112 | ]) | |
107 |
|
113 | |||
108 | if labs_active: |
|
114 | if labs_active: | |
109 | self.add_entry(self._labs_entry) |
|
115 | self.add_entry(self._labs_entry) | |
110 |
|
116 | |||
111 | def add_entry(self, entry): |
|
117 | def add_entry(self, entry): | |
112 | self._registered_entries[entry.key] = entry |
|
118 | self._registered_entries[entry.key] = entry | |
113 |
|
119 | |||
114 | def get_navlist(self, request): |
|
120 | def get_navlist(self, request): | |
115 |
navlist = [NavListEntry(i.key, i. |
|
121 | navlist = [NavListEntry(i.key, i.get_localized_name(request), | |
|
122 | i.generate_url(request)) | |||
116 | for i in self._registered_entries.values()] |
|
123 | for i in self._registered_entries.values()] | |
117 | return navlist |
|
124 | return navlist | |
118 |
|
125 | |||
119 |
|
126 | |||
120 | def navigation_registry(request): |
|
127 | def navigation_registry(request): | |
121 | """ |
|
128 | """ | |
122 | Helper that returns the admin navigation registry. |
|
129 | Helper that returns the admin navigation registry. | |
123 | """ |
|
130 | """ | |
124 | pyramid_registry = get_registry(request) |
|
131 | pyramid_registry = get_registry(request) | |
125 | nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry) |
|
132 | nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry) | |
126 | return nav_registry |
|
133 | return nav_registry | |
127 |
|
134 | |||
128 |
|
135 | |||
129 | def navigation_list(request): |
|
136 | def navigation_list(request): | |
130 | """ |
|
137 | """ | |
131 | Helper that returns the admin navigation as list of NavListEntry objects. |
|
138 | Helper that returns the admin navigation as list of NavListEntry objects. | |
132 | """ |
|
139 | """ | |
133 | return navigation_registry(request).get_navlist(request) |
|
140 | return navigation_registry(request).get_navlist(request) |
@@ -1,60 +1,60 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 logging |
|
21 | import logging | |
22 |
|
22 | |||
23 | from pyramid.view import view_config |
|
23 | from pyramid.view import view_config | |
24 |
|
24 | |||
25 | from rhodecode.translation import _ |
|
|||
26 | from rhodecode.svn_support.utils import generate_mod_dav_svn_config |
|
25 | from rhodecode.svn_support.utils import generate_mod_dav_svn_config | |
27 |
|
26 | |||
28 | from rhodecode.admin.views.base import AdminSettingsView |
|
27 | from rhodecode.admin.views.base import AdminSettingsView | |
29 | from rhodecode.lib.auth import ( |
|
28 | from rhodecode.lib.auth import ( | |
30 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) |
|
29 | LoginRequired, HasPermissionAllDecorator, CSRFRequired) | |
31 |
|
30 | |||
32 | log = logging.getLogger(__name__) |
|
31 | log = logging.getLogger(__name__) | |
33 |
|
32 | |||
34 |
|
33 | |||
35 | class SvnConfigAdminSettingsView(AdminSettingsView): |
|
34 | class SvnConfigAdminSettingsView(AdminSettingsView): | |
36 |
|
35 | |||
37 | @LoginRequired() |
|
36 | @LoginRequired() | |
38 | @CSRFRequired() |
|
37 | @CSRFRequired() | |
39 | @HasPermissionAllDecorator('hg.admin') |
|
38 | @HasPermissionAllDecorator('hg.admin') | |
40 | @view_config( |
|
39 | @view_config( | |
41 | route_name='admin_settings_vcs_svn_generate_cfg', |
|
40 | route_name='admin_settings_vcs_svn_generate_cfg', | |
42 | request_method='POST', renderer='json') |
|
41 | request_method='POST', renderer='json') | |
43 | def vcs_svn_generate_config(self): |
|
42 | def vcs_svn_generate_config(self): | |
|
43 | _ = self.request.translate | |||
44 | try: |
|
44 | try: | |
45 | generate_mod_dav_svn_config(self.request.registry) |
|
45 | generate_mod_dav_svn_config(self.request.registry) | |
46 | msg = { |
|
46 | msg = { | |
47 | 'message': _('Apache configuration for Subversion generated.'), |
|
47 | 'message': _('Apache configuration for Subversion generated.'), | |
48 | 'level': 'success', |
|
48 | 'level': 'success', | |
49 | } |
|
49 | } | |
50 | except Exception: |
|
50 | except Exception: | |
51 | log.exception( |
|
51 | log.exception( | |
52 | 'Exception while generating the Apache ' |
|
52 | 'Exception while generating the Apache ' | |
53 | 'configuration for Subversion.') |
|
53 | 'configuration for Subversion.') | |
54 | msg = { |
|
54 | msg = { | |
55 | 'message': _('Failed to generate the Apache configuration for Subversion.'), |
|
55 | 'message': _('Failed to generate the Apache configuration for Subversion.'), | |
56 | 'level': 'error', |
|
56 | 'level': 'error', | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | data = {'message': msg} |
|
59 | data = {'message': msg} | |
60 | return data |
|
60 | return data |
General Comments 0
You need to be logged in to leave comments.
Login now