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