##// END OF EJS Templates
logging: fixed typo
super-admin -
r4824:b76827e8 default
parent child Browse files
Show More
@@ -1,148 +1,148 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2016-2020 RhodeCode GmbH
3 # Copyright (C) 2016-2020 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._base.interfaces import IAdminNavigationRegistry
27 from rhodecode.apps._base.interfaces import IAdminNavigationRegistry
28 from rhodecode.lib.utils2 import str2bool
28 from rhodecode.lib.utils2 import str2bool
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(
34 NavListEntry = collections.namedtuple(
35 'NavListEntry', ['key', 'name', 'url', 'active_list'])
35 'NavListEntry', ['key', 'name', 'url', 'active_list'])
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 active_list: list of urls that we select active for this element
45 :param active_list: list of urls that we select active for this element
46 """
46 """
47
47
48 def __init__(self, key, name, view_name, active_list=None):
48 def __init__(self, key, name, view_name, active_list=None):
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._active_list = active_list or []
52 self._active_list = active_list or []
53
53
54 def generate_url(self, request):
54 def generate_url(self, request):
55 return request.route_path(self.view_name)
55 return request.route_path(self.view_name)
56
56
57 def get_localized_name(self, request):
57 def get_localized_name(self, request):
58 return request.translate(self.name)
58 return request.translate(self.name)
59
59
60 @property
60 @property
61 def active_list(self):
61 def active_list(self):
62 active_list = [self.key]
62 active_list = [self.key]
63 if self._active_list:
63 if self._active_list:
64 active_list = self._active_list
64 active_list = self._active_list
65 return active_list
65 return active_list
66
66
67
67
68 @implementer(IAdminNavigationRegistry)
68 @implementer(IAdminNavigationRegistry)
69 class NavigationRegistry(object):
69 class NavigationRegistry(object):
70
70
71 _base_entries = [
71 _base_entries = [
72 NavEntry('global', _('Global'),
72 NavEntry('global', _('Global'),
73 'admin_settings_global'),
73 'admin_settings_global'),
74 NavEntry('vcs', _('VCS'),
74 NavEntry('vcs', _('VCS'),
75 'admin_settings_vcs'),
75 'admin_settings_vcs'),
76 NavEntry('visual', _('Visual'),
76 NavEntry('visual', _('Visual'),
77 'admin_settings_visual'),
77 'admin_settings_visual'),
78 NavEntry('mapping', _('Remap and Rescan'),
78 NavEntry('mapping', _('Remap and Rescan'),
79 'admin_settings_mapping'),
79 'admin_settings_mapping'),
80 NavEntry('issuetracker', _('Issue Tracker'),
80 NavEntry('issuetracker', _('Issue Tracker'),
81 'admin_settings_issuetracker'),
81 'admin_settings_issuetracker'),
82 NavEntry('email', _('Email'),
82 NavEntry('email', _('Email'),
83 'admin_settings_email'),
83 'admin_settings_email'),
84 NavEntry('hooks', _('Hooks'),
84 NavEntry('hooks', _('Hooks'),
85 'admin_settings_hooks'),
85 'admin_settings_hooks'),
86 NavEntry('search', _('Full Text Search'),
86 NavEntry('search', _('Full Text Search'),
87 'admin_settings_search'),
87 'admin_settings_search'),
88 NavEntry('system', _('System Info'),
88 NavEntry('system', _('System Info'),
89 'admin_settings_system'),
89 'admin_settings_system'),
90 NavEntry('exceptions', _('Exceptions Tracker'),
90 NavEntry('exceptions', _('Exceptions Tracker'),
91 'admin_settings_exception_tracker',
91 'admin_settings_exception_tracker',
92 active_list=['exceptions', 'exceptions_browse']),
92 active_list=['exceptions', 'exceptions_browse']),
93 NavEntry('process_management', _('Processes'),
93 NavEntry('process_management', _('Processes'),
94 'admin_settings_process_management'),
94 'admin_settings_process_management'),
95 NavEntry('sessions', _('User Sessions'),
95 NavEntry('sessions', _('User Sessions'),
96 'admin_settings_sessions'),
96 'admin_settings_sessions'),
97 NavEntry('open_source', _('Open Source Licenses'),
97 NavEntry('open_source', _('Open Source Licenses'),
98 'admin_settings_open_source'),
98 'admin_settings_open_source'),
99 NavEntry('automation', _('Automation'),
99 NavEntry('automation', _('Automation'),
100 'admin_settings_automation')
100 'admin_settings_automation')
101 ]
101 ]
102
102
103 _labs_entry = NavEntry('labs', _('Labs'),
103 _labs_entry = NavEntry('labs', _('Labs'),
104 'admin_settings_labs')
104 'admin_settings_labs')
105
105
106 def __init__(self, labs_active=False):
106 def __init__(self, labs_active=False):
107 self._registered_entries = collections.OrderedDict()
107 self._registered_entries = collections.OrderedDict()
108 for item in self.__class__._base_entries:
108 for item in self.__class__._base_entries:
109 self._registered_entries[item.key] = item
109 self._registered_entries[item.key] = item
110
110
111 if labs_active:
111 if labs_active:
112 self.add_entry(self._labs_entry)
112 self.add_entry(self._labs_entry)
113
113
114 def add_entry(self, entry):
114 def add_entry(self, entry):
115 self._registered_entries[entry.key] = entry
115 self._registered_entries[entry.key] = entry
116
116
117 def get_navlist(self, request):
117 def get_navlist(self, request):
118 nav_list = [
118 nav_list = [
119 NavListEntry(i.key, i.get_localized_name(request),
119 NavListEntry(i.key, i.get_localized_name(request),
120 i.generate_url(request), i.active_list)
120 i.generate_url(request), i.active_list)
121 for i in self._registered_entries.values()]
121 for i in self._registered_entries.values()]
122 return nav_list
122 return nav_list
123
123
124
124
125 def navigation_registry(request, registry=None):
125 def navigation_registry(request, registry=None):
126 """
126 """
127 Helper that returns the admin navigation registry.
127 Helper that returns the admin navigation registry.
128 """
128 """
129 pyramid_registry = registry or request.registry
129 pyramid_registry = registry or request.registry
130 nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry)
130 nav_registry = pyramid_registry.queryUtility(IAdminNavigationRegistry)
131 return nav_registry
131 return nav_registry
132
132
133
133
134 def navigation_list(request):
134 def navigation_list(request):
135 """
135 """
136 Helper that returns the admin navigation as list of NavListEntry objects.
136 Helper that returns the admin navigation as list of NavListEntry objects.
137 """
137 """
138 return navigation_registry(request).get_navlist(request)
138 return navigation_registry(request).get_navlist(request)
139
139
140
140
141 def includeme(config):
141 def includeme(config):
142 # Create admin navigation registry and add it to the pyramid registry.
142 # Create admin navigation registry and add it to the pyramid registry.
143 settings = config.get_settings()
143 settings = config.get_settings()
144 labs_active = str2bool(settings.get('labs_settings_active', False))
144 labs_active = str2bool(settings.get('labs_settings_active', False))
145 navigation_registry_instance = NavigationRegistry(labs_active=labs_active)
145 navigation_registry_instance = NavigationRegistry(labs_active=labs_active)
146 config.registry.registerUtility(navigation_registry_instance)
146 config.registry.registerUtility(navigation_registry_instance)
147 log.debug('Created new nabigation instance, %s', navigation_registry_instance)
147 log.debug('Created new navigation instance, %s', navigation_registry_instance)
148
148
General Comments 0
You need to be logged in to leave comments. Login now