##// END OF EJS Templates
pyramid-admin: use new base app view in exchange of dedicated admin view....
marcink -
r1511:13903a13 default
parent child Browse files
Show More
@@ -1,48 +1,48 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import collections
22 22 import logging
23 23
24 24 from pylons import tmpl_context as c
25 25 from pyramid.view import view_config
26 26
27 from rhodecode.apps.admin.views.base import AdminSettingsView
27 from rhodecode.apps._base import BaseAppView
28 28 from rhodecode.apps.admin.navigation import navigation_list
29 29 from rhodecode.lib.auth import (LoginRequired, HasPermissionAllDecorator)
30 30 from rhodecode.lib.utils import read_opensource_licenses
31 31
32 32 log = logging.getLogger(__name__)
33 33
34 34
35 class OpenSourceLicensesAdminSettingsView(AdminSettingsView):
35 class OpenSourceLicensesAdminSettingsView(BaseAppView):
36 36
37 37 @LoginRequired()
38 38 @HasPermissionAllDecorator('hg.admin')
39 39 @view_config(
40 40 route_name='admin_settings_open_source', request_method='GET',
41 41 renderer='rhodecode:templates/admin/settings/settings.mako')
42 42 def open_source_licenses(self):
43 43 c.active = 'open_source'
44 44 c.navlist = navigation_list(self.request)
45 45 c.opensource_licenses = collections.OrderedDict(
46 46 sorted(read_opensource_licenses().items(), key=lambda t: t[0]))
47 47
48 48 return {}
@@ -1,98 +1,96 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22
23 23 from pylons import tmpl_context as c
24 24 from pyramid.view import view_config
25 25 from pyramid.httpexceptions import HTTPFound
26 26
27 from rhodecode.translation import _
28
29 from rhodecode.apps.admin.views.base import AdminSettingsView
27 from rhodecode.apps._base import BaseAppView
30 28 from rhodecode.apps.admin.navigation import navigation_list
31 29 from rhodecode.lib.auth import (
32 30 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
33 31 from rhodecode.lib.utils2 import safe_int
34 32 from rhodecode.lib import system_info
35 33 from rhodecode.lib import user_sessions
36 34
37 35
38 36 log = logging.getLogger(__name__)
39 37
40 38
41 class AdminSessionSettingsView(AdminSettingsView):
39 class AdminSessionSettingsView(BaseAppView):
42 40
43 41 @LoginRequired()
44 42 @HasPermissionAllDecorator('hg.admin')
45 43 @view_config(
46 44 route_name='admin_settings_sessions', request_method='GET',
47 45 renderer='rhodecode:templates/admin/settings/settings.mako')
48 46 def settings_sessions(self):
49 47 c.active = 'sessions'
50 48 c.navlist = navigation_list(self.request)
51 49
52 50 c.cleanup_older_days = 60
53 51 older_than_seconds = 60 * 60 * 24 * c.cleanup_older_days
54 52
55 53 config = system_info.rhodecode_config().get_value()['value']['config']
56 54 c.session_model = user_sessions.get_session_handler(
57 55 config.get('beaker.session.type', 'memory'))(config)
58 56
59 57 c.session_conf = c.session_model.config
60 58 c.session_count = c.session_model.get_count()
61 59 c.session_expired_count = c.session_model.get_expired_count(
62 60 older_than_seconds)
63 61
64 62 return {}
65 63
66 64 @LoginRequired()
67 65 @CSRFRequired()
68 66 @HasPermissionAllDecorator('hg.admin')
69 67 @view_config(
70 68 route_name='admin_settings_sessions_cleanup', request_method='POST')
71 69 def settings_sessions_cleanup(self):
72 70 _ = self.request.translate
73 71 expire_days = safe_int(self.request.params.get('expire_days'))
74 72
75 73 if expire_days is None:
76 74 expire_days = 60
77 75
78 76 older_than_seconds = 60 * 60 * 24 * expire_days
79 77
80 78 config = system_info.rhodecode_config().get_value()['value']['config']
81 79 session_model = user_sessions.get_session_handler(
82 80 config.get('beaker.session.type', 'memory'))(config)
83 81
84 82 try:
85 83 session_model.clean_sessions(
86 84 older_than_seconds=older_than_seconds)
87 85 self.request.session.flash(
88 86 _('Cleaned up old sessions'), queue='success')
89 87 except user_sessions.CleanupCommand as msg:
90 88 self.request.session.flash(msg.message, queue='warning')
91 89 except Exception as e:
92 90 log.exception('Failed session cleanup')
93 91 self.request.session.flash(
94 92 _('Failed to cleanup up old sessions'), queue='error')
95 93
96 94 redirect_to = self.request.resource_path(
97 95 self.context, route_name='admin_settings_sessions')
98 96 return HTTPFound(redirect_to)
@@ -1,60 +1,59 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22
23 23 from pyramid.view import view_config
24 24
25 from rhodecode.apps._base import BaseAppView
25 26 from rhodecode.svn_support.utils import generate_mod_dav_svn_config
26
27 from rhodecode.apps.admin.views.base import AdminSettingsView
28 27 from rhodecode.lib.auth import (
29 28 LoginRequired, HasPermissionAllDecorator, CSRFRequired)
30 29
31 30 log = logging.getLogger(__name__)
32 31
33 32
34 class SvnConfigAdminSettingsView(AdminSettingsView):
33 class SvnConfigAdminSettingsView(BaseAppView):
35 34
36 35 @LoginRequired()
37 36 @CSRFRequired()
38 37 @HasPermissionAllDecorator('hg.admin')
39 38 @view_config(
40 39 route_name='admin_settings_vcs_svn_generate_cfg',
41 40 request_method='POST', renderer='json')
42 41 def vcs_svn_generate_config(self):
43 42 _ = self.request.translate
44 43 try:
45 44 generate_mod_dav_svn_config(self.request.registry)
46 45 msg = {
47 46 'message': _('Apache configuration for Subversion generated.'),
48 47 'level': 'success',
49 48 }
50 49 except Exception:
51 50 log.exception(
52 51 'Exception while generating the Apache '
53 52 'configuration for Subversion.')
54 53 msg = {
55 54 'message': _('Failed to generate the Apache configuration for Subversion.'),
56 55 'level': 'error',
57 56 }
58 57
59 58 data = {'message': msg}
60 59 return data
@@ -1,203 +1,203 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2017 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import logging
22 22 import urllib2
23 23 import packaging.version
24 24
25 25 from pylons import tmpl_context as c
26 26 from pyramid.view import view_config
27 27
28 28 import rhodecode
29 from rhodecode.apps.admin.views.base import AdminSettingsView
29 from rhodecode.apps._base import BaseAppView
30 30 from rhodecode.apps.admin.navigation import navigation_list
31 31 from rhodecode.lib import helpers as h
32 32 from rhodecode.lib.auth import (LoginRequired, HasPermissionAllDecorator)
33 33 from rhodecode.lib.utils2 import str2bool
34 34 from rhodecode.lib import system_info
35 35 from rhodecode.lib.ext_json import json
36 36 from rhodecode.model.settings import SettingsModel
37 37
38 38 log = logging.getLogger(__name__)
39 39
40 40
41 class AdminSystemInfoSettingsView(AdminSettingsView):
41 class AdminSystemInfoSettingsView(BaseAppView):
42 42
43 43 @staticmethod
44 44 def get_update_data(update_url):
45 45 """Return the JSON update data."""
46 46 ver = rhodecode.__version__
47 47 log.debug('Checking for upgrade on `%s` server', update_url)
48 48 opener = urllib2.build_opener()
49 49 opener.addheaders = [('User-agent', 'RhodeCode-SCM/%s' % ver)]
50 50 response = opener.open(update_url)
51 51 response_data = response.read()
52 52 data = json.loads(response_data)
53 53
54 54 return data
55 55
56 56 def get_update_url(self):
57 57 settings = SettingsModel().get_all_settings()
58 58 return settings.get('rhodecode_update_url')
59 59
60 60 @LoginRequired()
61 61 @HasPermissionAllDecorator('hg.admin')
62 62 @view_config(
63 63 route_name='admin_settings_system', request_method='GET',
64 64 renderer='rhodecode:templates/admin/settings/settings.mako')
65 65 def settings_system_info(self):
66 66 _ = self.request.translate
67 67
68 68 c.active = 'system'
69 69 c.navlist = navigation_list(self.request)
70 70
71 71 # TODO(marcink), figure out how to allow only selected users to do this
72 72 c.allowed_to_snapshot = self._rhodecode_user.admin
73 73
74 74 snapshot = str2bool(self.request.params.get('snapshot'))
75 75
76 76 c.rhodecode_update_url = self.get_update_url()
77 77 server_info = system_info.get_system_info(self.request.environ)
78 78
79 79 for key, val in server_info.items():
80 80 setattr(c, key, val)
81 81
82 82 def val(name, subkey='human_value'):
83 83 return server_info[name][subkey]
84 84
85 85 def state(name):
86 86 return server_info[name]['state']
87 87
88 88 def val2(name):
89 89 val = server_info[name]['human_value']
90 90 state = server_info[name]['state']
91 91 return val, state
92 92
93 93 update_info_msg = _('Note: please make sure this server can '
94 94 'access `${url}` for the update link to work',
95 95 mapping=dict(url=c.rhodecode_update_url))
96 96 c.data_items = [
97 97 # update info
98 98 (_('Update info'), h.literal(
99 99 '<span class="link" id="check_for_update" >%s.</span>' % (
100 100 _('Check for updates')) +
101 101 '<br/> <span >%s.</span>' % (update_info_msg)
102 102 ), ''),
103 103
104 104 # RhodeCode specific
105 105 (_('RhodeCode Version'), val('rhodecode_app')['text'], state('rhodecode_app')),
106 106 (_('RhodeCode Server IP'), val('server')['server_ip'], state('server')),
107 107 (_('RhodeCode Server ID'), val('server')['server_id'], state('server')),
108 108 (_('RhodeCode Configuration'), val('rhodecode_config')['path'], state('rhodecode_config')),
109 109 (_('Workers'), val('rhodecode_config')['config']['server:main'].get('workers', '?'), state('rhodecode_config')),
110 110 (_('Worker Type'), val('rhodecode_config')['config']['server:main'].get('worker_class', 'sync'), state('rhodecode_config')),
111 111 ('', '', ''), # spacer
112 112
113 113 # Database
114 114 (_('Database'), val('database')['url'], state('database')),
115 115 (_('Database version'), val('database')['version'], state('database')),
116 116 ('', '', ''), # spacer
117 117
118 118 # Platform/Python
119 119 (_('Platform'), val('platform')['name'], state('platform')),
120 120 (_('Platform UUID'), val('platform')['uuid'], state('platform')),
121 121 (_('Python version'), val('python')['version'], state('python')),
122 122 (_('Python path'), val('python')['executable'], state('python')),
123 123 ('', '', ''), # spacer
124 124
125 125 # Systems stats
126 126 (_('CPU'), val('cpu')['text'], state('cpu')),
127 127 (_('Load'), val('load')['text'], state('load')),
128 128 (_('Memory'), val('memory')['text'], state('memory')),
129 129 (_('Uptime'), val('uptime')['text'], state('uptime')),
130 130 ('', '', ''), # spacer
131 131
132 132 # Repo storage
133 133 (_('Storage location'), val('storage')['path'], state('storage')),
134 134 (_('Storage info'), val('storage')['text'], state('storage')),
135 135 (_('Storage inodes'), val('storage_inodes')['text'], state('storage_inodes')),
136 136
137 137 (_('Gist storage location'), val('storage_gist')['path'], state('storage_gist')),
138 138 (_('Gist storage info'), val('storage_gist')['text'], state('storage_gist')),
139 139
140 140 (_('Archive cache storage location'), val('storage_archive')['path'], state('storage_archive')),
141 141 (_('Archive cache info'), val('storage_archive')['text'], state('storage_archive')),
142 142
143 143 (_('Temp storage location'), val('storage_temp')['path'], state('storage_temp')),
144 144 (_('Temp storage info'), val('storage_temp')['text'], state('storage_temp')),
145 145
146 146 (_('Search info'), val('search')['text'], state('search')),
147 147 (_('Search location'), val('search')['location'], state('search')),
148 148 ('', '', ''), # spacer
149 149
150 150 # VCS specific
151 151 (_('VCS Backends'), val('vcs_backends'), state('vcs_backends')),
152 152 (_('VCS Server'), val('vcs_server')['text'], state('vcs_server')),
153 153 (_('GIT'), val('git'), state('git')),
154 154 (_('HG'), val('hg'), state('hg')),
155 155 (_('SVN'), val('svn'), state('svn')),
156 156
157 157 ]
158 158
159 159 if snapshot:
160 160 if c.allowed_to_snapshot:
161 161 c.data_items.pop(0) # remove server info
162 162 self.request.override_renderer = 'admin/settings/settings_system_snapshot.mako'
163 163 else:
164 164 self.request.session.flash(
165 165 'You are not allowed to do this', queue='warning')
166 166 return {}
167 167
168 168 @LoginRequired()
169 169 @HasPermissionAllDecorator('hg.admin')
170 170 @view_config(
171 171 route_name='admin_settings_system_update', request_method='GET',
172 172 renderer='rhodecode:templates/admin/settings/settings_system_update.mako')
173 173 def settings_system_info_check_update(self):
174 174 _ = self.request.translate
175 175
176 176 update_url = self.get_update_url()
177 177
178 178 _err = lambda s: '<div style="color:#ff8888; padding:4px 0px">{}</div>'.format(s)
179 179 try:
180 180 data = self.get_update_data(update_url)
181 181 except urllib2.URLError as e:
182 182 log.exception("Exception contacting upgrade server")
183 183 self.request.override_renderer = 'string'
184 184 return _err('Failed to contact upgrade server: %r' % e)
185 185 except ValueError as e:
186 186 log.exception("Bad data sent from update server")
187 187 self.request.override_renderer = 'string'
188 188 return _err('Bad data sent from update server')
189 189
190 190 latest = data['versions'][0]
191 191
192 192 c.update_url = update_url
193 193 c.latest_data = latest
194 194 c.latest_ver = latest['version']
195 195 c.cur_ver = rhodecode.__version__
196 196 c.should_upgrade = False
197 197
198 198 if (packaging.version.Version(c.latest_ver) >
199 199 packaging.version.Version(c.cur_ver)):
200 200 c.should_upgrade = True
201 201 c.important_notices = latest['general']
202 202
203 203 return {}
1 NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now