##// END OF EJS Templates
pyramid: fixed some deprecated calls.
dan -
r3099:abc83359 default
parent child Browse files
Show More
@@ -1,42 +1,50 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2016-2018 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 from rhodecode.apps._base import ADMIN_PREFIX
21 21 from rhodecode.lib.utils2 import str2bool
22 22
23 23
24 def debug_style_enabled(info, request):
25 return str2bool(request.registry.settings.get('debug_style'))
24 class DebugStylePredicate(object):
25 def __init__(self, val, config):
26 self.val = val
26 27
28 def text(self):
29 return 'debug style route = %s' % self.val
30
31 phash = text
32
33 def __call__(self, info, request):
34 str2bool(request.registry.settings.get('debug_style'))
27 35
28 36 def includeme(config):
37 config.add_route_predicate(
38 'debug_style', DebugStylePredicate)
39
29 40 config.add_route(
30 41 name='debug_style_home',
31 42 pattern=ADMIN_PREFIX + '/debug_style',
32 custom_predicates=(debug_style_enabled,))
43 debug_style=True)
33 44 config.add_route(
34 45 name='debug_style_template',
35 46 pattern=ADMIN_PREFIX + '/debug_style/t/{t_path}',
36 custom_predicates=(debug_style_enabled,))
47 debug_style=True)
37 48
38 49 # Scan module for configuration decorators.
39 50 config.scan('.views', ignore='.tests')
40
41
42
@@ -1,230 +1,240 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2012-2018 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 rhodecode.apps._base import ADMIN_PREFIX, add_route_requirements
24 24 from rhodecode.lib.utils2 import safe_int
25 25 from rhodecode.model.db import Repository, Integration, RepoGroup
26 26 from rhodecode.integrations import integration_type_registry
27 27
28 28 log = logging.getLogger(__name__)
29 29
30 30
31 class ValidIntegrationPredicate(object):
32 def __init__(self, val, config):
33 self.val = val
34
35 def text(self):
36 return 'valid_integration_route = %s' % self.val
37
38 phash = text
39
40 def __call__(self, info, request):
41 integration_type = info['match']['integration']
42 integration_id = info['match'].get('integration_id')
43
44 if integration_type not in integration_type_registry:
45 return False
46
47 if integration_id:
48 if not safe_int(integration_id):
49 return False
50
51 integration = Integration.get(integration_id)
52 if not integration:
53 return False
54 if integration.integration_type != integration_type:
55 return False
56
57 # match types to repo or repo group
58 repo_name = info['match'].get('repo_name')
59 repo_group_name = info['match'].get('repo_group_name')
60 repo, repo_group = None, None
61 if repo_name:
62 repo = Repository.get_by_repo_name(repo_name)
63 if not repo:
64 return False
65
66 if repo_group_name:
67 repo_group = RepoGroup.get_by_group_name(repo_group_name)
68 if not repo_group:
69 return False
70
71 if repo and repo.repo_id != integration.repo_id:
72 return False
73 if repo_group and repo_group.group_id != integration.repo_group_id:
74 return False
75
76 return True
77
78
31 79 def includeme(config):
80 config.add_route_predicate(
81 'valid_integration', ValidIntegrationPredicate)
32 82
33 83 # global integrations
34 84 config.add_route('global_integrations_new',
35 85 ADMIN_PREFIX + '/integrations/new')
36 86 config.add_view('rhodecode.integrations.views.GlobalIntegrationsView',
37 87 attr='new_integration',
38 88 renderer='rhodecode:templates/admin/integrations/new.mako',
39 89 request_method='GET',
40 90 route_name='global_integrations_new')
41 91
42 92 config.add_route('global_integrations_home',
43 93 ADMIN_PREFIX + '/integrations')
44 94 config.add_route('global_integrations_list',
45 95 ADMIN_PREFIX + '/integrations/{integration}')
46 96 for route_name in ['global_integrations_home', 'global_integrations_list']:
47 97 config.add_view('rhodecode.integrations.views.GlobalIntegrationsView',
48 98 attr='integration_list',
49 99 renderer='rhodecode:templates/admin/integrations/list.mako',
50 100 request_method='GET',
51 101 route_name=route_name)
52 102
53 103 config.add_route('global_integrations_create',
54 104 ADMIN_PREFIX + '/integrations/{integration}/new',
55 custom_predicates=(valid_integration,))
105 valid_integration=True)
56 106 config.add_route('global_integrations_edit',
57 107 ADMIN_PREFIX + '/integrations/{integration}/{integration_id}',
58 custom_predicates=(valid_integration,))
108 valid_integration=True)
59 109
60 110 for route_name in ['global_integrations_create', 'global_integrations_edit']:
61 111 config.add_view('rhodecode.integrations.views.GlobalIntegrationsView',
62 112 attr='settings_get',
63 113 renderer='rhodecode:templates/admin/integrations/form.mako',
64 114 request_method='GET',
65 115 route_name=route_name)
66 116 config.add_view('rhodecode.integrations.views.GlobalIntegrationsView',
67 117 attr='settings_post',
68 118 renderer='rhodecode:templates/admin/integrations/form.mako',
69 119 request_method='POST',
70 120 route_name=route_name)
71 121
72 122 # repo group integrations
73 123 config.add_route('repo_group_integrations_home',
74 124 add_route_requirements('/{repo_group_name}/_settings/integrations'),
75 125 repo_group_route=True)
76 126
77 127 config.add_view('rhodecode.integrations.views.RepoGroupIntegrationsView',
78 128 attr='integration_list',
79 129 renderer='rhodecode:templates/admin/integrations/list.mako',
80 130 request_method='GET',
81 131 route_name='repo_group_integrations_home')
82 132
83 133 config.add_route('repo_group_integrations_new',
84 134 add_route_requirements('/{repo_group_name}/_settings/integrations/new'),
85 135 repo_group_route=True)
86 136 config.add_view('rhodecode.integrations.views.RepoGroupIntegrationsView',
87 137 attr='new_integration',
88 138 renderer='rhodecode:templates/admin/integrations/new.mako',
89 139 request_method='GET',
90 140 route_name='repo_group_integrations_new')
91 141
92 142 config.add_route('repo_group_integrations_list',
93 143 add_route_requirements('/{repo_group_name}/_settings/integrations/{integration}'),
94 144 repo_group_route=True,
95 custom_predicates=(valid_integration,))
145 valid_integration=True)
96 146 config.add_view('rhodecode.integrations.views.RepoGroupIntegrationsView',
97 147 attr='integration_list',
98 148 renderer='rhodecode:templates/admin/integrations/list.mako',
99 149 request_method='GET',
100 150 route_name='repo_group_integrations_list')
101 151
102 152 config.add_route('repo_group_integrations_create',
103 153 add_route_requirements('/{repo_group_name}/_settings/integrations/{integration}/new'),
104 154 repo_group_route=True,
105 custom_predicates=(valid_integration,))
155 valid_integration=True)
106 156 config.add_view('rhodecode.integrations.views.RepoGroupIntegrationsView',
107 157 attr='settings_get',
108 158 renderer='rhodecode:templates/admin/integrations/form.mako',
109 159 request_method='GET',
110 160 route_name='repo_group_integrations_create')
111 161 config.add_view('rhodecode.integrations.views.RepoGroupIntegrationsView',
112 162 attr='settings_post',
113 163 renderer='rhodecode:templates/admin/integrations/form.mako',
114 164 request_method='POST',
115 165 route_name='repo_group_integrations_create')
116 166
117 167 config.add_route('repo_group_integrations_edit',
118 168 add_route_requirements('/{repo_group_name}/_settings/integrations/{integration}/{integration_id}'),
119 169 repo_group_route=True,
120 custom_predicates=(valid_integration,))
170 valid_integration=True)
121 171
122 172 config.add_view('rhodecode.integrations.views.RepoGroupIntegrationsView',
123 173 attr='settings_get',
124 174 renderer='rhodecode:templates/admin/integrations/form.mako',
125 175 request_method='GET',
126 176 route_name='repo_group_integrations_edit')
127 177 config.add_view('rhodecode.integrations.views.RepoGroupIntegrationsView',
128 178 attr='settings_post',
129 179 renderer='rhodecode:templates/admin/integrations/form.mako',
130 180 request_method='POST',
131 181 route_name='repo_group_integrations_edit')
132 182
133 183 # repo integrations
134 184 config.add_route('repo_integrations_home',
135 185 add_route_requirements('/{repo_name}/settings/integrations'),
136 186 repo_route=True)
137 187 config.add_view('rhodecode.integrations.views.RepoIntegrationsView',
138 188 attr='integration_list',
139 189 request_method='GET',
140 190 renderer='rhodecode:templates/admin/integrations/list.mako',
141 191 route_name='repo_integrations_home')
142 192
143 193 config.add_route('repo_integrations_new',
144 194 add_route_requirements('/{repo_name}/settings/integrations/new'),
145 195 repo_route=True)
146 196 config.add_view('rhodecode.integrations.views.RepoIntegrationsView',
147 197 attr='new_integration',
148 198 renderer='rhodecode:templates/admin/integrations/new.mako',
149 199 request_method='GET',
150 200 route_name='repo_integrations_new')
151 201
152 202 config.add_route('repo_integrations_list',
153 203 add_route_requirements('/{repo_name}/settings/integrations/{integration}'),
154 204 repo_route=True,
155 custom_predicates=(valid_integration,))
205 valid_integration=True)
156 206 config.add_view('rhodecode.integrations.views.RepoIntegrationsView',
157 207 attr='integration_list',
158 208 request_method='GET',
159 209 renderer='rhodecode:templates/admin/integrations/list.mako',
160 210 route_name='repo_integrations_list')
161 211
162 212 config.add_route('repo_integrations_create',
163 213 add_route_requirements('/{repo_name}/settings/integrations/{integration}/new'),
164 214 repo_route=True,
165 custom_predicates=(valid_integration,))
215 valid_integration=True)
166 216 config.add_view('rhodecode.integrations.views.RepoIntegrationsView',
167 217 attr='settings_get',
168 218 renderer='rhodecode:templates/admin/integrations/form.mako',
169 219 request_method='GET',
170 220 route_name='repo_integrations_create')
171 221 config.add_view('rhodecode.integrations.views.RepoIntegrationsView',
172 222 attr='settings_post',
173 223 renderer='rhodecode:templates/admin/integrations/form.mako',
174 224 request_method='POST',
175 225 route_name='repo_integrations_create')
176 226
177 227 config.add_route('repo_integrations_edit',
178 228 add_route_requirements('/{repo_name}/settings/integrations/{integration}/{integration_id}'),
179 229 repo_route=True,
180 custom_predicates=(valid_integration,))
230 valid_integration=True)
181 231 config.add_view('rhodecode.integrations.views.RepoIntegrationsView',
182 232 attr='settings_get',
183 233 renderer='rhodecode:templates/admin/integrations/form.mako',
184 234 request_method='GET',
185 235 route_name='repo_integrations_edit')
186 236 config.add_view('rhodecode.integrations.views.RepoIntegrationsView',
187 237 attr='settings_post',
188 238 renderer='rhodecode:templates/admin/integrations/form.mako',
189 239 request_method='POST',
190 240 route_name='repo_integrations_edit')
191
192
193
194 def valid_integration(info, request):
195 integration_type = info['match']['integration']
196 integration_id = info['match'].get('integration_id')
197
198 if integration_type not in integration_type_registry:
199 return False
200
201 if integration_id:
202 if not safe_int(integration_id):
203 return False
204
205 integration = Integration.get(integration_id)
206 if not integration:
207 return False
208 if integration.integration_type != integration_type:
209 return False
210
211 # match types to repo or repo group
212 repo_name = info['match'].get('repo_name')
213 repo_group_name = info['match'].get('repo_group_name')
214 repo, repo_group = None, None
215 if repo_name:
216 repo = Repository.get_by_repo_name(repo_name)
217 if not repo:
218 return False
219
220 if repo_group_name:
221 repo_group = RepoGroup.get_by_group_name(repo_group_name)
222 if not repo_group:
223 return False
224
225 if repo and repo.repo_id != integration.repo_id:
226 return False
227 if repo_group and repo_group.group_id != integration.repo_group_id:
228 return False
229
230 return True
General Comments 0
You need to be logged in to leave comments. Login now