Mercurial > kallithea
annotate rhodecode/model/validators.py @ 3625:260a7a01b054 beta
follow Python conventions for boolean values
True and False might be singletons and the "default" values for "boolean"
expressions, but "all" values in Python has a boolean value and should be
evaluated as such. Checking with 'is True' and 'is False' is thus confusing,
error prone and unnessarily complex.
If we anywhere rely and nullable boolean fields from the database layer and
don't want the null value to be treated as False then we should check
explicitly for null with 'is None'.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Thu, 28 Mar 2013 01:10:45 +0100 |
parents | af96fb19b53a |
children | 802c94bdfc85 |
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 |
2759
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
8 from collections import defaultdict |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 from pylons.i18n.translation import _ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 from webhelpers.pylonslib.secure_form import authentication_token |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 from formencode.validators import ( |
2711
1de45f582f9d
added more validations when opening pull request
Marcin Kuzminski <marcin@python-works.com>
parents:
2706
diff
changeset
|
13 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set, |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
14 NotEmpty, IPAddress, CIDR |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 ) |
2759
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
16 from rhodecode.lib.compat import OrderedSet |
3212
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
17 from rhodecode.lib import ipaddr |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 from rhodecode.lib.utils import repo_name_slug |
3524
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
19 from rhodecode.lib.utils2 import safe_int |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
20 from rhodecode.model.db import RepoGroup, Repository, UserGroup, User,\ |
2719
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
21 ChangesetStatus |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 from rhodecode.lib.exceptions import LdapImportError |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 from rhodecode.config.routing import ADMIN_PREFIX |
3372
157231a4fcb7
move permission check of write access to repo groups inside a form.
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
24 from rhodecode.lib.auth import HasReposGroupPermissionAny, HasPermissionAny |
2719
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
25 |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 # silence warnings and pylint |
2719
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
27 UnicodeString, OneOf, Int, Number, Regex, Email, Bool, StringBoolean, Set, \ |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
28 NotEmpty, IPAddress, CIDR |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 log = logging.getLogger(__name__) |
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 |
2719
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
33 class UniqueList(formencode.FancyValidator): |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
34 """ |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
35 Unique List ! |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
36 """ |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
37 messages = dict( |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
38 empty=_('Value cannot be an empty list'), |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
39 missing_value=_('Value cannot be an empty list'), |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
40 ) |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
41 |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
42 def _to_python(self, value, state): |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
43 if isinstance(value, list): |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
44 return value |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
45 elif isinstance(value, set): |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
46 return list(value) |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
47 elif isinstance(value, tuple): |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
48 return list(value) |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
49 elif value is None: |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
50 return [] |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
51 else: |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
52 return [value] |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
53 |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
54 def empty_value(self, value): |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
55 return [] |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
56 |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
57 |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 class StateObj(object): |
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 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
|
61 """ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 _ = staticmethod(_) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 def M(self, key, state=None, **kwargs): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 """ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 returns string from self.message based on given key, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 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
|
69 translated strings |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 :param msg: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
72 :param state: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
73 """ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 if state is None: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 state = StateObj() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 else: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 state._ = staticmethod(_) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 #inject validator into state object |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 return self.message(key, state, **kwargs) |
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 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 def ValidUsername(edit=False, old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
85 'username_exists': _(u'Username "%(username)s" already exists'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
86 'system_invalid_username': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
87 _(u'Username "%(username)s" is forbidden'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
88 'invalid_username': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
89 _(u'Username may only contain alphanumeric characters ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
90 'underscores, periods or dashes and must begin with ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
91 'alphanumeric character') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
92 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
93 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
94 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
95 if value in ['default', 'new_user']: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
96 msg = M(self, 'system_invalid_username', state, username=value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
97 raise formencode.Invalid(msg, value, state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
98 #check if user is unique |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
99 old_un = None |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
100 if edit: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
101 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
|
102 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
103 if old_un != value or not edit: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
104 if User.get_by_username(value, case_insensitive=True): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
105 msg = M(self, 'username_exists', state, username=value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
106 raise formencode.Invalid(msg, value, state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
107 |
3186
fc26083c7436
make email validation regexp match the error description - single letter is ok
Mads Kiilerich <madski@unity3d.com>
parents:
3149
diff
changeset
|
108 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]*$', value) is None: |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
109 msg = M(self, 'invalid_username', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
110 raise formencode.Invalid(msg, value, state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
111 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
112 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
113 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
114 def ValidRepoUser(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
115 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
116 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
117 'invalid_username': _(u'Username %(username)s is not valid') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
118 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
119 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
120 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
121 try: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
122 User.query().filter(User.active == True)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 .filter(User.username == value).one() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
124 except Exception: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
125 msg = M(self, 'invalid_username', state, username=value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
126 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 error_dict=dict(username=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 return _validator |
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 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
133 def ValidUserGroup(edit=False, old_data={}): |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 messages = { |
3415
b8f929bff7e3
fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents:
3372
diff
changeset
|
136 'invalid_group': _(u'Invalid user group name'), |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
137 'group_exist': _(u'User group "%(usergroup)s" already exists'), |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
138 'invalid_usergroup_name': |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
139 _(u'user group name may only contain alphanumeric ' |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
140 'characters underscores, periods or dashes and must begin ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
141 'with alphanumeric character') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
143 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 if value in ['default']: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 msg = M(self, 'invalid_group', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
147 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 error_dict=dict(users_group_name=msg) |
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 #check if group is unique |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 old_ugname = None |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
152 if edit: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
153 old_id = old_data.get('users_group_id') |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
154 old_ugname = UserGroup.get(old_id).users_group_name |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
155 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
156 if old_ugname != value or not edit: |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
157 is_existing_group = UserGroup.get_by_group_name(value, |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
158 case_insensitive=True) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
159 if is_existing_group: |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
160 msg = M(self, 'group_exist', state, usergroup=value) |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
161 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
162 error_dict=dict(users_group_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+$', value) is None: |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
166 msg = M(self, 'invalid_usergroup_name', state) |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
167 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
168 error_dict=dict(users_group_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
169 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
170 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
171 return _validator |
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 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
174 def ValidReposGroup(edit=False, old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
175 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
176 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
177 '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
|
178 'group_exists': _(u'Group "%(group_name)s" already exists'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
179 'repo_exists': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
180 _(u'Repository with name "%(group_name)s" already exists') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
181 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
182 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
183 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
184 # TODO WRITE VALIDATIONS |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
185 group_name = value.get('group_name') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
186 group_parent_id = value.get('group_parent_id') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
187 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
188 # slugify repo group just in case :) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
189 slug = repo_name_slug(group_name) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
190 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
191 # check for parent of self |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
192 parent_of_self = lambda: ( |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
193 old_data['group_id'] == int(group_parent_id) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
194 if group_parent_id else False |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
195 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
196 if edit and parent_of_self(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
197 msg = M(self, 'group_parent_id', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
198 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
199 error_dict=dict(group_parent_id=msg) |
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 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
202 old_gname = None |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
203 if edit: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
204 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
|
205 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
206 if old_gname != group_name or not edit: |
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 # check group |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
209 gr = RepoGroup.query()\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
210 .filter(RepoGroup.group_name == slug)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
211 .filter(RepoGroup.group_parent_id == group_parent_id)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
212 .scalar() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
213 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
214 if gr: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
215 msg = M(self, 'group_exists', state, group_name=slug) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
216 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
217 error_dict=dict(group_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
218 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
219 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
220 # check for same repo |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
221 repo = Repository.query()\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
222 .filter(Repository.repo_name == slug)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
223 .scalar() |
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 if repo: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
226 msg = M(self, 'repo_exists', state, group_name=slug) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
227 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
228 error_dict=dict(group_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
229 ) |
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 ValidPassword(): |
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': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
238 _(u'Invalid characters (non-ascii) in password') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
239 } |
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 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
242 try: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
243 (value or '').decode('ascii') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
244 except UnicodeError: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
245 msg = M(self, 'invalid_password', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
246 raise formencode.Invalid(msg, value, state,) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
247 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
248 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
249 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
250 def ValidPasswordsMatch(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
251 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
252 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
253 'password_mismatch': _(u'Passwords do not match'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
254 } |
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 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
257 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
258 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
|
259 if pass_val != value['password_confirmation']: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
260 msg = M(self, 'password_mismatch', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
261 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
262 error_dict=dict(password_confirmation=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
263 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
264 return _validator |
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 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
267 def ValidAuth(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
268 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
269 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
270 'invalid_password': _(u'invalid password'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
271 'invalid_username': _(u'invalid user name'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
272 'disabled_account': _(u'Your account is disabled') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
273 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
274 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
275 def validate_python(self, value, state): |
2479
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2466
diff
changeset
|
276 from rhodecode.lib.auth import authenticate |
9225597688f4
Added validation into user email map
Marcin Kuzminski <marcin@python-works.com>
parents:
2466
diff
changeset
|
277 |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
278 password = value['password'] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
279 username = value['username'] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
280 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
281 if not authenticate(username, password): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
282 user = User.get_by_username(username) |
3625
260a7a01b054
follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents:
3524
diff
changeset
|
283 if user and not user.active: |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
284 log.warning('user %s is disabled' % username) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
285 msg = M(self, 'disabled_account', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
286 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
287 error_dict=dict(username=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
288 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
289 else: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
290 log.warning('user %s failed to authenticate' % username) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
291 msg = M(self, 'invalid_username', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
292 msg2 = M(self, 'invalid_password', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
293 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
294 error_dict=dict(username=msg, password=msg2) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
295 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
296 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
297 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
298 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
299 def ValidAuthToken(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
300 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
301 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
302 'invalid_token': _(u'Token mismatch') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
303 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
304 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
305 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
306 if value != authentication_token(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
307 msg = M(self, 'invalid_token', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
308 raise formencode.Invalid(msg, value, state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
309 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
310 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
311 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
312 def ValidRepoName(edit=False, old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
313 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
314 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
315 'invalid_repo_name': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
316 _(u'Repository name %(repo)s is disallowed'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
317 'repository_exists': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
318 _(u'Repository named %(repo)s already exists'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
319 'repository_in_group_exists': _(u'Repository "%(repo)s" already ' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
320 'exists in group "%(group)s"'), |
3416
5706f6ab60cf
follow-up on texts missing from 'users groups'/'repositories group' cleanup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
321 'same_group_exists': _(u'Repository group with name "%(repo)s" ' |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
322 'already exists') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
323 } |
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 def _to_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
326 repo_name = repo_name_slug(value.get('repo_name', '')) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
327 repo_group = value.get('repo_group') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
328 if repo_group: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
329 gr = RepoGroup.get(repo_group) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
330 group_path = gr.full_path |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
331 group_name = gr.group_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
332 # 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
|
333 # 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
|
334 # database |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
335 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
|
336 else: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
337 group_name = group_path = '' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
338 repo_name_full = repo_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
339 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
340 value['repo_name'] = repo_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
341 value['repo_name_full'] = repo_name_full |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
342 value['group_path'] = group_path |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
343 value['group_name'] = group_name |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
344 return value |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
345 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
346 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
347 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
348 repo_name = value.get('repo_name') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
349 repo_name_full = value.get('repo_name_full') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
350 group_path = value.get('group_path') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
351 group_name = value.get('group_name') |
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 if repo_name in [ADMIN_PREFIX, '']: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
354 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
|
355 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
356 error_dict=dict(repo_name=msg) |
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 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
359 rename = old_data.get('repo_name') != repo_name_full |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
360 create = not edit |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
361 if rename or create: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
362 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
363 if group_path != '': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
364 if Repository.get_by_repo_name(repo_name_full): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
365 msg = M(self, 'repository_in_group_exists', state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
366 repo=repo_name, group=group_name) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
367 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
368 error_dict=dict(repo_name=msg) |
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 elif RepoGroup.get_by_group_name(repo_name_full): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
371 msg = M(self, 'same_group_exists', state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
372 repo=repo_name) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
373 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
374 error_dict=dict(repo_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
375 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
376 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
377 elif Repository.get_by_repo_name(repo_name_full): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
378 msg = M(self, 'repository_exists', state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
379 repo=repo_name) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
380 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
381 error_dict=dict(repo_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
382 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
383 return value |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
384 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
385 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
386 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
387 def ValidForkName(*args, **kwargs): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
388 return ValidRepoName(*args, **kwargs) |
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 SlugifyName(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
392 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
393 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
394 def _to_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
395 return repo_name_slug(value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
396 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
397 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
398 pass |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
399 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
400 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
401 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
402 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
403 def ValidCloneUri(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
404 from rhodecode.lib.utils import make_ui |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
405 |
2701 | 406 def url_handler(repo_type, url, ui=None): |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
407 if repo_type == 'hg': |
2706
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
408 from rhodecode.lib.vcs.backends.hg.repository import MercurialRepository |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
409 from mercurial.httppeer import httppeer |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
410 if url.startswith('http'): |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
411 ## initially check if it's at least the proper URL |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
412 ## or does it pass basic auth |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
413 MercurialRepository._check_url(url) |
2717
dd240b2b7a12
Added optional flag to make_ui to not clean sqlalchemy Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
2711
diff
changeset
|
414 httppeer(ui, url)._capabilities() |
2701 | 415 elif url.startswith('svn+http'): |
416 from hgsubversion.svnrepo import svnremoterepo | |
2717
dd240b2b7a12
Added optional flag to make_ui to not clean sqlalchemy Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
2711
diff
changeset
|
417 svnremoterepo(ui, url).capabilities |
2706
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
418 elif url.startswith('git+http'): |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
419 raise NotImplementedError() |
3482
8ee36513efae
disallow cloning from different URI's that http[s]/svn/git/hg
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
420 else: |
8ee36513efae
disallow cloning from different URI's that http[s]/svn/git/hg
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
421 raise Exception('clone from URI %s not allowed' % (url)) |
2706
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
422 |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
423 elif repo_type == 'git': |
2706
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
424 from rhodecode.lib.vcs.backends.git.repository import GitRepository |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
425 if url.startswith('http'): |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
426 ## initially check if it's at least the proper URL |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
427 ## or does it pass basic auth |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
428 GitRepository._check_url(url) |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
429 elif url.startswith('svn+http'): |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
430 raise NotImplementedError() |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
431 elif url.startswith('hg+http'): |
22f79562836c
Fixed validators for remote repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2701
diff
changeset
|
432 raise NotImplementedError() |
3482
8ee36513efae
disallow cloning from different URI's that http[s]/svn/git/hg
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
433 else: |
8ee36513efae
disallow cloning from different URI's that http[s]/svn/git/hg
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
434 raise Exception('clone from URI %s not allowed' % (url)) |
2466
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 'clone_uri': _(u'invalid clone url'), |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
439 'invalid_clone_uri': _(u'Invalid clone url, provide a ' |
2700
f4b20558ae16
allow cloning with hgsubversion (reimplementing pull request 46)
domruf <dominikruf@gmail.com>
parents:
2479
diff
changeset
|
440 'valid clone http(s)/svn+http(s) url') |
2466
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 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
443 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
444 repo_type = value.get('repo_type') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
445 url = value.get('clone_uri') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
446 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
447 if not url: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
448 pass |
2701 | 449 else: |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
450 try: |
2717
dd240b2b7a12
Added optional flag to make_ui to not clean sqlalchemy Session.
Marcin Kuzminski <marcin@python-works.com>
parents:
2711
diff
changeset
|
451 url_handler(repo_type, url, make_ui('db', clear_session=False)) |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
452 except Exception: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
453 log.exception('Url validation failed') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
454 msg = M(self, 'clone_uri') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
455 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
456 error_dict=dict(clone_uri=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
457 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
458 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
459 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
460 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
461 def ValidForkType(old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
462 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
463 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
464 '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
|
465 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
466 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
467 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
468 if old_data['repo_type'] != value: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
469 msg = M(self, 'invalid_fork_type', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
470 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
471 error_dict=dict(repo_type=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
472 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
473 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
474 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
475 |
3524
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
476 def CanWriteGroup(old_data=None): |
2835
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
477 class _validator(formencode.validators.FancyValidator): |
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
478 messages = { |
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
479 'permission_denied': _(u"You don't have permissions " |
3372
157231a4fcb7
move permission check of write access to repo groups inside a form.
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
480 "to create repository in this group"), |
157231a4fcb7
move permission check of write access to repo groups inside a form.
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
481 'permission_denied_root': _(u"no permission to create repository " |
157231a4fcb7
move permission check of write access to repo groups inside a form.
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
482 "in root location") |
2835
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
483 } |
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
484 |
3372
157231a4fcb7
move permission check of write access to repo groups inside a form.
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
485 def _to_python(self, value, state): |
3222
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
486 #root location |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
487 if value in [-1, "-1"]: |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
488 return None |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
489 return value |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
490 |
2835
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
491 def validate_python(self, value, state): |
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
492 gr = RepoGroup.get(value) |
3222
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
493 gr_name = gr.group_name if gr else None # None means ROOT location |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
494 val = HasReposGroupPermissionAny('group.write', 'group.admin') |
3372
157231a4fcb7
move permission check of write access to repo groups inside a form.
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
495 can_create_repos = HasPermissionAny('hg.admin', 'hg.create.repository') |
3222
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
496 forbidden = not val(gr_name, 'can write into group validator') |
3524
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
497 value_changed = True # old_data['repo_group'].get('group_id') != safe_int(value) |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
498 if value_changed: # do check if we changed the value |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
499 #parent group need to be existing |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
500 if gr and forbidden: |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
501 msg = M(self, 'permission_denied', state) |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
502 raise formencode.Invalid(msg, value, state, |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
503 error_dict=dict(repo_type=msg) |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
504 ) |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
505 ## check if we can write to root location ! |
3625
260a7a01b054
follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents:
3524
diff
changeset
|
506 elif gr is None and not can_create_repos(): |
3524
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
507 msg = M(self, 'permission_denied_root', state) |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
508 raise formencode.Invalid(msg, value, state, |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
509 error_dict=dict(repo_type=msg) |
af96fb19b53a
Pass in old groups data to CanWriteToGroup validator for later skipping group checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3482
diff
changeset
|
510 ) |
3372
157231a4fcb7
move permission check of write access to repo groups inside a form.
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
511 |
2835
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
512 return _validator |
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
513 |
faffec4abbda
Implemented permissions for writing to repo
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
514 |
3222
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
515 def CanCreateGroup(can_create_in_root=False): |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
516 class _validator(formencode.validators.FancyValidator): |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
517 messages = { |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
518 'permission_denied': _(u"You don't have permissions " |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
519 "to create a group in this location") |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
520 } |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
521 |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
522 def to_python(self, value, state): |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
523 #root location |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
524 if value in [-1, "-1"]: |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
525 return None |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
526 return value |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
527 |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
528 def validate_python(self, value, state): |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
529 gr = RepoGroup.get(value) |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
530 gr_name = gr.group_name if gr else None # None means ROOT location |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
531 |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
532 if can_create_in_root and gr is None: |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
533 #we can create in root, we're fine no validations required |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
534 return |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
535 |
3625
260a7a01b054
follow Python conventions for boolean values
Mads Kiilerich <madski@unity3d.com>
parents:
3524
diff
changeset
|
536 forbidden_in_root = gr is None and not can_create_in_root |
3222
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
537 val = HasReposGroupPermissionAny('group.admin') |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
538 forbidden = not val(gr_name, 'can create group validator') |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
539 if forbidden_in_root or forbidden: |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
540 msg = M(self, 'permission_denied', state) |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
541 raise formencode.Invalid(msg, value, state, |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
542 error_dict=dict(group_parent_id=msg) |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
543 ) |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
544 |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
545 return _validator |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
546 |
b4daef4cc26d
Group management delegation:
Marcin Kuzminski <marcin@python-works.com>
parents:
3219
diff
changeset
|
547 |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
548 def ValidPerms(type_='repo'): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
549 if type_ == 'group': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
550 EMPTY_PERM = 'group.none' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
551 elif type_ == 'repo': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
552 EMPTY_PERM = 'repository.none' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
553 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
554 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
555 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
556 'perm_new_member_name': |
3415
b8f929bff7e3
fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents:
3372
diff
changeset
|
557 _(u'This username or user group name is not valid') |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
558 } |
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 def to_python(self, value, state): |
2759
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
561 perms_update = OrderedSet() |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
562 perms_new = OrderedSet() |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
563 # build a list of permission to update and new permission to create |
2759
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
564 |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
565 #CLEAN OUT ORG VALUE FROM NEW MEMBERS, and group them using |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
566 new_perms_group = defaultdict(dict) |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
567 for k, v in value.copy().iteritems(): |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
568 if k.startswith('perm_new_member'): |
2759
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
569 del value[k] |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
570 _type, part = k.split('perm_new_member_') |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
571 args = part.split('_') |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
572 if len(args) == 1: |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
573 new_perms_group[args[0]]['perm'] = v |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
574 elif len(args) == 2: |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
575 _key, pos = args |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
576 new_perms_group[pos][_key] = v |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
577 |
2759
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
578 # fill new permissions in order of how they were added |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
579 for k in sorted(map(int, new_perms_group.keys())): |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
580 perm_dict = new_perms_group[str(k)] |
2820
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2759
diff
changeset
|
581 new_member = perm_dict.get('name') |
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2759
diff
changeset
|
582 new_perm = perm_dict.get('perm') |
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2759
diff
changeset
|
583 new_type = perm_dict.get('type') |
2759
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
584 if new_member and new_perm and new_type: |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
585 perms_new.add((new_member, new_perm, new_type)) |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
586 |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
587 for k, v in value.iteritems(): |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
588 if k.startswith('u_perm_') or k.startswith('g_perm_'): |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
589 member = k[7:] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
590 t = {'u': 'user', |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
591 'g': 'users_group' |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
592 }[k[0]] |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
593 if member == 'default': |
3217
f5c5095c7028
fix private flag switching default permission
Marcin Kuzminski <marcin@python-works.com>
parents:
3212
diff
changeset
|
594 if value.get('repo_private'): |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
595 # set none for default when updating to |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
596 # private repo |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
597 v = EMPTY_PERM |
2759
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
598 perms_update.add((member, v, t)) |
3219
42d7ca49d073
added test for setting repo as private which should set perm => None for default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3217
diff
changeset
|
599 #always set NONE when private flag is set |
42d7ca49d073
added test for setting repo as private which should set perm => None for default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3217
diff
changeset
|
600 if value.get('repo_private'): |
42d7ca49d073
added test for setting repo as private which should set perm => None for default user
Marcin Kuzminski <marcin@python-works.com>
parents:
3217
diff
changeset
|
601 perms_update.add(('default', EMPTY_PERM, 'user')) |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
602 |
2759
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
603 value['perms_updates'] = list(perms_update) |
c61c2ccea2b4
#538 form for permissions can handle multiple users at once
Marcin Kuzminski <marcin@python-works.com>
parents:
2719
diff
changeset
|
604 value['perms_new'] = list(perms_new) |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
605 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
606 # update permissions |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
607 for k, v, t in perms_new: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
608 try: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
609 if t is 'user': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
610 self.user_db = User.query()\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
611 .filter(User.active == True)\ |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
612 .filter(User.username == k).one() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
613 if t is 'users_group': |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
614 self.user_db = UserGroup.query()\ |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
615 .filter(UserGroup.users_group_active == True)\ |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3416
diff
changeset
|
616 .filter(UserGroup.users_group_name == k).one() |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
617 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
618 except Exception: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
619 log.exception('Updated permission failed') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
620 msg = M(self, 'perm_new_member_type', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
621 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
622 error_dict=dict(perm_new_member_name=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
623 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
624 return value |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
625 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
626 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
627 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
628 def ValidSettings(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
629 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
630 def _to_python(self, value, state): |
3149
68f9c216377d
white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents:
3125
diff
changeset
|
631 # settings form for users that are not admin |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
632 # can't edit certain parameters, it's extra backup if they mangle |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
633 # with forms |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
634 |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
635 forbidden_params = [ |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
636 'user', 'repo_type', 'repo_enable_locking', |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
637 'repo_enable_downloads', 'repo_enable_statistics' |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
638 ] |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
639 |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
640 for param in forbidden_params: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
641 if param in value: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
2893
diff
changeset
|
642 del value[param] |
2466
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
643 return value |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
644 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
645 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
646 pass |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
647 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
648 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
649 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
650 def ValidPath(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
651 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
652 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
653 'invalid_path': _(u'This is not a valid path') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
654 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
655 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
656 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
657 if not os.path.isdir(value): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
658 msg = M(self, 'invalid_path', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
659 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
660 error_dict=dict(paths_root_path=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
661 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
662 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
663 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
664 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
665 def UniqSystemEmail(old_data={}): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
666 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
667 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
668 '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
|
669 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
670 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
671 def _to_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
672 return value.lower() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
673 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
674 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
675 if (old_data.get('email') or '').lower() != value: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
676 user = User.get_by_email(value, case_insensitive=True) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
677 if user: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
678 msg = M(self, 'email_taken', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
679 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
680 error_dict=dict(email=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
681 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
682 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
683 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
684 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
685 def ValidSystemEmail(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
686 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
687 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
688 '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
|
689 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
690 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
691 def _to_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
692 return value.lower() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
693 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
694 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
695 user = User.get_by_email(value, case_insensitive=True) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
696 if user is None: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
697 msg = M(self, 'non_existing_email', state, email=value) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
698 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
699 error_dict=dict(email=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
700 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
701 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
702 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
703 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
704 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
705 def LdapLibValidator(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
706 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
707 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
708 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
709 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
710 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
711 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
712 try: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
713 import ldap |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
714 ldap # pyflakes silence ! |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
715 except ImportError: |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
716 raise LdapImportError() |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
717 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
718 return _validator |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
719 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
720 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
721 def AttrLoginValidator(): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
722 class _validator(formencode.validators.FancyValidator): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
723 messages = { |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
724 'invalid_cn': |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
725 _(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
|
726 '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
|
727 'to "username"') |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
728 } |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
729 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
730 def validate_python(self, value, state): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
731 if not value or not isinstance(value, (str, unicode)): |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
732 msg = M(self, 'invalid_cn', state) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
733 raise formencode.Invalid(msg, value, state, |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
734 error_dict=dict(ldap_attr_login=msg) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
735 ) |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
736 |
7010dc12f10c
Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
737 return _validator |
2719
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
738 |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
739 |
2893
eb180eb16c18
Fixed #585, checks for status of revision where to strict, and made opening pull request with those revision impossible due to previosly set status.
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
740 def NotReviewedRevisions(repo_id): |
2719
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
741 class _validator(formencode.validators.FancyValidator): |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
742 messages = { |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
743 'rev_already_reviewed': |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
744 _(u'Revisions %(revs)s are already part of pull request ' |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
745 'or have set status') |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
746 } |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
747 |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
748 def validate_python(self, value, state): |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
749 # check revisions if they are not reviewed, or a part of another |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
750 # pull request |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
751 statuses = ChangesetStatus.query()\ |
2893
eb180eb16c18
Fixed #585, checks for status of revision where to strict, and made opening pull request with those revision impossible due to previosly set status.
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
752 .filter(ChangesetStatus.revision.in_(value))\ |
eb180eb16c18
Fixed #585, checks for status of revision where to strict, and made opening pull request with those revision impossible due to previosly set status.
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
753 .filter(ChangesetStatus.repo_id == repo_id)\ |
eb180eb16c18
Fixed #585, checks for status of revision where to strict, and made opening pull request with those revision impossible due to previosly set status.
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
754 .all() |
eb180eb16c18
Fixed #585, checks for status of revision where to strict, and made opening pull request with those revision impossible due to previosly set status.
Marcin Kuzminski <marcin@python-works.com>
parents:
2835
diff
changeset
|
755 |
2719
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
756 errors = [] |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
757 for cs in statuses: |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
758 if cs.pull_request_id: |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
759 errors.append(['pull_req', cs.revision[:12]]) |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
760 elif cs.status: |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
761 errors.append(['status', cs.revision[:12]]) |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
762 |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
763 if errors: |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
764 revs = ','.join([x[1] for x in errors]) |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
765 msg = M(self, 'rev_already_reviewed', state, revs=revs) |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
766 raise formencode.Invalid(msg, value, state, |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
767 error_dict=dict(revisions=revs) |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
768 ) |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
769 |
2e7f7568ea92
Changed v.Set validation into our own that actually raises exceptions on missing values.
Marcin Kuzminski <marcin@python-works.com>
parents:
2717
diff
changeset
|
770 return _validator |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
771 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
772 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
773 def ValidIp(): |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
774 class _validator(CIDR): |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
775 messages = dict( |
3212
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
776 badFormat=_('Please enter a valid IPv4 or IpV6 address'), |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
777 illegalBits=_('The network size (bits) must be within the range' |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
778 ' of 0-32 (not %(bits)r)')) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
779 |
3212
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
780 def to_python(self, value, state): |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
781 v = super(_validator, self).to_python(value, state) |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
782 v = v.strip() |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
783 net = ipaddr.IPNetwork(address=v) |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
784 if isinstance(net, ipaddr.IPv4Network): |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
785 #if IPv4 doesn't end with a mask, add /32 |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
786 if '/' not in value: |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
787 v += '/32' |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
788 if isinstance(net, ipaddr.IPv6Network): |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
789 #if IPv6 doesn't end with a mask, add /128 |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
790 if '/' not in value: |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
791 v += '/128' |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
792 return v |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
793 |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
794 def validate_python(self, value, state): |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
795 try: |
3212
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
796 addr = value.strip() |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
797 #this raises an ValueError if address is not IpV4 or IpV6 |
6c28533d122c
IP restrictions now also enabled for IPv6
Marcin Kuzminski <marcin@python-works.com>
parents:
3186
diff
changeset
|
798 ipaddr.IPNetwork(address=addr) |
3125
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
799 except ValueError: |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
800 raise formencode.Invalid(self.message('badFormat', state), |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
801 value, state) |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
802 |
9b92cf5a0cca
Added UserIpMap interface for allowed IP addresses and IP restriction access
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
803 return _validator |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
804 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
805 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
806 def FieldKey(): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
807 class _validator(formencode.validators.FancyValidator): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
808 messages = dict( |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
809 badFormat=_('Key name can only consist of letters, ' |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
810 'underscore, dash or numbers'),) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
811 |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
812 def validate_python(self, value, state): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
813 if not re.match('[a-zA-Z0-9_-]+$', value): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
814 raise formencode.Invalid(self.message('badFormat', state), |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
815 value, state) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3223
diff
changeset
|
816 return _validator |