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