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