Show More
@@ -0,0 +1,106 b'' | |||||
|
1 | # -*- coding: utf-8 -*- | |||
|
2 | ||||
|
3 | # Copyright (C) 2016-2016 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 | ||||
|
22 | import logging | |||
|
23 | import collections | |||
|
24 | from pylons import url | |||
|
25 | from pylons.i18n.translation import lazy_ugettext | |||
|
26 | from zope.interface import implementer | |||
|
27 | ||||
|
28 | import rhodecode | |||
|
29 | from rhodecode.admin.interfaces import IAdminNavigationRegistry | |||
|
30 | from rhodecode.lib.utils2 import str2bool | |||
|
31 | ||||
|
32 | ||||
|
33 | log = logging.getLogger(__name__) | |||
|
34 | ||||
|
35 | NavListEntry = collections.namedtuple('NavListEntry', ['key', 'name', 'url']) | |||
|
36 | ||||
|
37 | ||||
|
38 | class NavEntry(object): | |||
|
39 | ||||
|
40 | def __init__(self, key, name, view_name, pyramid=False): | |||
|
41 | self.key = key | |||
|
42 | self.name = name | |||
|
43 | self.view_name = view_name | |||
|
44 | self.pyramid = pyramid | |||
|
45 | ||||
|
46 | def generate_url(self, request): | |||
|
47 | if self.pyramid: | |||
|
48 | if hasattr(request, 'route_path'): | |||
|
49 | return request.route_path(self.view_name) | |||
|
50 | else: | |||
|
51 | # TODO: johbo: Remove this after migrating to pyramid. | |||
|
52 | # We need the pyramid request here to generate URLs to pyramid | |||
|
53 | # views from within pylons views. | |||
|
54 | from pyramid.threadlocal import get_current_request | |||
|
55 | pyramid_request = get_current_request() | |||
|
56 | return pyramid_request.route_path(self.view_name) | |||
|
57 | else: | |||
|
58 | return url(self.view_name) | |||
|
59 | ||||
|
60 | ||||
|
61 | @implementer(IAdminNavigationRegistry) | |||
|
62 | class NavigationRegistry(object): | |||
|
63 | ||||
|
64 | _base_entries = [ | |||
|
65 | NavEntry('global', lazy_ugettext('Global'), 'admin_settings_global'), | |||
|
66 | NavEntry('vcs', lazy_ugettext('VCS'), 'admin_settings_vcs'), | |||
|
67 | NavEntry('visual', lazy_ugettext('Visual'), 'admin_settings_visual'), | |||
|
68 | NavEntry('mapping', lazy_ugettext('Remap and Rescan'), | |||
|
69 | 'admin_settings_mapping'), | |||
|
70 | NavEntry('issuetracker', lazy_ugettext('Issue Tracker'), | |||
|
71 | 'admin_settings_issuetracker'), | |||
|
72 | NavEntry('email', lazy_ugettext('Email'), 'admin_settings_email'), | |||
|
73 | NavEntry('hooks', lazy_ugettext('Hooks'), 'admin_settings_hooks'), | |||
|
74 | NavEntry('search', lazy_ugettext('Full Text Search'), | |||
|
75 | 'admin_settings_search'), | |||
|
76 | NavEntry('system', lazy_ugettext('System Info'), | |||
|
77 | 'admin_settings_system'), | |||
|
78 | NavEntry('open_source', lazy_ugettext('Open Source Licenses'), | |||
|
79 | 'admin_settings_open_source', pyramid=True), | |||
|
80 | # TODO: marcink: we disable supervisor now until the supervisor stats | |||
|
81 | # page is fixed in the nix configuration | |||
|
82 | # NavEntry('supervisor', lazy_ugettext('Supervisor'), | |||
|
83 | # 'admin_settings_supervisor'), | |||
|
84 | ] | |||
|
85 | ||||
|
86 | def __init__(self): | |||
|
87 | self._registered_entries = collections.OrderedDict([ | |||
|
88 | (item.key, item) for item in self.__class__._base_entries | |||
|
89 | ]) | |||
|
90 | ||||
|
91 | # Add the labs entry when it's activated. | |||
|
92 | labs_active = str2bool( | |||
|
93 | rhodecode.CONFIG.get('labs_settings_active', 'false')) | |||
|
94 | if labs_active: | |||
|
95 | self.add_entry( | |||
|
96 | NavEntry('labs', lazy_ugettext('Labs'), 'admin_settings_labs')) | |||
|
97 | ||||
|
98 | def add_entry(self, entry): | |||
|
99 | self._registered_entries[entry.key] = entry | |||
|
100 | ||||
|
101 | def get_navlist(self, request): | |||
|
102 | navlist = [NavListEntry(i.key, i.name, i.generate_url(request)) | |||
|
103 | for i in self._registered_entries.values()] | |||
|
104 | return navlist | |||
|
105 | ||||
|
106 | navigation = NavigationRegistry() |
@@ -37,6 +37,7 b' from pylons.i18n.translation import _, l' | |||||
37 | from webob.exc import HTTPBadRequest |
|
37 | from webob.exc import HTTPBadRequest | |
38 |
|
38 | |||
39 | import rhodecode |
|
39 | import rhodecode | |
|
40 | from rhodecode.admin.navigation import navigation | |||
40 | from rhodecode.lib import auth |
|
41 | from rhodecode.lib import auth | |
41 | from rhodecode.lib import helpers as h |
|
42 | from rhodecode.lib import helpers as h | |
42 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator |
|
43 | from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator | |
@@ -49,7 +50,7 b' from rhodecode.lib.compat import Ordered' | |||||
49 | from rhodecode.lib.ext_json import json |
|
50 | from rhodecode.lib.ext_json import json | |
50 | from rhodecode.lib.utils import jsonify |
|
51 | from rhodecode.lib.utils import jsonify | |
51 |
|
52 | |||
52 |
from rhodecode.model.db import RhodeCodeUi, Repository |
|
53 | from rhodecode.model.db import RhodeCodeUi, Repository | |
53 | from rhodecode.model.forms import ApplicationSettingsForm, \ |
|
54 | from rhodecode.model.forms import ApplicationSettingsForm, \ | |
54 | ApplicationUiSettingsForm, ApplicationVisualisationForm, \ |
|
55 | ApplicationUiSettingsForm, ApplicationVisualisationForm, \ | |
55 | LabsSettingsForm, IssueTrackerPatternsForm |
|
56 | LabsSettingsForm, IssueTrackerPatternsForm | |
@@ -810,76 +811,3 b' LabSetting = collections.namedtuple(' | |||||
810 | help=lazy_ugettext('e.g. http://localhost:8080/') |
|
811 | help=lazy_ugettext('e.g. http://localhost:8080/') | |
811 | ), |
|
812 | ), | |
812 | ] |
|
813 | ] | |
813 |
|
||||
814 |
|
||||
815 | NavListEntry = collections.namedtuple('NavListEntry', ['key', 'name', 'url']) |
|
|||
816 |
|
||||
817 |
|
||||
818 | class NavEntry(object): |
|
|||
819 |
|
||||
820 | def __init__(self, key, name, view_name, pyramid=False): |
|
|||
821 | self.key = key |
|
|||
822 | self.name = name |
|
|||
823 | self.view_name = view_name |
|
|||
824 | self.pyramid = pyramid |
|
|||
825 |
|
||||
826 | def generate_url(self, request): |
|
|||
827 | if self.pyramid: |
|
|||
828 | if hasattr(request, 'route_path'): |
|
|||
829 | return request.route_path(self.view_name) |
|
|||
830 | else: |
|
|||
831 | # TODO: johbo: Remove this after migrating to pyramid. |
|
|||
832 | # We need the pyramid request here to generate URLs to pyramid |
|
|||
833 | # views from within pylons views. |
|
|||
834 | from pyramid.threadlocal import get_current_request |
|
|||
835 | pyramid_request = get_current_request() |
|
|||
836 | return pyramid_request.route_path(self.view_name) |
|
|||
837 | else: |
|
|||
838 | return url(self.view_name) |
|
|||
839 |
|
||||
840 |
|
||||
841 | class NavigationRegistry(object): |
|
|||
842 |
|
||||
843 | _base_entries = [ |
|
|||
844 | NavEntry('global', lazy_ugettext('Global'), 'admin_settings_global'), |
|
|||
845 | NavEntry('vcs', lazy_ugettext('VCS'), 'admin_settings_vcs'), |
|
|||
846 | NavEntry('visual', lazy_ugettext('Visual'), 'admin_settings_visual'), |
|
|||
847 | NavEntry('mapping', lazy_ugettext('Remap and Rescan'), |
|
|||
848 | 'admin_settings_mapping'), |
|
|||
849 | NavEntry('issuetracker', lazy_ugettext('Issue Tracker'), |
|
|||
850 | 'admin_settings_issuetracker'), |
|
|||
851 | NavEntry('email', lazy_ugettext('Email'), 'admin_settings_email'), |
|
|||
852 | NavEntry('hooks', lazy_ugettext('Hooks'), 'admin_settings_hooks'), |
|
|||
853 | NavEntry('search', lazy_ugettext('Full Text Search'), |
|
|||
854 | 'admin_settings_search'), |
|
|||
855 | NavEntry('system', lazy_ugettext('System Info'), |
|
|||
856 | 'admin_settings_system'), |
|
|||
857 | NavEntry('open_source', lazy_ugettext('Open Source Licenses'), |
|
|||
858 | 'admin_settings_open_source', pyramid=True), |
|
|||
859 | # TODO: marcink: we disable supervisor now until the supervisor stats |
|
|||
860 | # page is fixed in the nix configuration |
|
|||
861 | # NavEntry('supervisor', lazy_ugettext('Supervisor'), |
|
|||
862 | # 'admin_settings_supervisor'), |
|
|||
863 | ] |
|
|||
864 |
|
||||
865 | def __init__(self): |
|
|||
866 | self._registered_entries = collections.OrderedDict([ |
|
|||
867 | (item.key, item) for item in self.__class__._base_entries |
|
|||
868 | ]) |
|
|||
869 |
|
||||
870 | # Add the labs entry when it's activated. |
|
|||
871 | labs_active = str2bool( |
|
|||
872 | rhodecode.CONFIG.get('labs_settings_active', 'false')) |
|
|||
873 | if labs_active: |
|
|||
874 | self.add_entry( |
|
|||
875 | NavEntry('labs', lazy_ugettext('Labs'), 'admin_settings_labs')) |
|
|||
876 |
|
||||
877 | def add_entry(self, entry): |
|
|||
878 | self._registered_entries[entry.key] = entry |
|
|||
879 |
|
||||
880 | def get_navlist(self, request): |
|
|||
881 | navlist = [NavListEntry(i.key, i.name, i.generate_url(request)) |
|
|||
882 | for i in self._registered_entries.values()] |
|
|||
883 | return navlist |
|
|||
884 |
|
||||
885 | navigation = NavigationRegistry() |
|
General Comments 0
You need to be logged in to leave comments.
Login now