Show More
@@ -1,569 +1,570 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2010-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 | """ |
|
22 | 22 | this is forms validation classes |
|
23 | 23 | http://formencode.org/module-formencode.validators.html |
|
24 | 24 | for list off all availible validators |
|
25 | 25 | |
|
26 | 26 | we can create our own validators |
|
27 | 27 | |
|
28 | 28 | The table below outlines the options which can be used in a schema in addition to the validators themselves |
|
29 | 29 | pre_validators [] These validators will be applied before the schema |
|
30 | 30 | chained_validators [] These validators will be applied after the schema |
|
31 | 31 | allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present |
|
32 | 32 | filter_extra_fields False If True, then keys that aren't associated with a validator are removed |
|
33 | 33 | if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value. |
|
34 | 34 | ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | <name> = formencode.validators.<name of validator> |
|
38 | 38 | <name> must equal form name |
|
39 | 39 | list=[1,2,3,4,5] |
|
40 | 40 | for SELECT use formencode.All(OneOf(list), Int()) |
|
41 | 41 | |
|
42 | 42 | """ |
|
43 | 43 | |
|
44 | 44 | import deform |
|
45 | 45 | import logging |
|
46 | 46 | import formencode |
|
47 | 47 | |
|
48 | 48 | from pkg_resources import resource_filename |
|
49 | 49 | from formencode import All, Pipe |
|
50 | 50 | |
|
51 | 51 | from pylons.i18n.translation import _ |
|
52 | 52 | from pyramid.threadlocal import get_current_request |
|
53 | 53 | |
|
54 | 54 | from rhodecode import BACKENDS |
|
55 | 55 | from rhodecode.lib import helpers |
|
56 | 56 | from rhodecode.model import validators as v |
|
57 | 57 | |
|
58 | 58 | log = logging.getLogger(__name__) |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | deform_templates = resource_filename('deform', 'templates') |
|
62 | 62 | rhodecode_templates = resource_filename('rhodecode', 'templates/forms') |
|
63 | 63 | search_path = (rhodecode_templates, deform_templates) |
|
64 | 64 | |
|
65 | 65 | |
|
66 | 66 | class RhodecodeFormZPTRendererFactory(deform.ZPTRendererFactory): |
|
67 | 67 | """ Subclass of ZPTRendererFactory to add rhodecode context variables """ |
|
68 | 68 | def __call__(self, template_name, **kw): |
|
69 | 69 | kw['h'] = helpers |
|
70 | 70 | kw['request'] = get_current_request() |
|
71 | 71 | return self.load(template_name)(**kw) |
|
72 | 72 | |
|
73 | 73 | |
|
74 | 74 | form_renderer = RhodecodeFormZPTRendererFactory(search_path) |
|
75 | 75 | deform.Form.set_default_renderer(form_renderer) |
|
76 | 76 | |
|
77 | 77 | |
|
78 | 78 | def LoginForm(): |
|
79 | 79 | class _LoginForm(formencode.Schema): |
|
80 | 80 | allow_extra_fields = True |
|
81 | 81 | filter_extra_fields = True |
|
82 | 82 | username = v.UnicodeString( |
|
83 | 83 | strip=True, |
|
84 | 84 | min=1, |
|
85 | 85 | not_empty=True, |
|
86 | 86 | messages={ |
|
87 | 87 | 'empty': _(u'Please enter a login'), |
|
88 | 88 | 'tooShort': _(u'Enter a value %(min)i characters long or more') |
|
89 | 89 | } |
|
90 | 90 | ) |
|
91 | 91 | |
|
92 | 92 | password = v.UnicodeString( |
|
93 | 93 | strip=False, |
|
94 | 94 | min=3, |
|
95 | max=72, | |
|
95 | 96 | not_empty=True, |
|
96 | 97 | messages={ |
|
97 | 98 | 'empty': _(u'Please enter a password'), |
|
98 | 99 | 'tooShort': _(u'Enter %(min)i characters or more')} |
|
99 | 100 | ) |
|
100 | 101 | |
|
101 | 102 | remember = v.StringBoolean(if_missing=False) |
|
102 | 103 | |
|
103 | 104 | chained_validators = [v.ValidAuth()] |
|
104 | 105 | return _LoginForm |
|
105 | 106 | |
|
106 | 107 | |
|
107 | 108 | def UserForm(edit=False, available_languages=[], old_data={}): |
|
108 | 109 | class _UserForm(formencode.Schema): |
|
109 | 110 | allow_extra_fields = True |
|
110 | 111 | filter_extra_fields = True |
|
111 | 112 | username = All(v.UnicodeString(strip=True, min=1, not_empty=True), |
|
112 | 113 | v.ValidUsername(edit, old_data)) |
|
113 | 114 | if edit: |
|
114 | 115 | new_password = All( |
|
115 | 116 | v.ValidPassword(), |
|
116 | v.UnicodeString(strip=False, min=6, not_empty=False) | |
|
117 | v.UnicodeString(strip=False, min=6, max=72, not_empty=False) | |
|
117 | 118 | ) |
|
118 | 119 | password_confirmation = All( |
|
119 | 120 | v.ValidPassword(), |
|
120 | v.UnicodeString(strip=False, min=6, not_empty=False), | |
|
121 | v.UnicodeString(strip=False, min=6, max=72, not_empty=False), | |
|
121 | 122 | ) |
|
122 | 123 | admin = v.StringBoolean(if_missing=False) |
|
123 | 124 | else: |
|
124 | 125 | password = All( |
|
125 | 126 | v.ValidPassword(), |
|
126 | v.UnicodeString(strip=False, min=6, not_empty=True) | |
|
127 | v.UnicodeString(strip=False, min=6, max=72, not_empty=True) | |
|
127 | 128 | ) |
|
128 | 129 | password_confirmation = All( |
|
129 | 130 | v.ValidPassword(), |
|
130 | v.UnicodeString(strip=False, min=6, not_empty=False) | |
|
131 | v.UnicodeString(strip=False, min=6, max=72, not_empty=False) | |
|
131 | 132 | ) |
|
132 | 133 | |
|
133 | 134 | password_change = v.StringBoolean(if_missing=False) |
|
134 | 135 | create_repo_group = v.StringBoolean(if_missing=False) |
|
135 | 136 | |
|
136 | 137 | active = v.StringBoolean(if_missing=False) |
|
137 | 138 | firstname = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
138 | 139 | lastname = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
139 | 140 | email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data)) |
|
140 | 141 | extern_name = v.UnicodeString(strip=True) |
|
141 | 142 | extern_type = v.UnicodeString(strip=True) |
|
142 | 143 | language = v.OneOf(available_languages, hideList=False, |
|
143 | 144 | testValueList=True, if_missing=None) |
|
144 | 145 | chained_validators = [v.ValidPasswordsMatch()] |
|
145 | 146 | return _UserForm |
|
146 | 147 | |
|
147 | 148 | |
|
148 | 149 | def UserGroupForm(edit=False, old_data=None, allow_disabled=False): |
|
149 | 150 | old_data = old_data or {} |
|
150 | 151 | |
|
151 | 152 | class _UserGroupForm(formencode.Schema): |
|
152 | 153 | allow_extra_fields = True |
|
153 | 154 | filter_extra_fields = True |
|
154 | 155 | |
|
155 | 156 | users_group_name = All( |
|
156 | 157 | v.UnicodeString(strip=True, min=1, not_empty=True), |
|
157 | 158 | v.ValidUserGroup(edit, old_data) |
|
158 | 159 | ) |
|
159 | 160 | user_group_description = v.UnicodeString(strip=True, min=1, |
|
160 | 161 | not_empty=False) |
|
161 | 162 | |
|
162 | 163 | users_group_active = v.StringBoolean(if_missing=False) |
|
163 | 164 | |
|
164 | 165 | if edit: |
|
165 | 166 | # this is user group owner |
|
166 | 167 | user = All( |
|
167 | 168 | v.UnicodeString(not_empty=True), |
|
168 | 169 | v.ValidRepoUser(allow_disabled)) |
|
169 | 170 | return _UserGroupForm |
|
170 | 171 | |
|
171 | 172 | |
|
172 | 173 | def RepoGroupForm(edit=False, old_data=None, available_groups=None, |
|
173 | 174 | can_create_in_root=False, allow_disabled=False): |
|
174 | 175 | old_data = old_data or {} |
|
175 | 176 | available_groups = available_groups or [] |
|
176 | 177 | |
|
177 | 178 | class _RepoGroupForm(formencode.Schema): |
|
178 | 179 | allow_extra_fields = True |
|
179 | 180 | filter_extra_fields = False |
|
180 | 181 | |
|
181 | 182 | group_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), |
|
182 | 183 | v.SlugifyName(),) |
|
183 | 184 | group_description = v.UnicodeString(strip=True, min=1, |
|
184 | 185 | not_empty=False) |
|
185 | 186 | group_copy_permissions = v.StringBoolean(if_missing=False) |
|
186 | 187 | |
|
187 | 188 | group_parent_id = v.OneOf(available_groups, hideList=False, |
|
188 | 189 | testValueList=True, not_empty=True) |
|
189 | 190 | enable_locking = v.StringBoolean(if_missing=False) |
|
190 | 191 | chained_validators = [ |
|
191 | 192 | v.ValidRepoGroup(edit, old_data, can_create_in_root)] |
|
192 | 193 | |
|
193 | 194 | if edit: |
|
194 | 195 | # this is repo group owner |
|
195 | 196 | user = All( |
|
196 | 197 | v.UnicodeString(not_empty=True), |
|
197 | 198 | v.ValidRepoUser(allow_disabled)) |
|
198 | 199 | |
|
199 | 200 | return _RepoGroupForm |
|
200 | 201 | |
|
201 | 202 | |
|
202 | 203 | def RegisterForm(edit=False, old_data={}): |
|
203 | 204 | class _RegisterForm(formencode.Schema): |
|
204 | 205 | allow_extra_fields = True |
|
205 | 206 | filter_extra_fields = True |
|
206 | 207 | username = All( |
|
207 | 208 | v.ValidUsername(edit, old_data), |
|
208 | 209 | v.UnicodeString(strip=True, min=1, not_empty=True) |
|
209 | 210 | ) |
|
210 | 211 | password = All( |
|
211 | 212 | v.ValidPassword(), |
|
212 | v.UnicodeString(strip=False, min=6, not_empty=True) | |
|
213 | v.UnicodeString(strip=False, min=6, max=72, not_empty=True) | |
|
213 | 214 | ) |
|
214 | 215 | password_confirmation = All( |
|
215 | 216 | v.ValidPassword(), |
|
216 | v.UnicodeString(strip=False, min=6, not_empty=True) | |
|
217 | v.UnicodeString(strip=False, min=6, max=72, not_empty=True) | |
|
217 | 218 | ) |
|
218 | 219 | active = v.StringBoolean(if_missing=False) |
|
219 | 220 | firstname = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
220 | 221 | lastname = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
221 | 222 | email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data)) |
|
222 | 223 | |
|
223 | 224 | chained_validators = [v.ValidPasswordsMatch()] |
|
224 | 225 | |
|
225 | 226 | return _RegisterForm |
|
226 | 227 | |
|
227 | 228 | |
|
228 | 229 | def PasswordResetForm(): |
|
229 | 230 | class _PasswordResetForm(formencode.Schema): |
|
230 | 231 | allow_extra_fields = True |
|
231 | 232 | filter_extra_fields = True |
|
232 | 233 | email = All(v.ValidSystemEmail(), v.Email(not_empty=True)) |
|
233 | 234 | return _PasswordResetForm |
|
234 | 235 | |
|
235 | 236 | |
|
236 | 237 | def RepoForm(edit=False, old_data=None, repo_groups=None, landing_revs=None, |
|
237 | 238 | allow_disabled=False): |
|
238 | 239 | old_data = old_data or {} |
|
239 | 240 | repo_groups = repo_groups or [] |
|
240 | 241 | landing_revs = landing_revs or [] |
|
241 | 242 | supported_backends = BACKENDS.keys() |
|
242 | 243 | |
|
243 | 244 | class _RepoForm(formencode.Schema): |
|
244 | 245 | allow_extra_fields = True |
|
245 | 246 | filter_extra_fields = False |
|
246 | 247 | repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), |
|
247 | 248 | v.SlugifyName(), v.CannotHaveGitSuffix()) |
|
248 | 249 | repo_group = All(v.CanWriteGroup(old_data), |
|
249 | 250 | v.OneOf(repo_groups, hideList=True)) |
|
250 | 251 | repo_type = v.OneOf(supported_backends, required=False, |
|
251 | 252 | if_missing=old_data.get('repo_type')) |
|
252 | 253 | repo_description = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
253 | 254 | repo_private = v.StringBoolean(if_missing=False) |
|
254 | 255 | repo_landing_rev = v.OneOf(landing_revs, hideList=True) |
|
255 | 256 | repo_copy_permissions = v.StringBoolean(if_missing=False) |
|
256 | 257 | clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False)) |
|
257 | 258 | |
|
258 | 259 | repo_enable_statistics = v.StringBoolean(if_missing=False) |
|
259 | 260 | repo_enable_downloads = v.StringBoolean(if_missing=False) |
|
260 | 261 | repo_enable_locking = v.StringBoolean(if_missing=False) |
|
261 | 262 | |
|
262 | 263 | if edit: |
|
263 | 264 | # this is repo owner |
|
264 | 265 | user = All( |
|
265 | 266 | v.UnicodeString(not_empty=True), |
|
266 | 267 | v.ValidRepoUser(allow_disabled)) |
|
267 | 268 | clone_uri_change = v.UnicodeString( |
|
268 | 269 | not_empty=False, if_missing=v.Missing) |
|
269 | 270 | |
|
270 | 271 | chained_validators = [v.ValidCloneUri(), |
|
271 | 272 | v.ValidRepoName(edit, old_data)] |
|
272 | 273 | return _RepoForm |
|
273 | 274 | |
|
274 | 275 | |
|
275 | 276 | def RepoPermsForm(): |
|
276 | 277 | class _RepoPermsForm(formencode.Schema): |
|
277 | 278 | allow_extra_fields = True |
|
278 | 279 | filter_extra_fields = False |
|
279 | 280 | chained_validators = [v.ValidPerms(type_='repo')] |
|
280 | 281 | return _RepoPermsForm |
|
281 | 282 | |
|
282 | 283 | |
|
283 | 284 | def RepoGroupPermsForm(valid_recursive_choices): |
|
284 | 285 | class _RepoGroupPermsForm(formencode.Schema): |
|
285 | 286 | allow_extra_fields = True |
|
286 | 287 | filter_extra_fields = False |
|
287 | 288 | recursive = v.OneOf(valid_recursive_choices) |
|
288 | 289 | chained_validators = [v.ValidPerms(type_='repo_group')] |
|
289 | 290 | return _RepoGroupPermsForm |
|
290 | 291 | |
|
291 | 292 | |
|
292 | 293 | def UserGroupPermsForm(): |
|
293 | 294 | class _UserPermsForm(formencode.Schema): |
|
294 | 295 | allow_extra_fields = True |
|
295 | 296 | filter_extra_fields = False |
|
296 | 297 | chained_validators = [v.ValidPerms(type_='user_group')] |
|
297 | 298 | return _UserPermsForm |
|
298 | 299 | |
|
299 | 300 | |
|
300 | 301 | def RepoFieldForm(): |
|
301 | 302 | class _RepoFieldForm(formencode.Schema): |
|
302 | 303 | filter_extra_fields = True |
|
303 | 304 | allow_extra_fields = True |
|
304 | 305 | |
|
305 | 306 | new_field_key = All(v.FieldKey(), |
|
306 | 307 | v.UnicodeString(strip=True, min=3, not_empty=True)) |
|
307 | 308 | new_field_value = v.UnicodeString(not_empty=False, if_missing=u'') |
|
308 | 309 | new_field_type = v.OneOf(['str', 'unicode', 'list', 'tuple'], |
|
309 | 310 | if_missing='str') |
|
310 | 311 | new_field_label = v.UnicodeString(not_empty=False) |
|
311 | 312 | new_field_desc = v.UnicodeString(not_empty=False) |
|
312 | 313 | |
|
313 | 314 | return _RepoFieldForm |
|
314 | 315 | |
|
315 | 316 | |
|
316 | 317 | def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(), |
|
317 | 318 | repo_groups=[], landing_revs=[]): |
|
318 | 319 | class _RepoForkForm(formencode.Schema): |
|
319 | 320 | allow_extra_fields = True |
|
320 | 321 | filter_extra_fields = False |
|
321 | 322 | repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True), |
|
322 | 323 | v.SlugifyName()) |
|
323 | 324 | repo_group = All(v.CanWriteGroup(), |
|
324 | 325 | v.OneOf(repo_groups, hideList=True)) |
|
325 | 326 | repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends)) |
|
326 | 327 | description = v.UnicodeString(strip=True, min=1, not_empty=True) |
|
327 | 328 | private = v.StringBoolean(if_missing=False) |
|
328 | 329 | copy_permissions = v.StringBoolean(if_missing=False) |
|
329 | 330 | fork_parent_id = v.UnicodeString() |
|
330 | 331 | chained_validators = [v.ValidForkName(edit, old_data)] |
|
331 | 332 | landing_rev = v.OneOf(landing_revs, hideList=True) |
|
332 | 333 | |
|
333 | 334 | return _RepoForkForm |
|
334 | 335 | |
|
335 | 336 | |
|
336 | 337 | def ApplicationSettingsForm(): |
|
337 | 338 | class _ApplicationSettingsForm(formencode.Schema): |
|
338 | 339 | allow_extra_fields = True |
|
339 | 340 | filter_extra_fields = False |
|
340 | 341 | rhodecode_title = v.UnicodeString(strip=True, max=40, not_empty=False) |
|
341 | 342 | rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True) |
|
342 | 343 | rhodecode_pre_code = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
343 | 344 | rhodecode_post_code = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
344 | 345 | rhodecode_captcha_public_key = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
345 | 346 | rhodecode_captcha_private_key = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
346 | 347 | rhodecode_create_personal_repo_group = v.StringBoolean(if_missing=False) |
|
347 | 348 | rhodecode_personal_repo_group_pattern = v.UnicodeString(strip=True, min=1, not_empty=False) |
|
348 | 349 | |
|
349 | 350 | return _ApplicationSettingsForm |
|
350 | 351 | |
|
351 | 352 | |
|
352 | 353 | def ApplicationVisualisationForm(): |
|
353 | 354 | class _ApplicationVisualisationForm(formencode.Schema): |
|
354 | 355 | allow_extra_fields = True |
|
355 | 356 | filter_extra_fields = False |
|
356 | 357 | rhodecode_show_public_icon = v.StringBoolean(if_missing=False) |
|
357 | 358 | rhodecode_show_private_icon = v.StringBoolean(if_missing=False) |
|
358 | 359 | rhodecode_stylify_metatags = v.StringBoolean(if_missing=False) |
|
359 | 360 | |
|
360 | 361 | rhodecode_repository_fields = v.StringBoolean(if_missing=False) |
|
361 | 362 | rhodecode_lightweight_journal = v.StringBoolean(if_missing=False) |
|
362 | 363 | rhodecode_dashboard_items = v.Int(min=5, not_empty=True) |
|
363 | 364 | rhodecode_admin_grid_items = v.Int(min=5, not_empty=True) |
|
364 | 365 | rhodecode_show_version = v.StringBoolean(if_missing=False) |
|
365 | 366 | rhodecode_use_gravatar = v.StringBoolean(if_missing=False) |
|
366 | 367 | rhodecode_markup_renderer = v.OneOf(['markdown', 'rst']) |
|
367 | 368 | rhodecode_gravatar_url = v.UnicodeString(min=3) |
|
368 | 369 | rhodecode_clone_uri_tmpl = v.UnicodeString(min=3) |
|
369 | 370 | rhodecode_support_url = v.UnicodeString() |
|
370 | 371 | rhodecode_show_revision_number = v.StringBoolean(if_missing=False) |
|
371 | 372 | rhodecode_show_sha_length = v.Int(min=4, not_empty=True) |
|
372 | 373 | |
|
373 | 374 | return _ApplicationVisualisationForm |
|
374 | 375 | |
|
375 | 376 | |
|
376 | 377 | class _BaseVcsSettingsForm(formencode.Schema): |
|
377 | 378 | allow_extra_fields = True |
|
378 | 379 | filter_extra_fields = False |
|
379 | 380 | hooks_changegroup_repo_size = v.StringBoolean(if_missing=False) |
|
380 | 381 | hooks_changegroup_push_logger = v.StringBoolean(if_missing=False) |
|
381 | 382 | hooks_outgoing_pull_logger = v.StringBoolean(if_missing=False) |
|
382 | 383 | |
|
383 | 384 | # PR/Code-review |
|
384 | 385 | rhodecode_pr_merge_enabled = v.StringBoolean(if_missing=False) |
|
385 | 386 | rhodecode_use_outdated_comments = v.StringBoolean(if_missing=False) |
|
386 | 387 | |
|
387 | 388 | # hg |
|
388 | 389 | extensions_largefiles = v.StringBoolean(if_missing=False) |
|
389 | 390 | extensions_evolve = v.StringBoolean(if_missing=False) |
|
390 | 391 | phases_publish = v.StringBoolean(if_missing=False) |
|
391 | 392 | |
|
392 | 393 | rhodecode_hg_use_rebase_for_merging = v.StringBoolean(if_missing=False) |
|
393 | 394 | rhodecode_hg_close_branch_before_merging = v.StringBoolean(if_missing=False) |
|
394 | 395 | |
|
395 | 396 | # git |
|
396 | 397 | vcs_git_lfs_enabled = v.StringBoolean(if_missing=False) |
|
397 | 398 | rhodecode_git_use_rebase_for_merging = v.StringBoolean(if_missing=False) |
|
398 | 399 | rhodecode_git_close_branch_before_merging = v.StringBoolean(if_missing=False) |
|
399 | 400 | |
|
400 | 401 | # svn |
|
401 | 402 | vcs_svn_proxy_http_requests_enabled = v.StringBoolean(if_missing=False) |
|
402 | 403 | vcs_svn_proxy_http_server_url = v.UnicodeString(strip=True, if_missing=None) |
|
403 | 404 | |
|
404 | 405 | |
|
405 | 406 | def ApplicationUiSettingsForm(): |
|
406 | 407 | class _ApplicationUiSettingsForm(_BaseVcsSettingsForm): |
|
407 | 408 | web_push_ssl = v.StringBoolean(if_missing=False) |
|
408 | 409 | paths_root_path = All( |
|
409 | 410 | v.ValidPath(), |
|
410 | 411 | v.UnicodeString(strip=True, min=1, not_empty=True) |
|
411 | 412 | ) |
|
412 | 413 | largefiles_usercache = All( |
|
413 | 414 | v.ValidPath(), |
|
414 | 415 | v.UnicodeString(strip=True, min=2, not_empty=True)) |
|
415 | 416 | vcs_git_lfs_store_location = All( |
|
416 | 417 | v.ValidPath(), |
|
417 | 418 | v.UnicodeString(strip=True, min=2, not_empty=True)) |
|
418 | 419 | extensions_hgsubversion = v.StringBoolean(if_missing=False) |
|
419 | 420 | extensions_hggit = v.StringBoolean(if_missing=False) |
|
420 | 421 | new_svn_branch = v.ValidSvnPattern(section='vcs_svn_branch') |
|
421 | 422 | new_svn_tag = v.ValidSvnPattern(section='vcs_svn_tag') |
|
422 | 423 | |
|
423 | 424 | return _ApplicationUiSettingsForm |
|
424 | 425 | |
|
425 | 426 | |
|
426 | 427 | def RepoVcsSettingsForm(repo_name): |
|
427 | 428 | class _RepoVcsSettingsForm(_BaseVcsSettingsForm): |
|
428 | 429 | inherit_global_settings = v.StringBoolean(if_missing=False) |
|
429 | 430 | new_svn_branch = v.ValidSvnPattern( |
|
430 | 431 | section='vcs_svn_branch', repo_name=repo_name) |
|
431 | 432 | new_svn_tag = v.ValidSvnPattern( |
|
432 | 433 | section='vcs_svn_tag', repo_name=repo_name) |
|
433 | 434 | |
|
434 | 435 | return _RepoVcsSettingsForm |
|
435 | 436 | |
|
436 | 437 | |
|
437 | 438 | def LabsSettingsForm(): |
|
438 | 439 | class _LabSettingsForm(formencode.Schema): |
|
439 | 440 | allow_extra_fields = True |
|
440 | 441 | filter_extra_fields = False |
|
441 | 442 | |
|
442 | 443 | return _LabSettingsForm |
|
443 | 444 | |
|
444 | 445 | |
|
445 | 446 | def ApplicationPermissionsForm( |
|
446 | 447 | register_choices, password_reset_choices, extern_activate_choices): |
|
447 | 448 | class _DefaultPermissionsForm(formencode.Schema): |
|
448 | 449 | allow_extra_fields = True |
|
449 | 450 | filter_extra_fields = True |
|
450 | 451 | |
|
451 | 452 | anonymous = v.StringBoolean(if_missing=False) |
|
452 | 453 | default_register = v.OneOf(register_choices) |
|
453 | 454 | default_register_message = v.UnicodeString() |
|
454 | 455 | default_password_reset = v.OneOf(password_reset_choices) |
|
455 | 456 | default_extern_activate = v.OneOf(extern_activate_choices) |
|
456 | 457 | |
|
457 | 458 | return _DefaultPermissionsForm |
|
458 | 459 | |
|
459 | 460 | |
|
460 | 461 | def ObjectPermissionsForm(repo_perms_choices, group_perms_choices, |
|
461 | 462 | user_group_perms_choices): |
|
462 | 463 | class _ObjectPermissionsForm(formencode.Schema): |
|
463 | 464 | allow_extra_fields = True |
|
464 | 465 | filter_extra_fields = True |
|
465 | 466 | overwrite_default_repo = v.StringBoolean(if_missing=False) |
|
466 | 467 | overwrite_default_group = v.StringBoolean(if_missing=False) |
|
467 | 468 | overwrite_default_user_group = v.StringBoolean(if_missing=False) |
|
468 | 469 | default_repo_perm = v.OneOf(repo_perms_choices) |
|
469 | 470 | default_group_perm = v.OneOf(group_perms_choices) |
|
470 | 471 | default_user_group_perm = v.OneOf(user_group_perms_choices) |
|
471 | 472 | |
|
472 | 473 | return _ObjectPermissionsForm |
|
473 | 474 | |
|
474 | 475 | |
|
475 | 476 | def UserPermissionsForm(create_choices, create_on_write_choices, |
|
476 | 477 | repo_group_create_choices, user_group_create_choices, |
|
477 | 478 | fork_choices, inherit_default_permissions_choices): |
|
478 | 479 | class _DefaultPermissionsForm(formencode.Schema): |
|
479 | 480 | allow_extra_fields = True |
|
480 | 481 | filter_extra_fields = True |
|
481 | 482 | |
|
482 | 483 | anonymous = v.StringBoolean(if_missing=False) |
|
483 | 484 | |
|
484 | 485 | default_repo_create = v.OneOf(create_choices) |
|
485 | 486 | default_repo_create_on_write = v.OneOf(create_on_write_choices) |
|
486 | 487 | default_user_group_create = v.OneOf(user_group_create_choices) |
|
487 | 488 | default_repo_group_create = v.OneOf(repo_group_create_choices) |
|
488 | 489 | default_fork_create = v.OneOf(fork_choices) |
|
489 | 490 | default_inherit_default_permissions = v.OneOf(inherit_default_permissions_choices) |
|
490 | 491 | |
|
491 | 492 | return _DefaultPermissionsForm |
|
492 | 493 | |
|
493 | 494 | |
|
494 | 495 | def UserIndividualPermissionsForm(): |
|
495 | 496 | class _DefaultPermissionsForm(formencode.Schema): |
|
496 | 497 | allow_extra_fields = True |
|
497 | 498 | filter_extra_fields = True |
|
498 | 499 | |
|
499 | 500 | inherit_default_permissions = v.StringBoolean(if_missing=False) |
|
500 | 501 | |
|
501 | 502 | return _DefaultPermissionsForm |
|
502 | 503 | |
|
503 | 504 | |
|
504 | 505 | def DefaultsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()): |
|
505 | 506 | class _DefaultsForm(formencode.Schema): |
|
506 | 507 | allow_extra_fields = True |
|
507 | 508 | filter_extra_fields = True |
|
508 | 509 | default_repo_type = v.OneOf(supported_backends) |
|
509 | 510 | default_repo_private = v.StringBoolean(if_missing=False) |
|
510 | 511 | default_repo_enable_statistics = v.StringBoolean(if_missing=False) |
|
511 | 512 | default_repo_enable_downloads = v.StringBoolean(if_missing=False) |
|
512 | 513 | default_repo_enable_locking = v.StringBoolean(if_missing=False) |
|
513 | 514 | |
|
514 | 515 | return _DefaultsForm |
|
515 | 516 | |
|
516 | 517 | |
|
517 | 518 | def AuthSettingsForm(): |
|
518 | 519 | class _AuthSettingsForm(formencode.Schema): |
|
519 | 520 | allow_extra_fields = True |
|
520 | 521 | filter_extra_fields = True |
|
521 | 522 | auth_plugins = All(v.ValidAuthPlugins(), |
|
522 | 523 | v.UniqueListFromString()(not_empty=True)) |
|
523 | 524 | |
|
524 | 525 | return _AuthSettingsForm |
|
525 | 526 | |
|
526 | 527 | |
|
527 | 528 | def UserExtraEmailForm(): |
|
528 | 529 | class _UserExtraEmailForm(formencode.Schema): |
|
529 | 530 | email = All(v.UniqSystemEmail(), v.Email(not_empty=True)) |
|
530 | 531 | return _UserExtraEmailForm |
|
531 | 532 | |
|
532 | 533 | |
|
533 | 534 | def UserExtraIpForm(): |
|
534 | 535 | class _UserExtraIpForm(formencode.Schema): |
|
535 | 536 | ip = v.ValidIp()(not_empty=True) |
|
536 | 537 | return _UserExtraIpForm |
|
537 | 538 | |
|
538 | 539 | |
|
539 | 540 | |
|
540 | 541 | def PullRequestForm(repo_id): |
|
541 | 542 | class ReviewerForm(formencode.Schema): |
|
542 | 543 | user_id = v.Int(not_empty=True) |
|
543 | 544 | reasons = All() |
|
544 | 545 | mandatory = v.StringBoolean() |
|
545 | 546 | |
|
546 | 547 | class _PullRequestForm(formencode.Schema): |
|
547 | 548 | allow_extra_fields = True |
|
548 | 549 | filter_extra_fields = True |
|
549 | 550 | |
|
550 | 551 | common_ancestor = v.UnicodeString(strip=True, required=True) |
|
551 | 552 | source_repo = v.UnicodeString(strip=True, required=True) |
|
552 | 553 | source_ref = v.UnicodeString(strip=True, required=True) |
|
553 | 554 | target_repo = v.UnicodeString(strip=True, required=True) |
|
554 | 555 | target_ref = v.UnicodeString(strip=True, required=True) |
|
555 | 556 | revisions = All(#v.NotReviewedRevisions(repo_id)(), |
|
556 | 557 | v.UniqueList()(not_empty=True)) |
|
557 | 558 | review_members = formencode.ForEach(ReviewerForm()) |
|
558 | 559 | pullrequest_title = v.UnicodeString(strip=True, required=True) |
|
559 | 560 | pullrequest_desc = v.UnicodeString(strip=True, required=False) |
|
560 | 561 | |
|
561 | 562 | return _PullRequestForm |
|
562 | 563 | |
|
563 | 564 | |
|
564 | 565 | def IssueTrackerPatternsForm(): |
|
565 | 566 | class _IssueTrackerPatternsForm(formencode.Schema): |
|
566 | 567 | allow_extra_fields = True |
|
567 | 568 | filter_extra_fields = False |
|
568 | 569 | chained_validators = [v.ValidPattern()] |
|
569 | 570 | return _IssueTrackerPatternsForm |
General Comments 0
You need to be logged in to leave comments.
Login now