Mercurial > kallithea
annotate rhodecode/model/validators.py @ 2524:9d4b80743a2a beta
New repo model create function
- fixed some sessions calls
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 01 Jul 2012 15:47:54 +0200 |
parents | 9225597688f4 |
children | f4b20558ae16 |
rev | line source |
---|---|
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 """ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 Set of generic validators |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 """ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 import os |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 import re |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 import formencode |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 import logging |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 from pylons.i18n.translation import _ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 from webhelpers.pylonslib.secure_form import authentication_token |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 from formencode.validators import ( |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
13 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
14 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 from rhodecode.lib.utils import repo_name_slug |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 from rhodecode.model.db import RepoGroup, Repository, UsersGroup, User |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 from rhodecode.lib.exceptions import LdapImportError |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 from rhodecode.config.routing import ADMIN_PREFIX |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # silence warnings and pylint |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 log = logging.getLogger(__name__) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 class StateObj(object): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 """ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 this is needed to translate the messages using _() in validators |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 """ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 _ = staticmethod(_) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 def M(self, key, state=None, **kwargs): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 """ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 returns string from self.message based on given key, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 passed kw params are used to substitute %(named)s params inside |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 translated strings |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 :param msg: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 :param state: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 """ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 if state is None: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 state = StateObj() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 else: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 state._ = staticmethod(_) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 #inject validator into state object |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 return self.message(key, state, **kwargs) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 def ValidUsername(edit=False, old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 'username_exists': _(u'Username "%(username)s" already exists'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 'system_invalid_username': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 _(u'Username "%(username)s" is forbidden'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 'invalid_username': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 _(u'Username may only contain alphanumeric characters ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 'underscores, periods or dashes and must begin with ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 'alphanumeric character') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 if value in ['default', 'new_user']: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 msg = M(self, 'system_invalid_username', state, username=value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 raise formencode.Invalid(msg, value, state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 #check if user is unique |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 old_un = None |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 if edit: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 old_un = User.get(old_data.get('user_id')).username |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 if old_un != value or not edit: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 if User.get_by_username(value, case_insensitive=True): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 msg = M(self, 'username_exists', state, username=value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 raise formencode.Invalid(msg, value, state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+$', value) is None: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 msg = M(self, 'invalid_username', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 raise formencode.Invalid(msg, value, state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 def ValidRepoUser(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 'invalid_username': _(u'Username %(username)s is not valid') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 try: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 User.query().filter(User.active == True)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 .filter(User.username == value).one() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 except Exception: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 msg = M(self, 'invalid_username', state, username=value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 error_dict=dict(username=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 def ValidUsersGroup(edit=False, old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
102 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 'invalid_group': _(u'Invalid users group name'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 'group_exist': _(u'Users group "%(usersgroup)s" already exists'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 'invalid_usersgroup_name': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 _(u'users group name may only contain alphanumeric ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 'characters underscores, periods or dashes and must begin ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
108 'with alphanumeric character') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
111 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
112 if value in ['default']: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 msg = M(self, 'invalid_group', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 error_dict=dict(users_group_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 #check if group is unique |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 old_ugname = None |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 if edit: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 old_id = old_data.get('users_group_id') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 old_ugname = UsersGroup.get(old_id).users_group_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 if old_ugname != value or not edit: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 is_existing_group = UsersGroup.get_by_group_name(value, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 case_insensitive=True) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 if is_existing_group: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 msg = M(self, 'group_exist', state, usersgroup=value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 error_dict=dict(users_group_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
131 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
132 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+$', value) is None: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 msg = M(self, 'invalid_usersgroup_name', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 error_dict=dict(users_group_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
140 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 def ValidReposGroup(edit=False, old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
143 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 'group_parent_id': _(u'Cannot assign this group as parent'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 'group_exists': _(u'Group "%(group_name)s" already exists'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 'repo_exists': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
147 _(u'Repository with name "%(group_name)s" already exists') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
149 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
150 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 # TODO WRITE VALIDATIONS |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
152 group_name = value.get('group_name') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
153 group_parent_id = value.get('group_parent_id') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
154 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
155 # slugify repo group just in case :) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
156 slug = repo_name_slug(group_name) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
157 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
158 # check for parent of self |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
159 parent_of_self = lambda: ( |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
160 old_data['group_id'] == int(group_parent_id) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
161 if group_parent_id else False |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
162 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 if edit and parent_of_self(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 msg = M(self, 'group_parent_id', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
166 error_dict=dict(group_parent_id=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
167 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
168 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
169 old_gname = None |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
170 if edit: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
171 old_gname = RepoGroup.get(old_data.get('group_id')).group_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
172 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
173 if old_gname != group_name or not edit: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
174 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
175 # check group |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
176 gr = RepoGroup.query()\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
177 .filter(RepoGroup.group_name == slug)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
178 .filter(RepoGroup.group_parent_id == group_parent_id)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
179 .scalar() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
181 if gr: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
182 msg = M(self, 'group_exists', state, group_name=slug) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
183 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
184 error_dict=dict(group_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
185 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
186 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
187 # check for same repo |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
188 repo = Repository.query()\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
189 .filter(Repository.repo_name == slug)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
190 .scalar() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
191 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
192 if repo: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
193 msg = M(self, 'repo_exists', state, group_name=slug) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
194 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
195 error_dict=dict(group_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
196 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
197 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
199 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
200 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
201 def ValidPassword(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
202 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
203 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
204 'invalid_password': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
205 _(u'Invalid characters (non-ascii) in password') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
206 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
207 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
208 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
209 try: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
210 (value or '').decode('ascii') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
211 except UnicodeError: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
212 msg = M(self, 'invalid_password', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
213 raise formencode.Invalid(msg, value, state,) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
214 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
215 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
216 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
217 def ValidPasswordsMatch(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
218 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
219 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
220 'password_mismatch': _(u'Passwords do not match'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
221 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
222 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
223 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
224 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
225 pass_val = value.get('password') or value.get('new_password') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
226 if pass_val != value['password_confirmation']: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
227 msg = M(self, 'password_mismatch', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
228 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
229 error_dict=dict(password_confirmation=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
230 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
231 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
232 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
233 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
234 def ValidAuth(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
235 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
236 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
237 'invalid_password': _(u'invalid password'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
238 'invalid_username': _(u'invalid user name'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
239 'disabled_account': _(u'Your account is disabled') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
240 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
241 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
242 def validate_python(self, value, state): |
2479
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2466
diff
changeset
|
243 from rhodecode.lib.auth import authenticate |
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2466
diff
changeset
|
244 |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
245 password = value['password'] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
246 username = value['username'] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
247 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
248 if not authenticate(username, password): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
249 user = User.get_by_username(username) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
250 if user and user.active is False: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
251 log.warning('user %s is disabled' % username) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
252 msg = M(self, 'disabled_account', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
253 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
254 error_dict=dict(username=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
255 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
256 else: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
257 log.warning('user %s failed to authenticate' % username) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
258 msg = M(self, 'invalid_username', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
259 msg2 = M(self, 'invalid_password', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
260 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
261 error_dict=dict(username=msg, password=msg2) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
262 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
263 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
264 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
265 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
266 def ValidAuthToken(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
267 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
268 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
269 'invalid_token': _(u'Token mismatch') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
270 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
271 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
272 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
273 if value != authentication_token(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
274 msg = M(self, 'invalid_token', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
275 raise formencode.Invalid(msg, value, state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
276 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
277 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
278 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
279 def ValidRepoName(edit=False, old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
280 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
281 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
282 'invalid_repo_name': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
283 _(u'Repository name %(repo)s is disallowed'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
284 'repository_exists': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
285 _(u'Repository named %(repo)s already exists'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
286 'repository_in_group_exists': _(u'Repository "%(repo)s" already ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
287 'exists in group "%(group)s"'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
288 'same_group_exists': _(u'Repositories group with name "%(repo)s" ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
289 'already exists') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
290 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
291 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
292 def _to_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
293 repo_name = repo_name_slug(value.get('repo_name', '')) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
294 repo_group = value.get('repo_group') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
295 if repo_group: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
296 gr = RepoGroup.get(repo_group) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
297 group_path = gr.full_path |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
298 group_name = gr.group_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
299 # value needs to be aware of group name in order to check |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
300 # db key This is an actual just the name to store in the |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
301 # database |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
302 repo_name_full = group_path + RepoGroup.url_sep() + repo_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
303 else: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
304 group_name = group_path = '' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
305 repo_name_full = repo_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
306 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
307 value['repo_name'] = repo_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
308 value['repo_name_full'] = repo_name_full |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
309 value['group_path'] = group_path |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
310 value['group_name'] = group_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
311 return value |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
312 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
313 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
314 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
315 repo_name = value.get('repo_name') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
316 repo_name_full = value.get('repo_name_full') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
317 group_path = value.get('group_path') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
318 group_name = value.get('group_name') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
319 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
320 if repo_name in [ADMIN_PREFIX, '']: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
321 msg = M(self, 'invalid_repo_name', state, repo=repo_name) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
322 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
323 error_dict=dict(repo_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
324 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
325 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
326 rename = old_data.get('repo_name') != repo_name_full |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
327 create = not edit |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
328 if rename or create: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
329 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
330 if group_path != '': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
331 if Repository.get_by_repo_name(repo_name_full): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
332 msg = M(self, 'repository_in_group_exists', state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
333 repo=repo_name, group=group_name) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
334 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
335 error_dict=dict(repo_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
336 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
337 elif RepoGroup.get_by_group_name(repo_name_full): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
338 msg = M(self, 'same_group_exists', state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
339 repo=repo_name) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
340 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
341 error_dict=dict(repo_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
342 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
343 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
344 elif Repository.get_by_repo_name(repo_name_full): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
345 msg = M(self, 'repository_exists', state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
346 repo=repo_name) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
347 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
348 error_dict=dict(repo_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
349 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
350 return value |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
351 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
352 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
353 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
354 def ValidForkName(*args, **kwargs): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
355 return ValidRepoName(*args, **kwargs) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
356 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
357 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
358 def SlugifyName(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
359 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
360 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
361 def _to_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
362 return repo_name_slug(value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
363 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
364 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
365 pass |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
366 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
367 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
368 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
369 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
370 def ValidCloneUri(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
371 from rhodecode.lib.utils import make_ui |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
372 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
373 def url_handler(repo_type, url, proto, ui=None): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
374 if repo_type == 'hg': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
375 from mercurial.httprepo import httprepository, httpsrepository |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
376 if proto == 'https': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
377 httpsrepository(make_ui('db'), url).capabilities |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
378 elif proto == 'http': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
379 httprepository(make_ui('db'), url).capabilities |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
380 elif repo_type == 'git': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
381 #TODO: write a git url validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
382 pass |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
383 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
384 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
385 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
386 'clone_uri': _(u'invalid clone url'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
387 'invalid_clone_uri': _(u'Invalid clone url, provide a ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
388 'valid clone http\s url') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
389 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
390 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
391 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
392 repo_type = value.get('repo_type') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
393 url = value.get('clone_uri') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
394 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
395 if not url: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
396 pass |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
397 elif url.startswith('https') or url.startswith('http'): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
398 _type = 'https' if url.startswith('https') else 'http' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
399 try: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
400 url_handler(repo_type, url, _type, make_ui('db')) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
401 except Exception: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
402 log.exception('Url validation failed') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
403 msg = M(self, 'clone_uri') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
404 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
405 error_dict=dict(clone_uri=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
406 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
407 else: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
408 msg = M(self, 'invalid_clone_uri', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
409 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
410 error_dict=dict(clone_uri=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
411 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
412 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
413 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
414 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
415 def ValidForkType(old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
416 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
417 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
418 'invalid_fork_type': _(u'Fork have to be the same type as parent') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
419 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
420 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
421 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
422 if old_data['repo_type'] != value: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
423 msg = M(self, 'invalid_fork_type', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
424 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
425 error_dict=dict(repo_type=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
426 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
427 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
428 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
429 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
430 def ValidPerms(type_='repo'): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
431 if type_ == 'group': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
432 EMPTY_PERM = 'group.none' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
433 elif type_ == 'repo': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
434 EMPTY_PERM = 'repository.none' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
435 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
436 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
437 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
438 'perm_new_member_name': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
439 _(u'This username or users group name is not valid') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
440 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
441 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
442 def to_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
443 perms_update = [] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
444 perms_new = [] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
445 # build a list of permission to update and new permission to create |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
446 for k, v in value.items(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
447 # means new added member to permissions |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
448 if k.startswith('perm_new_member'): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
449 new_perm = value.get('perm_new_member', False) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
450 new_member = value.get('perm_new_member_name', False) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
451 new_type = value.get('perm_new_member_type') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
452 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
453 if new_member and new_perm: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
454 if (new_member, new_perm, new_type) not in perms_new: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
455 perms_new.append((new_member, new_perm, new_type)) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
456 elif k.startswith('u_perm_') or k.startswith('g_perm_'): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
457 member = k[7:] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
458 t = {'u': 'user', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
459 'g': 'users_group' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
460 }[k[0]] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
461 if member == 'default': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
462 if value.get('private'): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
463 # set none for default when updating to |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
464 # private repo |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
465 v = EMPTY_PERM |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
466 perms_update.append((member, v, t)) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
467 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
468 value['perms_updates'] = perms_update |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
469 value['perms_new'] = perms_new |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
470 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
471 # update permissions |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
472 for k, v, t in perms_new: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
473 try: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
474 if t is 'user': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
475 self.user_db = User.query()\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
476 .filter(User.active == True)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
477 .filter(User.username == k).one() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
478 if t is 'users_group': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
479 self.user_db = UsersGroup.query()\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
480 .filter(UsersGroup.users_group_active == True)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
481 .filter(UsersGroup.users_group_name == k).one() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
482 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
483 except Exception: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
484 log.exception('Updated permission failed') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
485 msg = M(self, 'perm_new_member_type', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
486 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
487 error_dict=dict(perm_new_member_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
488 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
489 return value |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
490 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
491 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
492 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
493 def ValidSettings(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
494 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
495 def _to_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
496 # settings form can't edit user |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
497 if 'user' in value: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
498 del value['user'] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
499 return value |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
500 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
501 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
502 pass |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
503 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
504 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
505 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
506 def ValidPath(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
507 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
508 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
509 'invalid_path': _(u'This is not a valid path') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
510 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
511 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
512 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
513 if not os.path.isdir(value): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
514 msg = M(self, 'invalid_path', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
515 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
516 error_dict=dict(paths_root_path=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
517 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
518 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
519 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
520 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
521 def UniqSystemEmail(old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
522 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
523 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
524 'email_taken': _(u'This e-mail address is already taken') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
525 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
526 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
527 def _to_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
528 return value.lower() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
529 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
530 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
531 if (old_data.get('email') or '').lower() != value: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
532 user = User.get_by_email(value, case_insensitive=True) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
533 if user: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
534 msg = M(self, 'email_taken', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
535 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
536 error_dict=dict(email=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
537 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
538 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
539 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
540 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
541 def ValidSystemEmail(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
542 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
543 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
544 'non_existing_email': _(u'e-mail "%(email)s" does not exist.') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
545 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
546 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
547 def _to_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
548 return value.lower() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
549 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
550 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
551 user = User.get_by_email(value, case_insensitive=True) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
552 if user is None: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
553 msg = M(self, 'non_existing_email', state, email=value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
554 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
555 error_dict=dict(email=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
556 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
557 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
558 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
559 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
560 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
561 def LdapLibValidator(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
562 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
563 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
564 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
565 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
566 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
567 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
568 try: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
569 import ldap |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
570 ldap # pyflakes silence ! |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
571 except ImportError: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
572 raise LdapImportError() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
573 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
574 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
575 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
576 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
577 def AttrLoginValidator(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
578 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
579 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
580 'invalid_cn': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
581 _(u'The LDAP Login attribute of the CN must be specified - ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
582 'this is the name of the attribute that is equivalent ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
583 'to "username"') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
584 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
585 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
586 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
587 if not value or not isinstance(value, (str, unicode)): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
588 msg = M(self, 'invalid_cn', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
589 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
590 error_dict=dict(ldap_attr_login=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
591 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
592 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
593 return _validator |