##// END OF EJS Templates
small fixes for detection of groups that already exists
marcink -
r1735:344ddfee beta
parent child Browse files
Show More
@@ -1,681 +1,683 b''
1 1 """ this is forms validation classes
2 2 http://formencode.org/module-formencode.validators.html
3 3 for list off all availible validators
4 4
5 5 we can create our own validators
6 6
7 7 The table below outlines the options which can be used in a schema in addition to the validators themselves
8 8 pre_validators [] These validators will be applied before the schema
9 9 chained_validators [] These validators will be applied after the schema
10 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 11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed
12 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 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 16 <name> = formencode.validators.<name of validator>
17 17 <name> must equal form name
18 18 list=[1,2,3,4,5]
19 19 for SELECT use formencode.All(OneOf(list), Int())
20 20
21 21 """
22 22 import os
23 23 import re
24 24 import logging
25 25 import traceback
26 26
27 27 import formencode
28 28 from formencode import All
29 29 from formencode.validators import UnicodeString, OneOf, Int, Number, Regex, \
30 30 Email, Bool, StringBoolean, Set
31 31
32 32 from pylons.i18n.translation import _
33 33 from webhelpers.pylonslib.secure_form import authentication_token
34 34
35 35 from rhodecode.config.routing import ADMIN_PREFIX
36 36 from rhodecode.lib.utils import repo_name_slug
37 37 from rhodecode.lib.auth import authenticate, get_crypt_password
38 38 from rhodecode.lib.exceptions import LdapImportError
39 39 from rhodecode.model.user import UserModel
40 40 from rhodecode.model.repo import RepoModel
41 41 from rhodecode.model.db import User, UsersGroup, RepoGroup
42 42 from rhodecode import BACKENDS
43 43
44 44 log = logging.getLogger(__name__)
45 45
46 46 #this is needed to translate the messages using _() in validators
47 47 class State_obj(object):
48 48 _ = staticmethod(_)
49 49
50 50 #==============================================================================
51 51 # VALIDATORS
52 52 #==============================================================================
53 53 class ValidAuthToken(formencode.validators.FancyValidator):
54 54 messages = {'invalid_token':_('Token mismatch')}
55 55
56 56 def validate_python(self, value, state):
57 57
58 58 if value != authentication_token():
59 59 raise formencode.Invalid(self.message('invalid_token', state,
60 60 search_number=value), value, state)
61 61
62 62 def ValidUsername(edit, old_data):
63 63 class _ValidUsername(formencode.validators.FancyValidator):
64 64
65 65 def validate_python(self, value, state):
66 66 if value in ['default', 'new_user']:
67 67 raise formencode.Invalid(_('Invalid username'), value, state)
68 68 #check if user is unique
69 69 old_un = None
70 70 if edit:
71 71 old_un = UserModel().get(old_data.get('user_id')).username
72 72
73 73 if old_un != value or not edit:
74 74 if User.get_by_username(value, case_insensitive=True):
75 75 raise formencode.Invalid(_('This username already '
76 76 'exists') , value, state)
77 77
78 78 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+$', value) is None:
79 79 raise formencode.Invalid(_('Username may only contain '
80 80 'alphanumeric characters '
81 81 'underscores, periods or dashes '
82 82 'and must begin with alphanumeric '
83 83 'character'), value, state)
84 84
85 85 return _ValidUsername
86 86
87 87
88 88 def ValidUsersGroup(edit, old_data):
89 89
90 90 class _ValidUsersGroup(formencode.validators.FancyValidator):
91 91
92 92 def validate_python(self, value, state):
93 93 if value in ['default']:
94 94 raise formencode.Invalid(_('Invalid group name'), value, state)
95 95 #check if group is unique
96 96 old_ugname = None
97 97 if edit:
98 98 old_ugname = UsersGroup.get(
99 99 old_data.get('users_group_id')).users_group_name
100 100
101 101 if old_ugname != value or not edit:
102 102 if UsersGroup.get_by_group_name(value, cache=False,
103 103 case_insensitive=True):
104 104 raise formencode.Invalid(_('This users group '
105 105 'already exists') , value,
106 106 state)
107 107
108 108
109 109 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+$', value) is None:
110 110 raise formencode.Invalid(_('RepoGroup name may only contain '
111 111 'alphanumeric characters '
112 112 'underscores, periods or dashes '
113 113 'and must begin with alphanumeric '
114 114 'character'), value, state)
115 115
116 116 return _ValidUsersGroup
117 117
118 118
119 119 def ValidReposGroup(edit, old_data):
120 120 class _ValidReposGroup(formencode.validators.FancyValidator):
121 121
122 122 def validate_python(self, value, state):
123 #TODO WRITE VALIDATIONS
123 # TODO WRITE VALIDATIONS
124 124 group_name = value.get('group_name')
125 group_parent_id = int(value.get('group_parent_id') or -1)
125 group_parent_id = value.get('group_parent_id')
126 126
127 127 # slugify repo group just in case :)
128 128 slug = repo_name_slug(group_name)
129 129
130 130 # check for parent of self
131 if edit and old_data['group_id'] == group_parent_id:
131 parent_of_self = lambda:(old_data['group_id'] == int(group_parent_id)
132 if group_parent_id else False)
133 if edit and parent_of_self():
132 134 e_dict = {'group_parent_id':_('Cannot assign this group '
133 135 'as parent')}
134 136 raise formencode.Invalid('', value, state,
135 137 error_dict=e_dict)
136 138
137 139 old_gname = None
138 140 if edit:
139 old_gname = RepoGroup.get(
140 old_data.get('group_id')).group_name
141 old_gname = RepoGroup.get(old_data.get('group_id')).group_name
141 142
142 143 if old_gname != group_name or not edit:
144
143 145 # check filesystem
144 146 gr = RepoGroup.query().filter(RepoGroup.group_name == slug)\
145 147 .filter(RepoGroup.group_parent_id == group_parent_id).scalar()
146 148
147 149 if gr:
148 150 e_dict = {'group_name':_('This group already exists')}
149 151 raise formencode.Invalid('', value, state,
150 152 error_dict=e_dict)
151 153
152 154 return _ValidReposGroup
153 155
154 156 class ValidPassword(formencode.validators.FancyValidator):
155 157
156 158 def to_python(self, value, state):
157 159
158 160 if value:
159 161
160 162 if value.get('password'):
161 163 try:
162 164 value['password'] = get_crypt_password(value['password'])
163 165 except UnicodeEncodeError:
164 166 e_dict = {'password':_('Invalid characters in password')}
165 167 raise formencode.Invalid('', value, state, error_dict=e_dict)
166 168
167 169 if value.get('password_confirmation'):
168 170 try:
169 171 value['password_confirmation'] = \
170 172 get_crypt_password(value['password_confirmation'])
171 173 except UnicodeEncodeError:
172 174 e_dict = {'password_confirmation':_('Invalid characters in password')}
173 175 raise formencode.Invalid('', value, state, error_dict=e_dict)
174 176
175 177 if value.get('new_password'):
176 178 try:
177 179 value['new_password'] = \
178 180 get_crypt_password(value['new_password'])
179 181 except UnicodeEncodeError:
180 182 e_dict = {'new_password':_('Invalid characters in password')}
181 183 raise formencode.Invalid('', value, state, error_dict=e_dict)
182 184
183 185 return value
184 186
185 187 class ValidPasswordsMatch(formencode.validators.FancyValidator):
186 188
187 189 def validate_python(self, value, state):
188 190
189 191 pass_val = value.get('password') or value.get('new_password')
190 192 if pass_val != value['password_confirmation']:
191 193 e_dict = {'password_confirmation':
192 194 _('Passwords do not match')}
193 195 raise formencode.Invalid('', value, state, error_dict=e_dict)
194 196
195 197 class ValidAuth(formencode.validators.FancyValidator):
196 198 messages = {
197 199 'invalid_password':_('invalid password'),
198 200 'invalid_login':_('invalid user name'),
199 201 'disabled_account':_('Your account is disabled')
200 202 }
201 203
202 204 # error mapping
203 205 e_dict = {'username':messages['invalid_login'],
204 206 'password':messages['invalid_password']}
205 207 e_dict_disable = {'username':messages['disabled_account']}
206 208
207 209 def validate_python(self, value, state):
208 210 password = value['password']
209 211 username = value['username']
210 212 user = User.get_by_username(username)
211 213
212 214 if authenticate(username, password):
213 215 return value
214 216 else:
215 217 if user and user.active is False:
216 218 log.warning('user %s is disabled', username)
217 219 raise formencode.Invalid(self.message('disabled_account',
218 220 state=State_obj),
219 221 value, state,
220 222 error_dict=self.e_dict_disable)
221 223 else:
222 224 log.warning('user %s not authenticated', username)
223 225 raise formencode.Invalid(self.message('invalid_password',
224 226 state=State_obj), value, state,
225 227 error_dict=self.e_dict)
226 228
227 229 class ValidRepoUser(formencode.validators.FancyValidator):
228 230
229 231 def to_python(self, value, state):
230 232 try:
231 233 User.query().filter(User.active == True)\
232 234 .filter(User.username == value).one()
233 235 except Exception:
234 236 raise formencode.Invalid(_('This username is not valid'),
235 237 value, state)
236 238 return value
237 239
238 240 def ValidRepoName(edit, old_data):
239 241 class _ValidRepoName(formencode.validators.FancyValidator):
240 242 def to_python(self, value, state):
241 243
242 244 repo_name = value.get('repo_name')
243 245
244 246 slug = repo_name_slug(repo_name)
245 247 if slug in [ADMIN_PREFIX, '']:
246 248 e_dict = {'repo_name': _('This repository name is disallowed')}
247 249 raise formencode.Invalid('', value, state, error_dict=e_dict)
248 250
249 251
250 252 if value.get('repo_group'):
251 253 gr = RepoGroup.get(value.get('repo_group'))
252 254 group_path = gr.full_path
253 255 # value needs to be aware of group name in order to check
254 256 # db key This is an actual just the name to store in the
255 257 # database
256 258 repo_name_full = group_path + RepoGroup.url_sep() + repo_name
257 259
258 260 else:
259 261 group_path = ''
260 262 repo_name_full = repo_name
261 263
262 264
263 265 value['repo_name_full'] = repo_name_full
264 266 rename = old_data.get('repo_name') != repo_name_full
265 267 create = not edit
266 268 if rename or create:
267 269
268 270 if group_path != '':
269 271 if RepoModel().get_by_repo_name(repo_name_full,):
270 272 e_dict = {'repo_name':_('This repository already '
271 273 'exists in a group "%s"') %
272 274 gr.group_name}
273 275 raise formencode.Invalid('', value, state,
274 276 error_dict=e_dict)
275 277 elif RepoGroup.get_by_group_name(repo_name_full):
276 278 e_dict = {'repo_name':_('There is a group with this'
277 279 ' name already "%s"') %
278 280 repo_name_full}
279 281 raise formencode.Invalid('', value, state,
280 282 error_dict=e_dict)
281 283
282 284 elif RepoModel().get_by_repo_name(repo_name_full):
283 285 e_dict = {'repo_name':_('This repository '
284 286 'already exists')}
285 287 raise formencode.Invalid('', value, state,
286 288 error_dict=e_dict)
287 289
288 290 return value
289 291
290 292 return _ValidRepoName
291 293
292 294 def ValidForkName(*args, **kwargs):
293 295 return ValidRepoName(*args, **kwargs)
294 296
295 297
296 298 def SlugifyName():
297 299 class _SlugifyName(formencode.validators.FancyValidator):
298 300
299 301 def to_python(self, value, state):
300 302 return repo_name_slug(value)
301 303
302 304 return _SlugifyName
303 305
304 306 def ValidCloneUri():
305 307 from mercurial.httprepo import httprepository, httpsrepository
306 308 from rhodecode.lib.utils import make_ui
307 309
308 310 class _ValidCloneUri(formencode.validators.FancyValidator):
309 311
310 312 def to_python(self, value, state):
311 313 if not value:
312 314 pass
313 315 elif value.startswith('https'):
314 316 try:
315 317 httpsrepository(make_ui('db'), value).capabilities
316 318 except Exception, e:
317 319 log.error(traceback.format_exc())
318 320 raise formencode.Invalid(_('invalid clone url'), value,
319 321 state)
320 322 elif value.startswith('http'):
321 323 try:
322 324 httprepository(make_ui('db'), value).capabilities
323 325 except Exception, e:
324 326 log.error(traceback.format_exc())
325 327 raise formencode.Invalid(_('invalid clone url'), value,
326 328 state)
327 329 else:
328 330 raise formencode.Invalid(_('Invalid clone url, provide a '
329 331 'valid clone http\s url'), value,
330 332 state)
331 333 return value
332 334
333 335 return _ValidCloneUri
334 336
335 337 def ValidForkType(old_data):
336 338 class _ValidForkType(formencode.validators.FancyValidator):
337 339
338 340 def to_python(self, value, state):
339 341 if old_data['repo_type'] != value:
340 342 raise formencode.Invalid(_('Fork have to be the same '
341 343 'type as original'), value, state)
342 344
343 345 return value
344 346 return _ValidForkType
345 347
346 348 class ValidPerms(formencode.validators.FancyValidator):
347 349 messages = {'perm_new_member_name':_('This username or users group name'
348 350 ' is not valid')}
349 351
350 352 def to_python(self, value, state):
351 353 perms_update = []
352 354 perms_new = []
353 355 #build a list of permission to update and new permission to create
354 356 for k, v in value.items():
355 357 #means new added member to permissions
356 358 if k.startswith('perm_new_member'):
357 359 new_perm = value.get('perm_new_member', False)
358 360 new_member = value.get('perm_new_member_name', False)
359 361 new_type = value.get('perm_new_member_type')
360 362
361 363 if new_member and new_perm:
362 364 if (new_member, new_perm, new_type) not in perms_new:
363 365 perms_new.append((new_member, new_perm, new_type))
364 366 elif k.startswith('u_perm_') or k.startswith('g_perm_'):
365 367 member = k[7:]
366 368 t = {'u':'user',
367 369 'g':'users_group'}[k[0]]
368 370 if member == 'default':
369 371 if value['private']:
370 372 #set none for default when updating to private repo
371 373 v = 'repository.none'
372 374 perms_update.append((member, v, t))
373 375
374 376 value['perms_updates'] = perms_update
375 377 value['perms_new'] = perms_new
376 378
377 379 #update permissions
378 380 for k, v, t in perms_new:
379 381 try:
380 382 if t is 'user':
381 383 self.user_db = User.query()\
382 384 .filter(User.active == True)\
383 385 .filter(User.username == k).one()
384 386 if t is 'users_group':
385 387 self.user_db = UsersGroup.query()\
386 388 .filter(UsersGroup.users_group_active == True)\
387 389 .filter(UsersGroup.users_group_name == k).one()
388 390
389 391 except Exception:
390 392 msg = self.message('perm_new_member_name',
391 393 state=State_obj)
392 394 raise formencode.Invalid(msg, value, state,
393 395 error_dict={'perm_new_member_name':msg})
394 396 return value
395 397
396 398 class ValidSettings(formencode.validators.FancyValidator):
397 399
398 400 def to_python(self, value, state):
399 401 #settings form can't edit user
400 402 if value.has_key('user'):
401 403 del['value']['user']
402 404
403 405 return value
404 406
405 407 class ValidPath(formencode.validators.FancyValidator):
406 408 def to_python(self, value, state):
407 409
408 410 if not os.path.isdir(value):
409 411 msg = _('This is not a valid path')
410 412 raise formencode.Invalid(msg, value, state,
411 413 error_dict={'paths_root_path':msg})
412 414 return value
413 415
414 416 def UniqSystemEmail(old_data):
415 417 class _UniqSystemEmail(formencode.validators.FancyValidator):
416 418 def to_python(self, value, state):
417 419 value = value.lower()
418 420 if old_data.get('email') != value:
419 421 user = User.query().filter(User.email == value).scalar()
420 422 if user:
421 423 raise formencode.Invalid(
422 424 _("This e-mail address is already taken"),
423 425 value, state)
424 426 return value
425 427
426 428 return _UniqSystemEmail
427 429
428 430 class ValidSystemEmail(formencode.validators.FancyValidator):
429 431 def to_python(self, value, state):
430 432 value = value.lower()
431 433 user = User.query().filter(User.email == value).scalar()
432 434 if user is None:
433 435 raise formencode.Invalid(_("This e-mail address doesn't exist.") ,
434 436 value, state)
435 437
436 438 return value
437 439
438 440 class LdapLibValidator(formencode.validators.FancyValidator):
439 441
440 442 def to_python(self, value, state):
441 443
442 444 try:
443 445 import ldap
444 446 except ImportError:
445 447 raise LdapImportError
446 448 return value
447 449
448 450 class AttrLoginValidator(formencode.validators.FancyValidator):
449 451
450 452 def to_python(self, value, state):
451 453
452 454 if not value or not isinstance(value, (str, unicode)):
453 455 raise formencode.Invalid(_("The LDAP Login attribute of the CN "
454 456 "must be specified - this is the name "
455 457 "of the attribute that is equivalent "
456 458 "to 'username'"),
457 459 value, state)
458 460
459 461 return value
460 462
461 463 #===============================================================================
462 464 # FORMS
463 465 #===============================================================================
464 466 class LoginForm(formencode.Schema):
465 467 allow_extra_fields = True
466 468 filter_extra_fields = True
467 469 username = UnicodeString(
468 470 strip=True,
469 471 min=1,
470 472 not_empty=True,
471 473 messages={
472 474 'empty':_('Please enter a login'),
473 475 'tooShort':_('Enter a value %(min)i characters long or more')}
474 476 )
475 477
476 478 password = UnicodeString(
477 479 strip=True,
478 480 min=3,
479 481 not_empty=True,
480 482 messages={
481 483 'empty':_('Please enter a password'),
482 484 'tooShort':_('Enter %(min)i characters or more')}
483 485 )
484 486
485 487 chained_validators = [ValidAuth]
486 488
487 489 def UserForm(edit=False, old_data={}):
488 490 class _UserForm(formencode.Schema):
489 491 allow_extra_fields = True
490 492 filter_extra_fields = True
491 493 username = All(UnicodeString(strip=True, min=1, not_empty=True),
492 494 ValidUsername(edit, old_data))
493 495 if edit:
494 496 new_password = All(UnicodeString(strip=True, min=6, not_empty=False))
495 497 password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=False))
496 498 admin = StringBoolean(if_missing=False)
497 499 else:
498 500 password = All(UnicodeString(strip=True, min=6, not_empty=True))
499 501 password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=False))
500 502
501 503 active = StringBoolean(if_missing=False)
502 504 name = UnicodeString(strip=True, min=1, not_empty=True)
503 505 lastname = UnicodeString(strip=True, min=1, not_empty=True)
504 506 email = All(Email(not_empty=True), UniqSystemEmail(old_data))
505 507
506 508 chained_validators = [ValidPasswordsMatch, ValidPassword]
507 509
508 510 return _UserForm
509 511
510 512
511 513 def UsersGroupForm(edit=False, old_data={}, available_members=[]):
512 514 class _UsersGroupForm(formencode.Schema):
513 515 allow_extra_fields = True
514 516 filter_extra_fields = True
515 517
516 518 users_group_name = All(UnicodeString(strip=True, min=1, not_empty=True),
517 519 ValidUsersGroup(edit, old_data))
518 520
519 521 users_group_active = StringBoolean(if_missing=False)
520 522
521 523 if edit:
522 524 users_group_members = OneOf(available_members, hideList=False,
523 525 testValueList=True,
524 526 if_missing=None, not_empty=False)
525 527
526 528 return _UsersGroupForm
527 529
528 530 def ReposGroupForm(edit=False, old_data={}, available_groups=[]):
529 531 class _ReposGroupForm(formencode.Schema):
530 532 allow_extra_fields = True
531 533 filter_extra_fields = True
532 534
533 535 group_name = All(UnicodeString(strip=True, min=1, not_empty=True),
534 536 SlugifyName())
535 537 group_description = UnicodeString(strip=True, min=1,
536 538 not_empty=True)
537 539 group_parent_id = OneOf(available_groups, hideList=False,
538 540 testValueList=True,
539 541 if_missing=None, not_empty=False)
540 542
541 543 chained_validators = [ValidReposGroup(edit, old_data)]
542 544
543 545 return _ReposGroupForm
544 546
545 547 def RegisterForm(edit=False, old_data={}):
546 548 class _RegisterForm(formencode.Schema):
547 549 allow_extra_fields = True
548 550 filter_extra_fields = True
549 551 username = All(ValidUsername(edit, old_data),
550 552 UnicodeString(strip=True, min=1, not_empty=True))
551 553 password = All(UnicodeString(strip=True, min=6, not_empty=True))
552 554 password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=True))
553 555 active = StringBoolean(if_missing=False)
554 556 name = UnicodeString(strip=True, min=1, not_empty=True)
555 557 lastname = UnicodeString(strip=True, min=1, not_empty=True)
556 558 email = All(Email(not_empty=True), UniqSystemEmail(old_data))
557 559
558 560 chained_validators = [ValidPasswordsMatch, ValidPassword]
559 561
560 562 return _RegisterForm
561 563
562 564 def PasswordResetForm():
563 565 class _PasswordResetForm(formencode.Schema):
564 566 allow_extra_fields = True
565 567 filter_extra_fields = True
566 568 email = All(ValidSystemEmail(), Email(not_empty=True))
567 569 return _PasswordResetForm
568 570
569 571 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
570 572 repo_groups=[]):
571 573 class _RepoForm(formencode.Schema):
572 574 allow_extra_fields = True
573 575 filter_extra_fields = False
574 576 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True),
575 577 SlugifyName())
576 578 clone_uri = All(UnicodeString(strip=True, min=1, not_empty=False),
577 579 ValidCloneUri()())
578 580 repo_group = OneOf(repo_groups, hideList=True)
579 581 repo_type = OneOf(supported_backends)
580 582 description = UnicodeString(strip=True, min=1, not_empty=True)
581 583 private = StringBoolean(if_missing=False)
582 584 enable_statistics = StringBoolean(if_missing=False)
583 585 enable_downloads = StringBoolean(if_missing=False)
584 586
585 587 if edit:
586 588 #this is repo owner
587 589 user = All(UnicodeString(not_empty=True), ValidRepoUser)
588 590
589 591 chained_validators = [ValidRepoName(edit, old_data), ValidPerms]
590 592 return _RepoForm
591 593
592 594 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
593 595 repo_groups=[]):
594 596 class _RepoForkForm(formencode.Schema):
595 597 allow_extra_fields = True
596 598 filter_extra_fields = False
597 599 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True),
598 600 SlugifyName())
599 601 repo_group = OneOf(repo_groups, hideList=True)
600 602 repo_type = All(ValidForkType(old_data), OneOf(supported_backends))
601 603 description = UnicodeString(strip=True, min=1, not_empty=True)
602 604 private = StringBoolean(if_missing=False)
603 605 copy_permissions = StringBoolean(if_missing=False)
604 606 fork_parent_id = UnicodeString()
605 607 chained_validators = [ValidForkName(edit, old_data)]
606 608
607 609 return _RepoForkForm
608 610
609 611 def RepoSettingsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
610 612 repo_groups=[]):
611 613 class _RepoForm(formencode.Schema):
612 614 allow_extra_fields = True
613 615 filter_extra_fields = False
614 616 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True),
615 617 SlugifyName())
616 618 description = UnicodeString(strip=True, min=1, not_empty=True)
617 619 repo_group = OneOf(repo_groups, hideList=True)
618 620 private = StringBoolean(if_missing=False)
619 621
620 622 chained_validators = [ValidRepoName(edit, old_data), ValidPerms,
621 623 ValidSettings]
622 624 return _RepoForm
623 625
624 626
625 627 def ApplicationSettingsForm():
626 628 class _ApplicationSettingsForm(formencode.Schema):
627 629 allow_extra_fields = True
628 630 filter_extra_fields = False
629 631 rhodecode_title = UnicodeString(strip=True, min=1, not_empty=True)
630 632 rhodecode_realm = UnicodeString(strip=True, min=1, not_empty=True)
631 633 rhodecode_ga_code = UnicodeString(strip=True, min=1, not_empty=False)
632 634
633 635 return _ApplicationSettingsForm
634 636
635 637 def ApplicationUiSettingsForm():
636 638 class _ApplicationUiSettingsForm(formencode.Schema):
637 639 allow_extra_fields = True
638 640 filter_extra_fields = False
639 641 web_push_ssl = OneOf(['true', 'false'], if_missing='false')
640 642 paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=1, not_empty=True))
641 643 hooks_changegroup_update = OneOf(['True', 'False'], if_missing=False)
642 644 hooks_changegroup_repo_size = OneOf(['True', 'False'], if_missing=False)
643 645 hooks_pretxnchangegroup_push_logger = OneOf(['True', 'False'], if_missing=False)
644 646 hooks_preoutgoing_pull_logger = OneOf(['True', 'False'], if_missing=False)
645 647
646 648 return _ApplicationUiSettingsForm
647 649
648 650 def DefaultPermissionsForm(perms_choices, register_choices, create_choices):
649 651 class _DefaultPermissionsForm(formencode.Schema):
650 652 allow_extra_fields = True
651 653 filter_extra_fields = True
652 654 overwrite_default = StringBoolean(if_missing=False)
653 655 anonymous = OneOf(['True', 'False'], if_missing=False)
654 656 default_perm = OneOf(perms_choices)
655 657 default_register = OneOf(register_choices)
656 658 default_create = OneOf(create_choices)
657 659
658 660 return _DefaultPermissionsForm
659 661
660 662
661 663 def LdapSettingsForm(tls_reqcert_choices, search_scope_choices, tls_kind_choices):
662 664 class _LdapSettingsForm(formencode.Schema):
663 665 allow_extra_fields = True
664 666 filter_extra_fields = True
665 667 pre_validators = [LdapLibValidator]
666 668 ldap_active = StringBoolean(if_missing=False)
667 669 ldap_host = UnicodeString(strip=True,)
668 670 ldap_port = Number(strip=True,)
669 671 ldap_tls_kind = OneOf(tls_kind_choices)
670 672 ldap_tls_reqcert = OneOf(tls_reqcert_choices)
671 673 ldap_dn_user = UnicodeString(strip=True,)
672 674 ldap_dn_pass = UnicodeString(strip=True,)
673 675 ldap_base_dn = UnicodeString(strip=True,)
674 676 ldap_filter = UnicodeString(strip=True,)
675 677 ldap_search_scope = OneOf(search_scope_choices)
676 678 ldap_attr_login = All(AttrLoginValidator, UnicodeString(strip=True,))
677 679 ldap_attr_firstname = UnicodeString(strip=True,)
678 680 ldap_attr_lastname = UnicodeString(strip=True,)
679 681 ldap_attr_email = UnicodeString(strip=True,)
680 682
681 683 return _LdapSettingsForm
General Comments 0
You need to be logged in to leave comments. Login now