##// END OF EJS Templates
Improve validation on dashboard items field
marcink -
r3949:3301fb05 beta
parent child Browse files
Show More
@@ -1,438 +1,438 b''
1 """ this is forms validation classes
1 """ this is forms validation classes
2 http://formencode.org/module-formencode.validators.html
2 http://formencode.org/module-formencode.validators.html
3 for list off all availible validators
3 for list off all availible validators
4
4
5 we can create our own validators
5 we can create our own validators
6
6
7 The table below outlines the options which can be used in a schema in addition to the validators themselves
7 The table below outlines the options which can be used in a schema in addition to the validators themselves
8 pre_validators [] These validators will be applied before the schema
8 pre_validators [] These validators will be applied before the schema
9 chained_validators [] These validators will be applied after the schema
9 chained_validators [] These validators will be applied after the schema
10 allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present
10 allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present
11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed
11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed
12 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.
12 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.
13 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
13 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
14
14
15
15
16 <name> = formencode.validators.<name of validator>
16 <name> = formencode.validators.<name of validator>
17 <name> must equal form name
17 <name> must equal form name
18 list=[1,2,3,4,5]
18 list=[1,2,3,4,5]
19 for SELECT use formencode.All(OneOf(list), Int())
19 for SELECT use formencode.All(OneOf(list), Int())
20
20
21 """
21 """
22 import logging
22 import logging
23
23
24 import formencode
24 import formencode
25 from formencode import All
25 from formencode import All
26
26
27 from pylons.i18n.translation import _
27 from pylons.i18n.translation import _
28
28
29 from rhodecode.model import validators as v
29 from rhodecode.model import validators as v
30 from rhodecode import BACKENDS
30 from rhodecode import BACKENDS
31
31
32 log = logging.getLogger(__name__)
32 log = logging.getLogger(__name__)
33
33
34
34
35 class LoginForm(formencode.Schema):
35 class LoginForm(formencode.Schema):
36 allow_extra_fields = True
36 allow_extra_fields = True
37 filter_extra_fields = True
37 filter_extra_fields = True
38 username = v.UnicodeString(
38 username = v.UnicodeString(
39 strip=True,
39 strip=True,
40 min=1,
40 min=1,
41 not_empty=True,
41 not_empty=True,
42 messages={
42 messages={
43 'empty': _(u'Please enter a login'),
43 'empty': _(u'Please enter a login'),
44 'tooShort': _(u'Enter a value %(min)i characters long or more')}
44 'tooShort': _(u'Enter a value %(min)i characters long or more')}
45 )
45 )
46
46
47 password = v.UnicodeString(
47 password = v.UnicodeString(
48 strip=False,
48 strip=False,
49 min=3,
49 min=3,
50 not_empty=True,
50 not_empty=True,
51 messages={
51 messages={
52 'empty': _(u'Please enter a password'),
52 'empty': _(u'Please enter a password'),
53 'tooShort': _(u'Enter %(min)i characters or more')}
53 'tooShort': _(u'Enter %(min)i characters or more')}
54 )
54 )
55
55
56 remember = v.StringBoolean(if_missing=False)
56 remember = v.StringBoolean(if_missing=False)
57
57
58 chained_validators = [v.ValidAuth()]
58 chained_validators = [v.ValidAuth()]
59
59
60
60
61 def UserForm(edit=False, old_data={}):
61 def UserForm(edit=False, old_data={}):
62 class _UserForm(formencode.Schema):
62 class _UserForm(formencode.Schema):
63 allow_extra_fields = True
63 allow_extra_fields = True
64 filter_extra_fields = True
64 filter_extra_fields = True
65 username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
65 username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
66 v.ValidUsername(edit, old_data))
66 v.ValidUsername(edit, old_data))
67 if edit:
67 if edit:
68 new_password = All(
68 new_password = All(
69 v.ValidPassword(),
69 v.ValidPassword(),
70 v.UnicodeString(strip=False, min=6, not_empty=False)
70 v.UnicodeString(strip=False, min=6, not_empty=False)
71 )
71 )
72 password_confirmation = All(
72 password_confirmation = All(
73 v.ValidPassword(),
73 v.ValidPassword(),
74 v.UnicodeString(strip=False, min=6, not_empty=False),
74 v.UnicodeString(strip=False, min=6, not_empty=False),
75 )
75 )
76 admin = v.StringBoolean(if_missing=False)
76 admin = v.StringBoolean(if_missing=False)
77 else:
77 else:
78 password = All(
78 password = All(
79 v.ValidPassword(),
79 v.ValidPassword(),
80 v.UnicodeString(strip=False, min=6, not_empty=True)
80 v.UnicodeString(strip=False, min=6, not_empty=True)
81 )
81 )
82 password_confirmation = All(
82 password_confirmation = All(
83 v.ValidPassword(),
83 v.ValidPassword(),
84 v.UnicodeString(strip=False, min=6, not_empty=False)
84 v.UnicodeString(strip=False, min=6, not_empty=False)
85 )
85 )
86
86
87 active = v.StringBoolean(if_missing=False)
87 active = v.StringBoolean(if_missing=False)
88 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
88 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
89 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
89 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
90 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
90 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
91
91
92 chained_validators = [v.ValidPasswordsMatch()]
92 chained_validators = [v.ValidPasswordsMatch()]
93
93
94 return _UserForm
94 return _UserForm
95
95
96
96
97 def UserGroupForm(edit=False, old_data={}, available_members=[]):
97 def UserGroupForm(edit=False, old_data={}, available_members=[]):
98 class _UserGroupForm(formencode.Schema):
98 class _UserGroupForm(formencode.Schema):
99 allow_extra_fields = True
99 allow_extra_fields = True
100 filter_extra_fields = True
100 filter_extra_fields = True
101
101
102 users_group_name = All(
102 users_group_name = All(
103 v.UnicodeString(strip=True, min=1, not_empty=True),
103 v.UnicodeString(strip=True, min=1, not_empty=True),
104 v.ValidUserGroup(edit, old_data)
104 v.ValidUserGroup(edit, old_data)
105 )
105 )
106
106
107 users_group_active = v.StringBoolean(if_missing=False)
107 users_group_active = v.StringBoolean(if_missing=False)
108
108
109 if edit:
109 if edit:
110 users_group_members = v.OneOf(
110 users_group_members = v.OneOf(
111 available_members, hideList=False, testValueList=True,
111 available_members, hideList=False, testValueList=True,
112 if_missing=None, not_empty=False
112 if_missing=None, not_empty=False
113 )
113 )
114
114
115 return _UserGroupForm
115 return _UserGroupForm
116
116
117
117
118 def ReposGroupForm(edit=False, old_data={}, available_groups=[],
118 def ReposGroupForm(edit=False, old_data={}, available_groups=[],
119 can_create_in_root=False):
119 can_create_in_root=False):
120 class _ReposGroupForm(formencode.Schema):
120 class _ReposGroupForm(formencode.Schema):
121 allow_extra_fields = True
121 allow_extra_fields = True
122 filter_extra_fields = False
122 filter_extra_fields = False
123
123
124 group_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
124 group_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
125 v.SlugifyName())
125 v.SlugifyName())
126 group_description = v.UnicodeString(strip=True, min=1,
126 group_description = v.UnicodeString(strip=True, min=1,
127 not_empty=False)
127 not_empty=False)
128 if edit:
128 if edit:
129 #FIXME: do a special check that we cannot move a group to one of
129 #FIXME: do a special check that we cannot move a group to one of
130 #it's children
130 #it's children
131 pass
131 pass
132 group_parent_id = All(v.CanCreateGroup(can_create_in_root),
132 group_parent_id = All(v.CanCreateGroup(can_create_in_root),
133 v.OneOf(available_groups, hideList=False,
133 v.OneOf(available_groups, hideList=False,
134 testValueList=True,
134 testValueList=True,
135 if_missing=None, not_empty=True))
135 if_missing=None, not_empty=True))
136 enable_locking = v.StringBoolean(if_missing=False)
136 enable_locking = v.StringBoolean(if_missing=False)
137 chained_validators = [v.ValidReposGroup(edit, old_data)]
137 chained_validators = [v.ValidReposGroup(edit, old_data)]
138
138
139 return _ReposGroupForm
139 return _ReposGroupForm
140
140
141
141
142 def RegisterForm(edit=False, old_data={}):
142 def RegisterForm(edit=False, old_data={}):
143 class _RegisterForm(formencode.Schema):
143 class _RegisterForm(formencode.Schema):
144 allow_extra_fields = True
144 allow_extra_fields = True
145 filter_extra_fields = True
145 filter_extra_fields = True
146 username = All(
146 username = All(
147 v.ValidUsername(edit, old_data),
147 v.ValidUsername(edit, old_data),
148 v.UnicodeString(strip=True, min=1, not_empty=True)
148 v.UnicodeString(strip=True, min=1, not_empty=True)
149 )
149 )
150 password = All(
150 password = All(
151 v.ValidPassword(),
151 v.ValidPassword(),
152 v.UnicodeString(strip=False, min=6, not_empty=True)
152 v.UnicodeString(strip=False, min=6, not_empty=True)
153 )
153 )
154 password_confirmation = All(
154 password_confirmation = All(
155 v.ValidPassword(),
155 v.ValidPassword(),
156 v.UnicodeString(strip=False, min=6, not_empty=True)
156 v.UnicodeString(strip=False, min=6, not_empty=True)
157 )
157 )
158 active = v.StringBoolean(if_missing=False)
158 active = v.StringBoolean(if_missing=False)
159 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
159 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
160 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
160 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
161 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
161 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
162
162
163 chained_validators = [v.ValidPasswordsMatch()]
163 chained_validators = [v.ValidPasswordsMatch()]
164
164
165 return _RegisterForm
165 return _RegisterForm
166
166
167
167
168 def PasswordResetForm():
168 def PasswordResetForm():
169 class _PasswordResetForm(formencode.Schema):
169 class _PasswordResetForm(formencode.Schema):
170 allow_extra_fields = True
170 allow_extra_fields = True
171 filter_extra_fields = True
171 filter_extra_fields = True
172 email = All(v.ValidSystemEmail(), v.Email(not_empty=True))
172 email = All(v.ValidSystemEmail(), v.Email(not_empty=True))
173 return _PasswordResetForm
173 return _PasswordResetForm
174
174
175
175
176 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
176 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
177 repo_groups=[], landing_revs=[]):
177 repo_groups=[], landing_revs=[]):
178 class _RepoForm(formencode.Schema):
178 class _RepoForm(formencode.Schema):
179 allow_extra_fields = True
179 allow_extra_fields = True
180 filter_extra_fields = False
180 filter_extra_fields = False
181 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
181 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
182 v.SlugifyName())
182 v.SlugifyName())
183 repo_group = All(v.CanWriteGroup(old_data),
183 repo_group = All(v.CanWriteGroup(old_data),
184 v.OneOf(repo_groups, hideList=True))
184 v.OneOf(repo_groups, hideList=True))
185 repo_type = v.OneOf(supported_backends, required=False,
185 repo_type = v.OneOf(supported_backends, required=False,
186 if_missing=old_data.get('repo_type'))
186 if_missing=old_data.get('repo_type'))
187 repo_description = v.UnicodeString(strip=True, min=1, not_empty=False)
187 repo_description = v.UnicodeString(strip=True, min=1, not_empty=False)
188 repo_private = v.StringBoolean(if_missing=False)
188 repo_private = v.StringBoolean(if_missing=False)
189 repo_landing_rev = v.OneOf(landing_revs, hideList=True)
189 repo_landing_rev = v.OneOf(landing_revs, hideList=True)
190 clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False))
190 clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False))
191
191
192 repo_enable_statistics = v.StringBoolean(if_missing=False)
192 repo_enable_statistics = v.StringBoolean(if_missing=False)
193 repo_enable_downloads = v.StringBoolean(if_missing=False)
193 repo_enable_downloads = v.StringBoolean(if_missing=False)
194 repo_enable_locking = v.StringBoolean(if_missing=False)
194 repo_enable_locking = v.StringBoolean(if_missing=False)
195
195
196 if edit:
196 if edit:
197 #this is repo owner
197 #this is repo owner
198 user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser())
198 user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser())
199
199
200 chained_validators = [v.ValidCloneUri(),
200 chained_validators = [v.ValidCloneUri(),
201 v.ValidRepoName(edit, old_data)]
201 v.ValidRepoName(edit, old_data)]
202 return _RepoForm
202 return _RepoForm
203
203
204
204
205 def RepoPermsForm():
205 def RepoPermsForm():
206 class _RepoPermsForm(formencode.Schema):
206 class _RepoPermsForm(formencode.Schema):
207 allow_extra_fields = True
207 allow_extra_fields = True
208 filter_extra_fields = False
208 filter_extra_fields = False
209 chained_validators = [v.ValidPerms(type_='repo')]
209 chained_validators = [v.ValidPerms(type_='repo')]
210 return _RepoPermsForm
210 return _RepoPermsForm
211
211
212
212
213 def RepoGroupPermsForm():
213 def RepoGroupPermsForm():
214 class _RepoGroupPermsForm(formencode.Schema):
214 class _RepoGroupPermsForm(formencode.Schema):
215 allow_extra_fields = True
215 allow_extra_fields = True
216 filter_extra_fields = False
216 filter_extra_fields = False
217 recursive = v.StringBoolean(if_missing=False)
217 recursive = v.StringBoolean(if_missing=False)
218 chained_validators = [v.ValidPerms(type_='repo_group')]
218 chained_validators = [v.ValidPerms(type_='repo_group')]
219 return _RepoGroupPermsForm
219 return _RepoGroupPermsForm
220
220
221
221
222 def UserGroupPermsForm():
222 def UserGroupPermsForm():
223 class _UserPermsForm(formencode.Schema):
223 class _UserPermsForm(formencode.Schema):
224 allow_extra_fields = True
224 allow_extra_fields = True
225 filter_extra_fields = False
225 filter_extra_fields = False
226 chained_validators = [v.ValidPerms(type_='user_group')]
226 chained_validators = [v.ValidPerms(type_='user_group')]
227 return _UserPermsForm
227 return _UserPermsForm
228
228
229
229
230 def RepoFieldForm():
230 def RepoFieldForm():
231 class _RepoFieldForm(formencode.Schema):
231 class _RepoFieldForm(formencode.Schema):
232 filter_extra_fields = True
232 filter_extra_fields = True
233 allow_extra_fields = True
233 allow_extra_fields = True
234
234
235 new_field_key = All(v.FieldKey(),
235 new_field_key = All(v.FieldKey(),
236 v.UnicodeString(strip=True, min=3, not_empty=True))
236 v.UnicodeString(strip=True, min=3, not_empty=True))
237 new_field_value = v.UnicodeString(not_empty=False, if_missing='')
237 new_field_value = v.UnicodeString(not_empty=False, if_missing='')
238 new_field_type = v.OneOf(['str', 'unicode', 'list', 'tuple'],
238 new_field_type = v.OneOf(['str', 'unicode', 'list', 'tuple'],
239 if_missing='str')
239 if_missing='str')
240 new_field_label = v.UnicodeString(not_empty=False)
240 new_field_label = v.UnicodeString(not_empty=False)
241 new_field_desc = v.UnicodeString(not_empty=False)
241 new_field_desc = v.UnicodeString(not_empty=False)
242
242
243 return _RepoFieldForm
243 return _RepoFieldForm
244
244
245
245
246 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
246 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
247 repo_groups=[], landing_revs=[]):
247 repo_groups=[], landing_revs=[]):
248 class _RepoForkForm(formencode.Schema):
248 class _RepoForkForm(formencode.Schema):
249 allow_extra_fields = True
249 allow_extra_fields = True
250 filter_extra_fields = False
250 filter_extra_fields = False
251 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
251 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
252 v.SlugifyName())
252 v.SlugifyName())
253 repo_group = All(v.CanWriteGroup(),
253 repo_group = All(v.CanWriteGroup(),
254 v.OneOf(repo_groups, hideList=True))
254 v.OneOf(repo_groups, hideList=True))
255 repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
255 repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
256 description = v.UnicodeString(strip=True, min=1, not_empty=True)
256 description = v.UnicodeString(strip=True, min=1, not_empty=True)
257 private = v.StringBoolean(if_missing=False)
257 private = v.StringBoolean(if_missing=False)
258 copy_permissions = v.StringBoolean(if_missing=False)
258 copy_permissions = v.StringBoolean(if_missing=False)
259 update_after_clone = v.StringBoolean(if_missing=False)
259 update_after_clone = v.StringBoolean(if_missing=False)
260 fork_parent_id = v.UnicodeString()
260 fork_parent_id = v.UnicodeString()
261 chained_validators = [v.ValidForkName(edit, old_data)]
261 chained_validators = [v.ValidForkName(edit, old_data)]
262 landing_rev = v.OneOf(landing_revs, hideList=True)
262 landing_rev = v.OneOf(landing_revs, hideList=True)
263
263
264 return _RepoForkForm
264 return _RepoForkForm
265
265
266
266
267 def ApplicationSettingsForm():
267 def ApplicationSettingsForm():
268 class _ApplicationSettingsForm(formencode.Schema):
268 class _ApplicationSettingsForm(formencode.Schema):
269 allow_extra_fields = True
269 allow_extra_fields = True
270 filter_extra_fields = False
270 filter_extra_fields = False
271 rhodecode_title = v.UnicodeString(strip=True, min=1, not_empty=True)
271 rhodecode_title = v.UnicodeString(strip=True, min=1, not_empty=True)
272 rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True)
272 rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True)
273 rhodecode_ga_code = v.UnicodeString(strip=True, min=1, not_empty=False)
273 rhodecode_ga_code = v.UnicodeString(strip=True, min=1, not_empty=False)
274
274
275 return _ApplicationSettingsForm
275 return _ApplicationSettingsForm
276
276
277
277
278 def ApplicationVisualisationForm():
278 def ApplicationVisualisationForm():
279 class _ApplicationVisualisationForm(formencode.Schema):
279 class _ApplicationVisualisationForm(formencode.Schema):
280 allow_extra_fields = True
280 allow_extra_fields = True
281 filter_extra_fields = False
281 filter_extra_fields = False
282 rhodecode_show_public_icon = v.StringBoolean(if_missing=False)
282 rhodecode_show_public_icon = v.StringBoolean(if_missing=False)
283 rhodecode_show_private_icon = v.StringBoolean(if_missing=False)
283 rhodecode_show_private_icon = v.StringBoolean(if_missing=False)
284 rhodecode_stylify_metatags = v.StringBoolean(if_missing=False)
284 rhodecode_stylify_metatags = v.StringBoolean(if_missing=False)
285
285
286 rhodecode_repository_fields = v.StringBoolean(if_missing=False)
286 rhodecode_repository_fields = v.StringBoolean(if_missing=False)
287 rhodecode_lightweight_journal = v.StringBoolean(if_missing=False)
287 rhodecode_lightweight_journal = v.StringBoolean(if_missing=False)
288 rhodecode_dashboard_items = v.UnicodeString()
288 rhodecode_dashboard_items = v.Int(min=5, not_empty=True)
289 rhodecode_show_version = v.StringBoolean(if_missing=False)
289 rhodecode_show_version = v.StringBoolean(if_missing=False)
290
290
291 return _ApplicationVisualisationForm
291 return _ApplicationVisualisationForm
292
292
293
293
294 def ApplicationUiSettingsForm():
294 def ApplicationUiSettingsForm():
295 class _ApplicationUiSettingsForm(formencode.Schema):
295 class _ApplicationUiSettingsForm(formencode.Schema):
296 allow_extra_fields = True
296 allow_extra_fields = True
297 filter_extra_fields = False
297 filter_extra_fields = False
298 web_push_ssl = v.StringBoolean(if_missing=False)
298 web_push_ssl = v.StringBoolean(if_missing=False)
299 paths_root_path = All(
299 paths_root_path = All(
300 v.ValidPath(),
300 v.ValidPath(),
301 v.UnicodeString(strip=True, min=1, not_empty=True)
301 v.UnicodeString(strip=True, min=1, not_empty=True)
302 )
302 )
303 hooks_changegroup_update = v.StringBoolean(if_missing=False)
303 hooks_changegroup_update = v.StringBoolean(if_missing=False)
304 hooks_changegroup_repo_size = v.StringBoolean(if_missing=False)
304 hooks_changegroup_repo_size = v.StringBoolean(if_missing=False)
305 hooks_changegroup_push_logger = v.StringBoolean(if_missing=False)
305 hooks_changegroup_push_logger = v.StringBoolean(if_missing=False)
306 hooks_outgoing_pull_logger = v.StringBoolean(if_missing=False)
306 hooks_outgoing_pull_logger = v.StringBoolean(if_missing=False)
307
307
308 extensions_largefiles = v.StringBoolean(if_missing=False)
308 extensions_largefiles = v.StringBoolean(if_missing=False)
309 extensions_hgsubversion = v.StringBoolean(if_missing=False)
309 extensions_hgsubversion = v.StringBoolean(if_missing=False)
310 extensions_hggit = v.StringBoolean(if_missing=False)
310 extensions_hggit = v.StringBoolean(if_missing=False)
311
311
312 return _ApplicationUiSettingsForm
312 return _ApplicationUiSettingsForm
313
313
314
314
315 def DefaultPermissionsForm(repo_perms_choices, group_perms_choices,
315 def DefaultPermissionsForm(repo_perms_choices, group_perms_choices,
316 user_group_perms_choices, create_choices,
316 user_group_perms_choices, create_choices,
317 repo_group_create_choices, user_group_create_choices,
317 repo_group_create_choices, user_group_create_choices,
318 fork_choices, register_choices, extern_activate_choices):
318 fork_choices, register_choices, extern_activate_choices):
319 class _DefaultPermissionsForm(formencode.Schema):
319 class _DefaultPermissionsForm(formencode.Schema):
320 allow_extra_fields = True
320 allow_extra_fields = True
321 filter_extra_fields = True
321 filter_extra_fields = True
322 overwrite_default_repo = v.StringBoolean(if_missing=False)
322 overwrite_default_repo = v.StringBoolean(if_missing=False)
323 overwrite_default_group = v.StringBoolean(if_missing=False)
323 overwrite_default_group = v.StringBoolean(if_missing=False)
324 overwrite_default_user_group = v.StringBoolean(if_missing=False)
324 overwrite_default_user_group = v.StringBoolean(if_missing=False)
325 anonymous = v.StringBoolean(if_missing=False)
325 anonymous = v.StringBoolean(if_missing=False)
326 default_repo_perm = v.OneOf(repo_perms_choices)
326 default_repo_perm = v.OneOf(repo_perms_choices)
327 default_group_perm = v.OneOf(group_perms_choices)
327 default_group_perm = v.OneOf(group_perms_choices)
328 default_user_group_perm = v.OneOf(user_group_perms_choices)
328 default_user_group_perm = v.OneOf(user_group_perms_choices)
329
329
330 default_repo_create = v.OneOf(create_choices)
330 default_repo_create = v.OneOf(create_choices)
331 default_user_group_create = v.OneOf(user_group_create_choices)
331 default_user_group_create = v.OneOf(user_group_create_choices)
332 #default_repo_group_create = v.OneOf(repo_group_create_choices) #not impl. yet
332 #default_repo_group_create = v.OneOf(repo_group_create_choices) #not impl. yet
333 default_fork = v.OneOf(fork_choices)
333 default_fork = v.OneOf(fork_choices)
334
334
335 default_register = v.OneOf(register_choices)
335 default_register = v.OneOf(register_choices)
336 default_extern_activate = v.OneOf(extern_activate_choices)
336 default_extern_activate = v.OneOf(extern_activate_choices)
337 return _DefaultPermissionsForm
337 return _DefaultPermissionsForm
338
338
339
339
340 def CustomDefaultPermissionsForm():
340 def CustomDefaultPermissionsForm():
341 class _CustomDefaultPermissionsForm(formencode.Schema):
341 class _CustomDefaultPermissionsForm(formencode.Schema):
342 filter_extra_fields = True
342 filter_extra_fields = True
343 allow_extra_fields = True
343 allow_extra_fields = True
344 inherit_default_permissions = v.StringBoolean(if_missing=False)
344 inherit_default_permissions = v.StringBoolean(if_missing=False)
345
345
346 create_repo_perm = v.StringBoolean(if_missing=False)
346 create_repo_perm = v.StringBoolean(if_missing=False)
347 create_user_group_perm = v.StringBoolean(if_missing=False)
347 create_user_group_perm = v.StringBoolean(if_missing=False)
348 #create_repo_group_perm Impl. later
348 #create_repo_group_perm Impl. later
349
349
350 fork_repo_perm = v.StringBoolean(if_missing=False)
350 fork_repo_perm = v.StringBoolean(if_missing=False)
351
351
352 return _CustomDefaultPermissionsForm
352 return _CustomDefaultPermissionsForm
353
353
354
354
355 def DefaultsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
355 def DefaultsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()):
356 class _DefaultsForm(formencode.Schema):
356 class _DefaultsForm(formencode.Schema):
357 allow_extra_fields = True
357 allow_extra_fields = True
358 filter_extra_fields = True
358 filter_extra_fields = True
359 default_repo_type = v.OneOf(supported_backends)
359 default_repo_type = v.OneOf(supported_backends)
360 default_repo_private = v.StringBoolean(if_missing=False)
360 default_repo_private = v.StringBoolean(if_missing=False)
361 default_repo_enable_statistics = v.StringBoolean(if_missing=False)
361 default_repo_enable_statistics = v.StringBoolean(if_missing=False)
362 default_repo_enable_downloads = v.StringBoolean(if_missing=False)
362 default_repo_enable_downloads = v.StringBoolean(if_missing=False)
363 default_repo_enable_locking = v.StringBoolean(if_missing=False)
363 default_repo_enable_locking = v.StringBoolean(if_missing=False)
364
364
365 return _DefaultsForm
365 return _DefaultsForm
366
366
367
367
368 def LdapSettingsForm(tls_reqcert_choices, search_scope_choices,
368 def LdapSettingsForm(tls_reqcert_choices, search_scope_choices,
369 tls_kind_choices):
369 tls_kind_choices):
370 class _LdapSettingsForm(formencode.Schema):
370 class _LdapSettingsForm(formencode.Schema):
371 allow_extra_fields = True
371 allow_extra_fields = True
372 filter_extra_fields = True
372 filter_extra_fields = True
373 #pre_validators = [LdapLibValidator]
373 #pre_validators = [LdapLibValidator]
374 ldap_active = v.StringBoolean(if_missing=False)
374 ldap_active = v.StringBoolean(if_missing=False)
375 ldap_host = v.UnicodeString(strip=True,)
375 ldap_host = v.UnicodeString(strip=True,)
376 ldap_port = v.Number(strip=True,)
376 ldap_port = v.Number(strip=True,)
377 ldap_tls_kind = v.OneOf(tls_kind_choices)
377 ldap_tls_kind = v.OneOf(tls_kind_choices)
378 ldap_tls_reqcert = v.OneOf(tls_reqcert_choices)
378 ldap_tls_reqcert = v.OneOf(tls_reqcert_choices)
379 ldap_dn_user = v.UnicodeString(strip=True,)
379 ldap_dn_user = v.UnicodeString(strip=True,)
380 ldap_dn_pass = v.UnicodeString(strip=True,)
380 ldap_dn_pass = v.UnicodeString(strip=True,)
381 ldap_base_dn = v.UnicodeString(strip=True,)
381 ldap_base_dn = v.UnicodeString(strip=True,)
382 ldap_filter = v.UnicodeString(strip=True,)
382 ldap_filter = v.UnicodeString(strip=True,)
383 ldap_search_scope = v.OneOf(search_scope_choices)
383 ldap_search_scope = v.OneOf(search_scope_choices)
384 ldap_attr_login = v.AttrLoginValidator()(not_empty=True)
384 ldap_attr_login = v.AttrLoginValidator()(not_empty=True)
385 ldap_attr_firstname = v.UnicodeString(strip=True,)
385 ldap_attr_firstname = v.UnicodeString(strip=True,)
386 ldap_attr_lastname = v.UnicodeString(strip=True,)
386 ldap_attr_lastname = v.UnicodeString(strip=True,)
387 ldap_attr_email = v.UnicodeString(strip=True,)
387 ldap_attr_email = v.UnicodeString(strip=True,)
388
388
389 return _LdapSettingsForm
389 return _LdapSettingsForm
390
390
391
391
392 def UserExtraEmailForm():
392 def UserExtraEmailForm():
393 class _UserExtraEmailForm(formencode.Schema):
393 class _UserExtraEmailForm(formencode.Schema):
394 email = All(v.UniqSystemEmail(), v.Email(not_empty=True))
394 email = All(v.UniqSystemEmail(), v.Email(not_empty=True))
395 return _UserExtraEmailForm
395 return _UserExtraEmailForm
396
396
397
397
398 def UserExtraIpForm():
398 def UserExtraIpForm():
399 class _UserExtraIpForm(formencode.Schema):
399 class _UserExtraIpForm(formencode.Schema):
400 ip = v.ValidIp()(not_empty=True)
400 ip = v.ValidIp()(not_empty=True)
401 return _UserExtraIpForm
401 return _UserExtraIpForm
402
402
403
403
404 def PullRequestForm(repo_id):
404 def PullRequestForm(repo_id):
405 class _PullRequestForm(formencode.Schema):
405 class _PullRequestForm(formencode.Schema):
406 allow_extra_fields = True
406 allow_extra_fields = True
407 filter_extra_fields = True
407 filter_extra_fields = True
408
408
409 user = v.UnicodeString(strip=True, required=True)
409 user = v.UnicodeString(strip=True, required=True)
410 org_repo = v.UnicodeString(strip=True, required=True)
410 org_repo = v.UnicodeString(strip=True, required=True)
411 org_ref = v.UnicodeString(strip=True, required=True)
411 org_ref = v.UnicodeString(strip=True, required=True)
412 other_repo = v.UnicodeString(strip=True, required=True)
412 other_repo = v.UnicodeString(strip=True, required=True)
413 other_ref = v.UnicodeString(strip=True, required=True)
413 other_ref = v.UnicodeString(strip=True, required=True)
414 revisions = All(#v.NotReviewedRevisions(repo_id)(),
414 revisions = All(#v.NotReviewedRevisions(repo_id)(),
415 v.UniqueList(not_empty=True))
415 v.UniqueList(not_empty=True))
416 review_members = v.UniqueList(not_empty=True)
416 review_members = v.UniqueList(not_empty=True)
417
417
418 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3)
418 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3)
419 pullrequest_desc = v.UnicodeString(strip=True, required=False)
419 pullrequest_desc = v.UnicodeString(strip=True, required=False)
420
420
421 ancestor_rev = v.UnicodeString(strip=True, required=True)
421 ancestor_rev = v.UnicodeString(strip=True, required=True)
422 merge_rev = v.UnicodeString(strip=True, required=True)
422 merge_rev = v.UnicodeString(strip=True, required=True)
423
423
424 return _PullRequestForm
424 return _PullRequestForm
425
425
426
426
427 def GistForm(lifetime_options):
427 def GistForm(lifetime_options):
428 class _GistForm(formencode.Schema):
428 class _GistForm(formencode.Schema):
429
429
430 filename = All(v.BasePath()(),
430 filename = All(v.BasePath()(),
431 v.UnicodeString(strip=True, required=False))
431 v.UnicodeString(strip=True, required=False))
432 description = v.UnicodeString(required=False, if_missing='')
432 description = v.UnicodeString(required=False, if_missing='')
433 lifetime = v.OneOf(lifetime_options)
433 lifetime = v.OneOf(lifetime_options)
434 content = v.UnicodeString(required=True, not_empty=True)
434 content = v.UnicodeString(required=True, not_empty=True)
435 public = v.UnicodeString(required=False, if_missing='')
435 public = v.UnicodeString(required=False, if_missing='')
436 private = v.UnicodeString(required=False, if_missing='')
436 private = v.UnicodeString(required=False, if_missing='')
437
437
438 return _GistForm
438 return _GistForm
General Comments 0
You need to be logged in to leave comments. Login now