##// END OF EJS Templates
security: limit the maximum password lenght to 72 characters to prevent possible...
ergo -
r2128:f22a9ea9 default
parent child Browse files
Show More
@@ -1,569 +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 not_empty=True,
96 not_empty=True,
96 messages={
97 messages={
97 'empty': _(u'Please enter a password'),
98 'empty': _(u'Please enter a password'),
98 'tooShort': _(u'Enter %(min)i characters or more')}
99 'tooShort': _(u'Enter %(min)i characters or more')}
99 )
100 )
100
101
101 remember = v.StringBoolean(if_missing=False)
102 remember = v.StringBoolean(if_missing=False)
102
103
103 chained_validators = [v.ValidAuth()]
104 chained_validators = [v.ValidAuth()]
104 return _LoginForm
105 return _LoginForm
105
106
106
107
107 def UserForm(edit=False, available_languages=[], old_data={}):
108 def UserForm(edit=False, available_languages=[], old_data={}):
108 class _UserForm(formencode.Schema):
109 class _UserForm(formencode.Schema):
109 allow_extra_fields = True
110 allow_extra_fields = True
110 filter_extra_fields = True
111 filter_extra_fields = True
111 username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
112 username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
112 v.ValidUsername(edit, old_data))
113 v.ValidUsername(edit, old_data))
113 if edit:
114 if edit:
114 new_password = All(
115 new_password = All(
115 v.ValidPassword(),
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 password_confirmation = All(
119 password_confirmation = All(
119 v.ValidPassword(),
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 admin = v.StringBoolean(if_missing=False)
123 admin = v.StringBoolean(if_missing=False)
123 else:
124 else:
124 password = All(
125 password = All(
125 v.ValidPassword(),
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 password_confirmation = All(
129 password_confirmation = All(
129 v.ValidPassword(),
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 password_change = v.StringBoolean(if_missing=False)
134 password_change = v.StringBoolean(if_missing=False)
134 create_repo_group = v.StringBoolean(if_missing=False)
135 create_repo_group = v.StringBoolean(if_missing=False)
135
136
136 active = v.StringBoolean(if_missing=False)
137 active = v.StringBoolean(if_missing=False)
137 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
138 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
138 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
139 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
139 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
140 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
140 extern_name = v.UnicodeString(strip=True)
141 extern_name = v.UnicodeString(strip=True)
141 extern_type = v.UnicodeString(strip=True)
142 extern_type = v.UnicodeString(strip=True)
142 language = v.OneOf(available_languages, hideList=False,
143 language = v.OneOf(available_languages, hideList=False,
143 testValueList=True, if_missing=None)
144 testValueList=True, if_missing=None)
144 chained_validators = [v.ValidPasswordsMatch()]
145 chained_validators = [v.ValidPasswordsMatch()]
145 return _UserForm
146 return _UserForm
146
147
147
148
148 def UserGroupForm(edit=False, old_data=None, allow_disabled=False):
149 def UserGroupForm(edit=False, old_data=None, allow_disabled=False):
149 old_data = old_data or {}
150 old_data = old_data or {}
150
151
151 class _UserGroupForm(formencode.Schema):
152 class _UserGroupForm(formencode.Schema):
152 allow_extra_fields = True
153 allow_extra_fields = True
153 filter_extra_fields = True
154 filter_extra_fields = True
154
155
155 users_group_name = All(
156 users_group_name = All(
156 v.UnicodeString(strip=True, min=1, not_empty=True),
157 v.UnicodeString(strip=True, min=1, not_empty=True),
157 v.ValidUserGroup(edit, old_data)
158 v.ValidUserGroup(edit, old_data)
158 )
159 )
159 user_group_description = v.UnicodeString(strip=True, min=1,
160 user_group_description = v.UnicodeString(strip=True, min=1,
160 not_empty=False)
161 not_empty=False)
161
162
162 users_group_active = v.StringBoolean(if_missing=False)
163 users_group_active = v.StringBoolean(if_missing=False)
163
164
164 if edit:
165 if edit:
165 # this is user group owner
166 # this is user group owner
166 user = All(
167 user = All(
167 v.UnicodeString(not_empty=True),
168 v.UnicodeString(not_empty=True),
168 v.ValidRepoUser(allow_disabled))
169 v.ValidRepoUser(allow_disabled))
169 return _UserGroupForm
170 return _UserGroupForm
170
171
171
172
172 def RepoGroupForm(edit=False, old_data=None, available_groups=None,
173 def RepoGroupForm(edit=False, old_data=None, available_groups=None,
173 can_create_in_root=False, allow_disabled=False):
174 can_create_in_root=False, allow_disabled=False):
174 old_data = old_data or {}
175 old_data = old_data or {}
175 available_groups = available_groups or []
176 available_groups = available_groups or []
176
177
177 class _RepoGroupForm(formencode.Schema):
178 class _RepoGroupForm(formencode.Schema):
178 allow_extra_fields = True
179 allow_extra_fields = True
179 filter_extra_fields = False
180 filter_extra_fields = False
180
181
181 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),
182 v.SlugifyName(),)
183 v.SlugifyName(),)
183 group_description = v.UnicodeString(strip=True, min=1,
184 group_description = v.UnicodeString(strip=True, min=1,
184 not_empty=False)
185 not_empty=False)
185 group_copy_permissions = v.StringBoolean(if_missing=False)
186 group_copy_permissions = v.StringBoolean(if_missing=False)
186
187
187 group_parent_id = v.OneOf(available_groups, hideList=False,
188 group_parent_id = v.OneOf(available_groups, hideList=False,
188 testValueList=True, not_empty=True)
189 testValueList=True, not_empty=True)
189 enable_locking = v.StringBoolean(if_missing=False)
190 enable_locking = v.StringBoolean(if_missing=False)
190 chained_validators = [
191 chained_validators = [
191 v.ValidRepoGroup(edit, old_data, can_create_in_root)]
192 v.ValidRepoGroup(edit, old_data, can_create_in_root)]
192
193
193 if edit:
194 if edit:
194 # this is repo group owner
195 # this is repo group owner
195 user = All(
196 user = All(
196 v.UnicodeString(not_empty=True),
197 v.UnicodeString(not_empty=True),
197 v.ValidRepoUser(allow_disabled))
198 v.ValidRepoUser(allow_disabled))
198
199
199 return _RepoGroupForm
200 return _RepoGroupForm
200
201
201
202
202 def RegisterForm(edit=False, old_data={}):
203 def RegisterForm(edit=False, old_data={}):
203 class _RegisterForm(formencode.Schema):
204 class _RegisterForm(formencode.Schema):
204 allow_extra_fields = True
205 allow_extra_fields = True
205 filter_extra_fields = True
206 filter_extra_fields = True
206 username = All(
207 username = All(
207 v.ValidUsername(edit, old_data),
208 v.ValidUsername(edit, old_data),
208 v.UnicodeString(strip=True, min=1, not_empty=True)
209 v.UnicodeString(strip=True, min=1, not_empty=True)
209 )
210 )
210 password = All(
211 password = All(
211 v.ValidPassword(),
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 password_confirmation = All(
215 password_confirmation = All(
215 v.ValidPassword(),
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 active = v.StringBoolean(if_missing=False)
219 active = v.StringBoolean(if_missing=False)
219 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
220 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
220 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
221 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
221 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
222 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
222
223
223 chained_validators = [v.ValidPasswordsMatch()]
224 chained_validators = [v.ValidPasswordsMatch()]
224
225
225 return _RegisterForm
226 return _RegisterForm
226
227
227
228
228 def PasswordResetForm():
229 def PasswordResetForm():
229 class _PasswordResetForm(formencode.Schema):
230 class _PasswordResetForm(formencode.Schema):
230 allow_extra_fields = True
231 allow_extra_fields = True
231 filter_extra_fields = True
232 filter_extra_fields = True
232 email = All(v.ValidSystemEmail(), v.Email(not_empty=True))
233 email = All(v.ValidSystemEmail(), v.Email(not_empty=True))
233 return _PasswordResetForm
234 return _PasswordResetForm
234
235
235
236
236 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,
237 allow_disabled=False):
238 allow_disabled=False):
238 old_data = old_data or {}
239 old_data = old_data or {}
239 repo_groups = repo_groups or []
240 repo_groups = repo_groups or []
240 landing_revs = landing_revs or []
241 landing_revs = landing_revs or []
241 supported_backends = BACKENDS.keys()
242 supported_backends = BACKENDS.keys()
242
243
243 class _RepoForm(formencode.Schema):
244 class _RepoForm(formencode.Schema):
244 allow_extra_fields = True
245 allow_extra_fields = True
245 filter_extra_fields = False
246 filter_extra_fields = False
246 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),
247 v.SlugifyName(), v.CannotHaveGitSuffix())
248 v.SlugifyName(), v.CannotHaveGitSuffix())
248 repo_group = All(v.CanWriteGroup(old_data),
249 repo_group = All(v.CanWriteGroup(old_data),
249 v.OneOf(repo_groups, hideList=True))
250 v.OneOf(repo_groups, hideList=True))
250 repo_type = v.OneOf(supported_backends, required=False,
251 repo_type = v.OneOf(supported_backends, required=False,
251 if_missing=old_data.get('repo_type'))
252 if_missing=old_data.get('repo_type'))
252 repo_description = v.UnicodeString(strip=True, min=1, not_empty=False)
253 repo_description = v.UnicodeString(strip=True, min=1, not_empty=False)
253 repo_private = v.StringBoolean(if_missing=False)
254 repo_private = v.StringBoolean(if_missing=False)
254 repo_landing_rev = v.OneOf(landing_revs, hideList=True)
255 repo_landing_rev = v.OneOf(landing_revs, hideList=True)
255 repo_copy_permissions = v.StringBoolean(if_missing=False)
256 repo_copy_permissions = v.StringBoolean(if_missing=False)
256 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))
257
258
258 repo_enable_statistics = v.StringBoolean(if_missing=False)
259 repo_enable_statistics = v.StringBoolean(if_missing=False)
259 repo_enable_downloads = v.StringBoolean(if_missing=False)
260 repo_enable_downloads = v.StringBoolean(if_missing=False)
260 repo_enable_locking = v.StringBoolean(if_missing=False)
261 repo_enable_locking = v.StringBoolean(if_missing=False)
261
262
262 if edit:
263 if edit:
263 # this is repo owner
264 # this is repo owner
264 user = All(
265 user = All(
265 v.UnicodeString(not_empty=True),
266 v.UnicodeString(not_empty=True),
266 v.ValidRepoUser(allow_disabled))
267 v.ValidRepoUser(allow_disabled))
267 clone_uri_change = v.UnicodeString(
268 clone_uri_change = v.UnicodeString(
268 not_empty=False, if_missing=v.Missing)
269 not_empty=False, if_missing=v.Missing)
269
270
270 chained_validators = [v.ValidCloneUri(),
271 chained_validators = [v.ValidCloneUri(),
271 v.ValidRepoName(edit, old_data)]
272 v.ValidRepoName(edit, old_data)]
272 return _RepoForm
273 return _RepoForm
273
274
274
275
275 def RepoPermsForm():
276 def RepoPermsForm():
276 class _RepoPermsForm(formencode.Schema):
277 class _RepoPermsForm(formencode.Schema):
277 allow_extra_fields = True
278 allow_extra_fields = True
278 filter_extra_fields = False
279 filter_extra_fields = False
279 chained_validators = [v.ValidPerms(type_='repo')]
280 chained_validators = [v.ValidPerms(type_='repo')]
280 return _RepoPermsForm
281 return _RepoPermsForm
281
282
282
283
283 def RepoGroupPermsForm(valid_recursive_choices):
284 def RepoGroupPermsForm(valid_recursive_choices):
284 class _RepoGroupPermsForm(formencode.Schema):
285 class _RepoGroupPermsForm(formencode.Schema):
285 allow_extra_fields = True
286 allow_extra_fields = True
286 filter_extra_fields = False
287 filter_extra_fields = False
287 recursive = v.OneOf(valid_recursive_choices)
288 recursive = v.OneOf(valid_recursive_choices)
288 chained_validators = [v.ValidPerms(type_='repo_group')]
289 chained_validators = [v.ValidPerms(type_='repo_group')]
289 return _RepoGroupPermsForm
290 return _RepoGroupPermsForm
290
291
291
292
292 def UserGroupPermsForm():
293 def UserGroupPermsForm():
293 class _UserPermsForm(formencode.Schema):
294 class _UserPermsForm(formencode.Schema):
294 allow_extra_fields = True
295 allow_extra_fields = True
295 filter_extra_fields = False
296 filter_extra_fields = False
296 chained_validators = [v.ValidPerms(type_='user_group')]
297 chained_validators = [v.ValidPerms(type_='user_group')]
297 return _UserPermsForm
298 return _UserPermsForm
298
299
299
300
300 def RepoFieldForm():
301 def RepoFieldForm():
301 class _RepoFieldForm(formencode.Schema):
302 class _RepoFieldForm(formencode.Schema):
302 filter_extra_fields = True
303 filter_extra_fields = True
303 allow_extra_fields = True
304 allow_extra_fields = True
304
305
305 new_field_key = All(v.FieldKey(),
306 new_field_key = All(v.FieldKey(),
306 v.UnicodeString(strip=True, min=3, not_empty=True))
307 v.UnicodeString(strip=True, min=3, not_empty=True))
307 new_field_value = v.UnicodeString(not_empty=False, if_missing=u'')
308 new_field_value = v.UnicodeString(not_empty=False, if_missing=u'')
308 new_field_type = v.OneOf(['str', 'unicode', 'list', 'tuple'],
309 new_field_type = v.OneOf(['str', 'unicode', 'list', 'tuple'],
309 if_missing='str')
310 if_missing='str')
310 new_field_label = v.UnicodeString(not_empty=False)
311 new_field_label = v.UnicodeString(not_empty=False)
311 new_field_desc = v.UnicodeString(not_empty=False)
312 new_field_desc = v.UnicodeString(not_empty=False)
312
313
313 return _RepoFieldForm
314 return _RepoFieldForm
314
315
315
316
316 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
317 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
317 repo_groups=[], landing_revs=[]):
318 repo_groups=[], landing_revs=[]):
318 class _RepoForkForm(formencode.Schema):
319 class _RepoForkForm(formencode.Schema):
319 allow_extra_fields = True
320 allow_extra_fields = True
320 filter_extra_fields = False
321 filter_extra_fields = False
321 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),
322 v.SlugifyName())
323 v.SlugifyName())
323 repo_group = All(v.CanWriteGroup(),
324 repo_group = All(v.CanWriteGroup(),
324 v.OneOf(repo_groups, hideList=True))
325 v.OneOf(repo_groups, hideList=True))
325 repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
326 repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
326 description = v.UnicodeString(strip=True, min=1, not_empty=True)
327 description = v.UnicodeString(strip=True, min=1, not_empty=True)
327 private = v.StringBoolean(if_missing=False)
328 private = v.StringBoolean(if_missing=False)
328 copy_permissions = v.StringBoolean(if_missing=False)
329 copy_permissions = v.StringBoolean(if_missing=False)
329 fork_parent_id = v.UnicodeString()
330 fork_parent_id = v.UnicodeString()
330 chained_validators = [v.ValidForkName(edit, old_data)]
331 chained_validators = [v.ValidForkName(edit, old_data)]
331 landing_rev = v.OneOf(landing_revs, hideList=True)
332 landing_rev = v.OneOf(landing_revs, hideList=True)
332
333
333 return _RepoForkForm
334 return _RepoForkForm
334
335
335
336
336 def ApplicationSettingsForm():
337 def ApplicationSettingsForm():
337 class _ApplicationSettingsForm(formencode.Schema):
338 class _ApplicationSettingsForm(formencode.Schema):
338 allow_extra_fields = True
339 allow_extra_fields = True
339 filter_extra_fields = False
340 filter_extra_fields = False
340 rhodecode_title = v.UnicodeString(strip=True, max=40, not_empty=False)
341 rhodecode_title = v.UnicodeString(strip=True, max=40, not_empty=False)
341 rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True)
342 rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True)
342 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)
343 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)
344 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)
345 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)
346 rhodecode_create_personal_repo_group = v.StringBoolean(if_missing=False)
347 rhodecode_create_personal_repo_group = v.StringBoolean(if_missing=False)
347 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)
348
349
349 return _ApplicationSettingsForm
350 return _ApplicationSettingsForm
350
351
351
352
352 def ApplicationVisualisationForm():
353 def ApplicationVisualisationForm():
353 class _ApplicationVisualisationForm(formencode.Schema):
354 class _ApplicationVisualisationForm(formencode.Schema):
354 allow_extra_fields = True
355 allow_extra_fields = True
355 filter_extra_fields = False
356 filter_extra_fields = False
356 rhodecode_show_public_icon = v.StringBoolean(if_missing=False)
357 rhodecode_show_public_icon = v.StringBoolean(if_missing=False)
357 rhodecode_show_private_icon = v.StringBoolean(if_missing=False)
358 rhodecode_show_private_icon = v.StringBoolean(if_missing=False)
358 rhodecode_stylify_metatags = v.StringBoolean(if_missing=False)
359 rhodecode_stylify_metatags = v.StringBoolean(if_missing=False)
359
360
360 rhodecode_repository_fields = v.StringBoolean(if_missing=False)
361 rhodecode_repository_fields = v.StringBoolean(if_missing=False)
361 rhodecode_lightweight_journal = v.StringBoolean(if_missing=False)
362 rhodecode_lightweight_journal = v.StringBoolean(if_missing=False)
362 rhodecode_dashboard_items = v.Int(min=5, not_empty=True)
363 rhodecode_dashboard_items = v.Int(min=5, not_empty=True)
363 rhodecode_admin_grid_items = v.Int(min=5, not_empty=True)
364 rhodecode_admin_grid_items = v.Int(min=5, not_empty=True)
364 rhodecode_show_version = v.StringBoolean(if_missing=False)
365 rhodecode_show_version = v.StringBoolean(if_missing=False)
365 rhodecode_use_gravatar = v.StringBoolean(if_missing=False)
366 rhodecode_use_gravatar = v.StringBoolean(if_missing=False)
366 rhodecode_markup_renderer = v.OneOf(['markdown', 'rst'])
367 rhodecode_markup_renderer = v.OneOf(['markdown', 'rst'])
367 rhodecode_gravatar_url = v.UnicodeString(min=3)
368 rhodecode_gravatar_url = v.UnicodeString(min=3)
368 rhodecode_clone_uri_tmpl = v.UnicodeString(min=3)
369 rhodecode_clone_uri_tmpl = v.UnicodeString(min=3)
369 rhodecode_support_url = v.UnicodeString()
370 rhodecode_support_url = v.UnicodeString()
370 rhodecode_show_revision_number = v.StringBoolean(if_missing=False)
371 rhodecode_show_revision_number = v.StringBoolean(if_missing=False)
371 rhodecode_show_sha_length = v.Int(min=4, not_empty=True)
372 rhodecode_show_sha_length = v.Int(min=4, not_empty=True)
372
373
373 return _ApplicationVisualisationForm
374 return _ApplicationVisualisationForm
374
375
375
376
376 class _BaseVcsSettingsForm(formencode.Schema):
377 class _BaseVcsSettingsForm(formencode.Schema):
377 allow_extra_fields = True
378 allow_extra_fields = True
378 filter_extra_fields = False
379 filter_extra_fields = False
379 hooks_changegroup_repo_size = v.StringBoolean(if_missing=False)
380 hooks_changegroup_repo_size = v.StringBoolean(if_missing=False)
380 hooks_changegroup_push_logger = v.StringBoolean(if_missing=False)
381 hooks_changegroup_push_logger = v.StringBoolean(if_missing=False)
381 hooks_outgoing_pull_logger = v.StringBoolean(if_missing=False)
382 hooks_outgoing_pull_logger = v.StringBoolean(if_missing=False)
382
383
383 # PR/Code-review
384 # PR/Code-review
384 rhodecode_pr_merge_enabled = v.StringBoolean(if_missing=False)
385 rhodecode_pr_merge_enabled = v.StringBoolean(if_missing=False)
385 rhodecode_use_outdated_comments = v.StringBoolean(if_missing=False)
386 rhodecode_use_outdated_comments = v.StringBoolean(if_missing=False)
386
387
387 # hg
388 # hg
388 extensions_largefiles = v.StringBoolean(if_missing=False)
389 extensions_largefiles = v.StringBoolean(if_missing=False)
389 extensions_evolve = v.StringBoolean(if_missing=False)
390 extensions_evolve = v.StringBoolean(if_missing=False)
390 phases_publish = v.StringBoolean(if_missing=False)
391 phases_publish = v.StringBoolean(if_missing=False)
391
392
392 rhodecode_hg_use_rebase_for_merging = v.StringBoolean(if_missing=False)
393 rhodecode_hg_use_rebase_for_merging = v.StringBoolean(if_missing=False)
393 rhodecode_hg_close_branch_before_merging = v.StringBoolean(if_missing=False)
394 rhodecode_hg_close_branch_before_merging = v.StringBoolean(if_missing=False)
394
395
395 # git
396 # git
396 vcs_git_lfs_enabled = v.StringBoolean(if_missing=False)
397 vcs_git_lfs_enabled = v.StringBoolean(if_missing=False)
397 rhodecode_git_use_rebase_for_merging = v.StringBoolean(if_missing=False)
398 rhodecode_git_use_rebase_for_merging = v.StringBoolean(if_missing=False)
398 rhodecode_git_close_branch_before_merging = v.StringBoolean(if_missing=False)
399 rhodecode_git_close_branch_before_merging = v.StringBoolean(if_missing=False)
399
400
400 # svn
401 # svn
401 vcs_svn_proxy_http_requests_enabled = v.StringBoolean(if_missing=False)
402 vcs_svn_proxy_http_requests_enabled = v.StringBoolean(if_missing=False)
402 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)
403
404
404
405
405 def ApplicationUiSettingsForm():
406 def ApplicationUiSettingsForm():
406 class _ApplicationUiSettingsForm(_BaseVcsSettingsForm):
407 class _ApplicationUiSettingsForm(_BaseVcsSettingsForm):
407 web_push_ssl = v.StringBoolean(if_missing=False)
408 web_push_ssl = v.StringBoolean(if_missing=False)
408 paths_root_path = All(
409 paths_root_path = All(
409 v.ValidPath(),
410 v.ValidPath(),
410 v.UnicodeString(strip=True, min=1, not_empty=True)
411 v.UnicodeString(strip=True, min=1, not_empty=True)
411 )
412 )
412 largefiles_usercache = All(
413 largefiles_usercache = All(
413 v.ValidPath(),
414 v.ValidPath(),
414 v.UnicodeString(strip=True, min=2, not_empty=True))
415 v.UnicodeString(strip=True, min=2, not_empty=True))
415 vcs_git_lfs_store_location = All(
416 vcs_git_lfs_store_location = All(
416 v.ValidPath(),
417 v.ValidPath(),
417 v.UnicodeString(strip=True, min=2, not_empty=True))
418 v.UnicodeString(strip=True, min=2, not_empty=True))
418 extensions_hgsubversion = v.StringBoolean(if_missing=False)
419 extensions_hgsubversion = v.StringBoolean(if_missing=False)
419 extensions_hggit = v.StringBoolean(if_missing=False)
420 extensions_hggit = v.StringBoolean(if_missing=False)
420 new_svn_branch = v.ValidSvnPattern(section='vcs_svn_branch')
421 new_svn_branch = v.ValidSvnPattern(section='vcs_svn_branch')
421 new_svn_tag = v.ValidSvnPattern(section='vcs_svn_tag')
422 new_svn_tag = v.ValidSvnPattern(section='vcs_svn_tag')
422
423
423 return _ApplicationUiSettingsForm
424 return _ApplicationUiSettingsForm
424
425
425
426
426 def RepoVcsSettingsForm(repo_name):
427 def RepoVcsSettingsForm(repo_name):
427 class _RepoVcsSettingsForm(_BaseVcsSettingsForm):
428 class _RepoVcsSettingsForm(_BaseVcsSettingsForm):
428 inherit_global_settings = v.StringBoolean(if_missing=False)
429 inherit_global_settings = v.StringBoolean(if_missing=False)
429 new_svn_branch = v.ValidSvnPattern(
430 new_svn_branch = v.ValidSvnPattern(
430 section='vcs_svn_branch', repo_name=repo_name)
431 section='vcs_svn_branch', repo_name=repo_name)
431 new_svn_tag = v.ValidSvnPattern(
432 new_svn_tag = v.ValidSvnPattern(
432 section='vcs_svn_tag', repo_name=repo_name)
433 section='vcs_svn_tag', repo_name=repo_name)
433
434
434 return _RepoVcsSettingsForm
435 return _RepoVcsSettingsForm
435
436
436
437
437 def LabsSettingsForm():
438 def LabsSettingsForm():
438 class _LabSettingsForm(formencode.Schema):
439 class _LabSettingsForm(formencode.Schema):
439 allow_extra_fields = True
440 allow_extra_fields = True
440 filter_extra_fields = False
441 filter_extra_fields = False
441
442
442 return _LabSettingsForm
443 return _LabSettingsForm
443
444
444
445
445 def ApplicationPermissionsForm(
446 def ApplicationPermissionsForm(
446 register_choices, password_reset_choices, extern_activate_choices):
447 register_choices, password_reset_choices, extern_activate_choices):
447 class _DefaultPermissionsForm(formencode.Schema):
448 class _DefaultPermissionsForm(formencode.Schema):
448 allow_extra_fields = True
449 allow_extra_fields = True
449 filter_extra_fields = True
450 filter_extra_fields = True
450
451
451 anonymous = v.StringBoolean(if_missing=False)
452 anonymous = v.StringBoolean(if_missing=False)
452 default_register = v.OneOf(register_choices)
453 default_register = v.OneOf(register_choices)
453 default_register_message = v.UnicodeString()
454 default_register_message = v.UnicodeString()
454 default_password_reset = v.OneOf(password_reset_choices)
455 default_password_reset = v.OneOf(password_reset_choices)
455 default_extern_activate = v.OneOf(extern_activate_choices)
456 default_extern_activate = v.OneOf(extern_activate_choices)
456
457
457 return _DefaultPermissionsForm
458 return _DefaultPermissionsForm
458
459
459
460
460 def ObjectPermissionsForm(repo_perms_choices, group_perms_choices,
461 def ObjectPermissionsForm(repo_perms_choices, group_perms_choices,
461 user_group_perms_choices):
462 user_group_perms_choices):
462 class _ObjectPermissionsForm(formencode.Schema):
463 class _ObjectPermissionsForm(formencode.Schema):
463 allow_extra_fields = True
464 allow_extra_fields = True
464 filter_extra_fields = True
465 filter_extra_fields = True
465 overwrite_default_repo = v.StringBoolean(if_missing=False)
466 overwrite_default_repo = v.StringBoolean(if_missing=False)
466 overwrite_default_group = v.StringBoolean(if_missing=False)
467 overwrite_default_group = v.StringBoolean(if_missing=False)
467 overwrite_default_user_group = v.StringBoolean(if_missing=False)
468 overwrite_default_user_group = v.StringBoolean(if_missing=False)
468 default_repo_perm = v.OneOf(repo_perms_choices)
469 default_repo_perm = v.OneOf(repo_perms_choices)
469 default_group_perm = v.OneOf(group_perms_choices)
470 default_group_perm = v.OneOf(group_perms_choices)
470 default_user_group_perm = v.OneOf(user_group_perms_choices)
471 default_user_group_perm = v.OneOf(user_group_perms_choices)
471
472
472 return _ObjectPermissionsForm
473 return _ObjectPermissionsForm
473
474
474
475
475 def UserPermissionsForm(create_choices, create_on_write_choices,
476 def UserPermissionsForm(create_choices, create_on_write_choices,
476 repo_group_create_choices, user_group_create_choices,
477 repo_group_create_choices, user_group_create_choices,
477 fork_choices, inherit_default_permissions_choices):
478 fork_choices, inherit_default_permissions_choices):
478 class _DefaultPermissionsForm(formencode.Schema):
479 class _DefaultPermissionsForm(formencode.Schema):
479 allow_extra_fields = True
480 allow_extra_fields = True
480 filter_extra_fields = True
481 filter_extra_fields = True
481
482
482 anonymous = v.StringBoolean(if_missing=False)
483 anonymous = v.StringBoolean(if_missing=False)
483
484
484 default_repo_create = v.OneOf(create_choices)
485 default_repo_create = v.OneOf(create_choices)
485 default_repo_create_on_write = v.OneOf(create_on_write_choices)
486 default_repo_create_on_write = v.OneOf(create_on_write_choices)
486 default_user_group_create = v.OneOf(user_group_create_choices)
487 default_user_group_create = v.OneOf(user_group_create_choices)
487 default_repo_group_create = v.OneOf(repo_group_create_choices)
488 default_repo_group_create = v.OneOf(repo_group_create_choices)
488 default_fork_create = v.OneOf(fork_choices)
489 default_fork_create = v.OneOf(fork_choices)
489 default_inherit_default_permissions = v.OneOf(inherit_default_permissions_choices)
490 default_inherit_default_permissions = v.OneOf(inherit_default_permissions_choices)
490
491
491 return _DefaultPermissionsForm
492 return _DefaultPermissionsForm
492
493
493
494
494 def UserIndividualPermissionsForm():
495 def UserIndividualPermissionsForm():
495 class _DefaultPermissionsForm(formencode.Schema):
496 class _DefaultPermissionsForm(formencode.Schema):
496 allow_extra_fields = True
497 allow_extra_fields = True
497 filter_extra_fields = True
498 filter_extra_fields = True
498
499
499 inherit_default_permissions = v.StringBoolean(if_missing=False)
500 inherit_default_permissions = v.StringBoolean(if_missing=False)
500
501
501 return _DefaultPermissionsForm
502 return _DefaultPermissionsForm
502
503
503
504
504 def DefaultsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
505 def DefaultsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
505 class _DefaultsForm(formencode.Schema):
506 class _DefaultsForm(formencode.Schema):
506 allow_extra_fields = True
507 allow_extra_fields = True
507 filter_extra_fields = True
508 filter_extra_fields = True
508 default_repo_type = v.OneOf(supported_backends)
509 default_repo_type = v.OneOf(supported_backends)
509 default_repo_private = v.StringBoolean(if_missing=False)
510 default_repo_private = v.StringBoolean(if_missing=False)
510 default_repo_enable_statistics = v.StringBoolean(if_missing=False)
511 default_repo_enable_statistics = v.StringBoolean(if_missing=False)
511 default_repo_enable_downloads = v.StringBoolean(if_missing=False)
512 default_repo_enable_downloads = v.StringBoolean(if_missing=False)
512 default_repo_enable_locking = v.StringBoolean(if_missing=False)
513 default_repo_enable_locking = v.StringBoolean(if_missing=False)
513
514
514 return _DefaultsForm
515 return _DefaultsForm
515
516
516
517
517 def AuthSettingsForm():
518 def AuthSettingsForm():
518 class _AuthSettingsForm(formencode.Schema):
519 class _AuthSettingsForm(formencode.Schema):
519 allow_extra_fields = True
520 allow_extra_fields = True
520 filter_extra_fields = True
521 filter_extra_fields = True
521 auth_plugins = All(v.ValidAuthPlugins(),
522 auth_plugins = All(v.ValidAuthPlugins(),
522 v.UniqueListFromString()(not_empty=True))
523 v.UniqueListFromString()(not_empty=True))
523
524
524 return _AuthSettingsForm
525 return _AuthSettingsForm
525
526
526
527
527 def UserExtraEmailForm():
528 def UserExtraEmailForm():
528 class _UserExtraEmailForm(formencode.Schema):
529 class _UserExtraEmailForm(formencode.Schema):
529 email = All(v.UniqSystemEmail(), v.Email(not_empty=True))
530 email = All(v.UniqSystemEmail(), v.Email(not_empty=True))
530 return _UserExtraEmailForm
531 return _UserExtraEmailForm
531
532
532
533
533 def UserExtraIpForm():
534 def UserExtraIpForm():
534 class _UserExtraIpForm(formencode.Schema):
535 class _UserExtraIpForm(formencode.Schema):
535 ip = v.ValidIp()(not_empty=True)
536 ip = v.ValidIp()(not_empty=True)
536 return _UserExtraIpForm
537 return _UserExtraIpForm
537
538
538
539
539
540
540 def PullRequestForm(repo_id):
541 def PullRequestForm(repo_id):
541 class ReviewerForm(formencode.Schema):
542 class ReviewerForm(formencode.Schema):
542 user_id = v.Int(not_empty=True)
543 user_id = v.Int(not_empty=True)
543 reasons = All()
544 reasons = All()
544 mandatory = v.StringBoolean()
545 mandatory = v.StringBoolean()
545
546
546 class _PullRequestForm(formencode.Schema):
547 class _PullRequestForm(formencode.Schema):
547 allow_extra_fields = True
548 allow_extra_fields = True
548 filter_extra_fields = True
549 filter_extra_fields = True
549
550
550 common_ancestor = v.UnicodeString(strip=True, required=True)
551 common_ancestor = v.UnicodeString(strip=True, required=True)
551 source_repo = v.UnicodeString(strip=True, required=True)
552 source_repo = v.UnicodeString(strip=True, required=True)
552 source_ref = v.UnicodeString(strip=True, required=True)
553 source_ref = v.UnicodeString(strip=True, required=True)
553 target_repo = v.UnicodeString(strip=True, required=True)
554 target_repo = v.UnicodeString(strip=True, required=True)
554 target_ref = v.UnicodeString(strip=True, required=True)
555 target_ref = v.UnicodeString(strip=True, required=True)
555 revisions = All(#v.NotReviewedRevisions(repo_id)(),
556 revisions = All(#v.NotReviewedRevisions(repo_id)(),
556 v.UniqueList()(not_empty=True))
557 v.UniqueList()(not_empty=True))
557 review_members = formencode.ForEach(ReviewerForm())
558 review_members = formencode.ForEach(ReviewerForm())
558 pullrequest_title = v.UnicodeString(strip=True, required=True)
559 pullrequest_title = v.UnicodeString(strip=True, required=True)
559 pullrequest_desc = v.UnicodeString(strip=True, required=False)
560 pullrequest_desc = v.UnicodeString(strip=True, required=False)
560
561
561 return _PullRequestForm
562 return _PullRequestForm
562
563
563
564
564 def IssueTrackerPatternsForm():
565 def IssueTrackerPatternsForm():
565 class _IssueTrackerPatternsForm(formencode.Schema):
566 class _IssueTrackerPatternsForm(formencode.Schema):
566 allow_extra_fields = True
567 allow_extra_fields = True
567 filter_extra_fields = False
568 filter_extra_fields = False
568 chained_validators = [v.ValidPattern()]
569 chained_validators = [v.ValidPattern()]
569 return _IssueTrackerPatternsForm
570 return _IssueTrackerPatternsForm
General Comments 0
You need to be logged in to leave comments. Login now