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