Mercurial > public > src > rhodecode
annotate pylons_app/model/forms.py @ 481:d66a7fa7689b
moved loged in user propagation out of forms,
update user model to get auto update last login.
bugfix with redirect log
fixed forms logic a little bit
some other tweeks
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 01 Sep 2010 23:32:47 +0200 |
parents | 63c697d1a631 |
children | 00f883abdb0c |
rev | line source |
---|---|
0 | 1 """ this is forms validation classes |
2 http://formencode.org/module-formencode.validators.html | |
3 for list off all availible validators | |
4 | |
5 we can create our own validators | |
6 | |
7 The table below outlines the options which can be used in a schema in addition to the validators themselves | |
8 pre_validators [] These validators will be applied before the schema | |
9 chained_validators [] These validators will be applied after the schema | |
10 allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present | |
11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed | |
12 if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value. | |
13 ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already | |
14 | |
15 | |
16 <name> = formencode.validators.<name of validator> | |
17 <name> must equal form name | |
18 list=[1,2,3,4,5] | |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
19 for SELECT use formencode.All(OneOf(list), Int()) |
0 | 20 |
21 """ | |
242
5da4ef115006
Added lastlogin to user after login, model db update
Marcin Kuzminski <marcin@python-works.com>
parents:
238
diff
changeset
|
22 from formencode import All |
238
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
23 from formencode.validators import UnicodeString, OneOf, Int, Number, Regex, \ |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
24 Email, Bool, StringBoolean |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
25 from pylons import session |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
26 from pylons.i18n.translation import _ |
452
25ab66a26975
fix for new bcrypt password.
Marcin Kuzminski <marcin@python-works.com>
parents:
451
diff
changeset
|
27 from pylons_app.lib.auth import check_password, get_crypt_password |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
28 from pylons_app.model import meta |
481
d66a7fa7689b
moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents:
454
diff
changeset
|
29 from pylons_app.model.user_model import UserModel |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
30 from pylons_app.model.db import User, Repository |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
31 from sqlalchemy.exc import OperationalError |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
32 from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
33 from webhelpers.pylonslib.secure_form import authentication_token |
0 | 34 import formencode |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
35 import logging |
421
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
36 import os |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
37 import pylons_app.lib.helpers as h |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
38 log = logging.getLogger(__name__) |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
39 |
0 | 40 |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
41 #this is needed to translate the messages using _() in validators |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
42 class State_obj(object): |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
43 _ = staticmethod(_) |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
44 |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
45 #=============================================================================== |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
46 # VALIDATORS |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
47 #=============================================================================== |
0 | 48 class ValidAuthToken(formencode.validators.FancyValidator): |
49 messages = {'invalid_token':_('Token mismatch')} | |
50 | |
51 def validate_python(self, value, state): | |
52 | |
53 if value != authentication_token(): | |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
54 raise formencode.Invalid(self.message('invalid_token', state, |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
55 search_number=value), value, state) |
383
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
56 |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
57 def ValidUsername(edit, old_data): |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
58 class _ValidUsername(formencode.validators.FancyValidator): |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
59 |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
60 def validate_python(self, value, state): |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
61 if value in ['default', 'new_user']: |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
62 raise formencode.Invalid(_('Invalid username'), value, state) |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
63 #check if user is uniq |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
64 sa = meta.Session |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
65 old_un = None |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
66 if edit: |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
67 old_un = sa.query(User).get(old_data.get('user_id')).username |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
68 |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
69 if old_un != value or not edit: |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
70 if sa.query(User).filter(User.username == value).scalar(): |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
71 raise formencode.Invalid(_('This username already exists') , |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
72 value, state) |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
73 meta.Session.remove() |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
74 |
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
75 return _ValidUsername |
238
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
76 |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
77 class ValidPassword(formencode.validators.FancyValidator): |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
78 |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
79 def to_python(self, value, state): |
370
40bccabf4574
fixed bug for user update, when password was always set.
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
80 if value: |
40bccabf4574
fixed bug for user update, when password was always set.
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
81 return get_crypt_password(value) |
238
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
82 |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
83 class ValidAuth(formencode.validators.FancyValidator): |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
84 messages = { |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
85 'invalid_password':_('invalid password'), |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
86 'invalid_login':_('invalid user name'), |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
87 'disabled_account':_('Your acccount is disabled') |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
88 |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
89 } |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
90 #error mapping |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
91 e_dict = {'username':messages['invalid_login'], |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
92 'password':messages['invalid_password']} |
227
351013049742
CHanged form error when user account is disabled.
Marcin Kuzminski <marcin@python-works.com>
parents:
201
diff
changeset
|
93 e_dict_disable = {'username':messages['disabled_account']} |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
94 |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
95 def validate_python(self, value, state): |
451
04e8b31fb245
Changed password crypting scheme to bcrypt, added dependency for setup
Marcin Kuzminski <marcin@python-works.com>
parents:
428
diff
changeset
|
96 password = value['password'] |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
97 username = value['username'] |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
98 try: |
481
d66a7fa7689b
moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents:
454
diff
changeset
|
99 user = UserModel().get_user_by_name(username) |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
100 except (NoResultFound, MultipleResultsFound, OperationalError) as e: |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
101 log.error(e) |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
102 user = None |
238
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
103 raise formencode.Invalid(self.message('invalid_password', |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
104 state=State_obj), value, state, |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
105 error_dict=self.e_dict) |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
106 if user: |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
107 if user.active: |
481
d66a7fa7689b
moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents:
454
diff
changeset
|
108 if user.username == username and check_password(password, |
d66a7fa7689b
moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents:
454
diff
changeset
|
109 user.password): |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
110 return value |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
111 else: |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
112 log.warning('user %s not authenticated', username) |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
113 raise formencode.Invalid(self.message('invalid_password', |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
114 state=State_obj), value, state, |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
115 error_dict=self.e_dict) |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
116 else: |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
117 log.warning('user %s is disabled', username) |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
118 raise formencode.Invalid(self.message('disabled_account', |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
119 state=State_obj), |
227
351013049742
CHanged form error when user account is disabled.
Marcin Kuzminski <marcin@python-works.com>
parents:
201
diff
changeset
|
120 value, state, |
351013049742
CHanged form error when user account is disabled.
Marcin Kuzminski <marcin@python-works.com>
parents:
201
diff
changeset
|
121 error_dict=self.e_dict_disable) |
382
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
122 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
123 class ValidRepoUser(formencode.validators.FancyValidator): |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
124 |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
125 def to_python(self, value, state): |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
126 try: |
481
d66a7fa7689b
moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents:
454
diff
changeset
|
127 self.user_db = meta.Session.query(User)\ |
347
cec5cbc956c0
Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
Marcin Kuzminski <marcin@python-works.com>
parents:
336
diff
changeset
|
128 .filter(User.active == True)\ |
cec5cbc956c0
Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
Marcin Kuzminski <marcin@python-works.com>
parents:
336
diff
changeset
|
129 .filter(User.username == value).one() |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
130 except Exception: |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
131 raise formencode.Invalid(_('This username is not valid'), |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
132 value, state) |
481
d66a7fa7689b
moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents:
454
diff
changeset
|
133 finally: |
d66a7fa7689b
moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents:
454
diff
changeset
|
134 meta.Session.remove() |
d66a7fa7689b
moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents:
454
diff
changeset
|
135 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
136 return self.user_db.user_id |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
137 |
382
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
138 def ValidRepoName(edit, old_data): |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
139 class _ValidRepoName(formencode.validators.FancyValidator): |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
140 |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
141 def to_python(self, value, state): |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
142 slug = h.repo_name_slug(value) |
323
fc4027fe46bc
fixed bug when user is capable of creating _admin repository which is a link to admin interface
Marcin Kuzminski <marcin@python-works.com>
parents:
312
diff
changeset
|
143 if slug in ['_admin']: |
fc4027fe46bc
fixed bug when user is capable of creating _admin repository which is a link to admin interface
Marcin Kuzminski <marcin@python-works.com>
parents:
312
diff
changeset
|
144 raise formencode.Invalid(_('This repository name is disallowed'), |
fc4027fe46bc
fixed bug when user is capable of creating _admin repository which is a link to admin interface
Marcin Kuzminski <marcin@python-works.com>
parents:
312
diff
changeset
|
145 value, state) |
382
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
146 if old_data.get('repo_name') != value or not edit: |
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
147 sa = meta.Session |
393
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
389
diff
changeset
|
148 if sa.query(Repository).filter(Repository.repo_name == slug).scalar(): |
382
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
149 raise formencode.Invalid(_('This repository already exists') , |
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
150 value, state) |
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
151 meta.Session.remove() |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
152 return slug |
382
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
153 |
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
154 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
155 return _ValidRepoName |
309
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
156 |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
157 class ValidPerms(formencode.validators.FancyValidator): |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
158 messages = {'perm_new_user_name':_('This username is not valid')} |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
159 |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
160 def to_python(self, value, state): |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
161 perms_update = [] |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
162 perms_new = [] |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
163 #build a list of permission to update and new permission to create |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
164 for k, v in value.items(): |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
165 if k.startswith('perm_'): |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
166 if k.startswith('perm_new_user'): |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
167 new_perm = value.get('perm_new_user', False) |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
168 new_user = value.get('perm_new_user_name', False) |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
169 if new_user and new_perm: |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
170 if (new_user, new_perm) not in perms_new: |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
171 perms_new.append((new_user, new_perm)) |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
172 else: |
312
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
309
diff
changeset
|
173 usr = k[5:] |
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
309
diff
changeset
|
174 if usr == 'default': |
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
309
diff
changeset
|
175 if value['private']: |
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
309
diff
changeset
|
176 #set none for default when updating to private repo |
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
309
diff
changeset
|
177 v = 'repository.none' |
d303aacb3349
repos crud controllers - change id into repo_name for compatability, added ajax repo perm user function variuos html fixes, permissions forms and managment fixes.
Marcin Kuzminski <marcin@python-works.com>
parents:
309
diff
changeset
|
178 perms_update.append((usr, v)) |
309
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
179 value['perms_updates'] = perms_update |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
180 value['perms_new'] = perms_new |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
181 sa = meta.Session |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
182 for k, v in perms_new: |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
183 try: |
347
cec5cbc956c0
Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
Marcin Kuzminski <marcin@python-works.com>
parents:
336
diff
changeset
|
184 self.user_db = sa.query(User)\ |
cec5cbc956c0
Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
Marcin Kuzminski <marcin@python-works.com>
parents:
336
diff
changeset
|
185 .filter(User.active == True)\ |
cec5cbc956c0
Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
Marcin Kuzminski <marcin@python-works.com>
parents:
336
diff
changeset
|
186 .filter(User.username == k).one() |
309
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
187 except Exception: |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
188 msg = self.message('perm_new_user_name', |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
189 state=State_obj) |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
190 raise formencode.Invalid(msg, value, state, error_dict={'perm_new_user_name':msg}) |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
191 return value |
336
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
192 |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
193 class ValidSettings(formencode.validators.FancyValidator): |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
194 |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
195 def to_python(self, value, state): |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
196 #settings form can't edit user |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
197 if value.has_key('user'): |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
198 del['value']['user'] |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
199 |
421
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
200 return value |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
201 |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
202 class ValidPath(formencode.validators.FancyValidator): |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
203 def to_python(self, value, state): |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
204 isdir = os.path.isdir(value.replace('*', '')) |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
205 if (value.endswith('/*') or value.endswith('/**')) and isdir: |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
206 return value |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
207 elif not isdir: |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
208 msg = _('This is not a valid path') |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
209 else: |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
210 msg = _('You need to specify * or ** at the end of path (ie. /tmp/*)') |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
211 |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
212 raise formencode.Invalid(msg, value, state, |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
213 error_dict={'paths_root_path':msg}) |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
214 |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
215 #=============================================================================== |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
216 # FORMS |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
217 #=============================================================================== |
45 | 218 class LoginForm(formencode.Schema): |
219 allow_extra_fields = True | |
220 filter_extra_fields = True | |
221 username = UnicodeString( | |
222 strip=True, | |
223 min=3, | |
224 not_empty=True, | |
225 messages={ | |
226 'empty':_('Please enter a login'), | |
227 'tooShort':_('Enter a value %(min)i characters long or more')} | |
228 ) | |
0 | 229 |
45 | 230 password = UnicodeString( |
231 strip=True, | |
232 min=3, | |
233 not_empty=True, | |
234 messages={ | |
235 'empty':_('Please enter a password'), | |
236 'tooShort':_('Enter a value %(min)i characters long or more')} | |
237 ) | |
0 | 238 |
239 | |
186
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
240 #chained validators have access to all data |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
241 chained_validators = [ValidAuth] |
556473ba0399
fixed menu in home page, and added login html with forms that validates username and password.
Marcin Kuzminski <marcin@python-works.com>
parents:
45
diff
changeset
|
242 |
383
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
243 def UserForm(edit=False, old_data={}): |
238
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
244 class _UserForm(formencode.Schema): |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
245 allow_extra_fields = True |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
246 filter_extra_fields = True |
383
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
247 username = All(UnicodeString(strip=True, min=3, not_empty=True), ValidUsername(edit, old_data)) |
238
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
248 if edit: |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
249 new_password = All(UnicodeString(strip=True, min=3, not_empty=False), ValidPassword) |
348
aafd9a98ea58
added admin flag to users editing
Marcin Kuzminski <marcin@python-works.com>
parents:
347
diff
changeset
|
250 admin = StringBoolean(if_missing=False) |
238
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
251 else: |
383
ebdd1a89cdd9
Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents:
382
diff
changeset
|
252 password = All(UnicodeString(strip=True, min=8, not_empty=True), ValidPassword) |
238
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
253 active = StringBoolean(if_missing=False) |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
254 name = UnicodeString(strip=True, min=3, not_empty=True) |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
255 lastname = UnicodeString(strip=True, min=3, not_empty=True) |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
256 email = Email(not_empty=True) |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
257 |
a55c17874486
Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents:
234
diff
changeset
|
258 return _UserForm |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
259 |
389
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
383
diff
changeset
|
260 RegisterForm = UserForm |
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
383
diff
changeset
|
261 |
98abf8953b87
Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents:
383
diff
changeset
|
262 |
382
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
263 def RepoForm(edit=False, old_data={}): |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
264 class _RepoForm(formencode.Schema): |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
265 allow_extra_fields = True |
309
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
266 filter_extra_fields = False |
382
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
267 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data)) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
268 description = UnicodeString(strip=True, min=3, not_empty=True) |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
269 private = StringBoolean(if_missing=False) |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
270 |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
271 if edit: |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
272 user = All(Int(not_empty=True), ValidRepoUser) |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
273 |
309
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
274 chained_validators = [ValidPerms] |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
242
diff
changeset
|
275 return _RepoForm |
336
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
276 |
382
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
277 def RepoSettingsForm(edit=False, old_data={}): |
336
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
278 class _RepoForm(formencode.Schema): |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
279 allow_extra_fields = True |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
280 filter_extra_fields = False |
382
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
281 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data)) |
336
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
282 description = UnicodeString(strip=True, min=3, not_empty=True) |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
283 private = StringBoolean(if_missing=False) |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
284 |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
285 chained_validators = [ValidPerms, ValidSettings] |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
286 return _RepoForm |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
287 |
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
288 |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
370
diff
changeset
|
289 def ApplicationSettingsForm(): |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
370
diff
changeset
|
290 class _ApplicationSettingsForm(formencode.Schema): |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
370
diff
changeset
|
291 allow_extra_fields = True |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
370
diff
changeset
|
292 filter_extra_fields = False |
413
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
393
diff
changeset
|
293 hg_app_title = UnicodeString(strip=True, min=3, not_empty=True) |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
393
diff
changeset
|
294 hg_app_realm = UnicodeString(strip=True, min=3, not_empty=True) |
374
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
370
diff
changeset
|
295 |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
370
diff
changeset
|
296 return _ApplicationSettingsForm |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
370
diff
changeset
|
297 |
421
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
298 def ApplicationUiSettingsForm(): |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
299 class _ApplicationUiSettingsForm(formencode.Schema): |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
300 allow_extra_fields = True |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
301 filter_extra_fields = False |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
302 web_push_ssl = OneOf(['true', 'false'], if_missing='false') |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
303 paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=3, not_empty=True)) |
428
e8af467b5a60
Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
421
diff
changeset
|
304 hooks_changegroup_update = OneOf(['True', 'False'], if_missing=False) |
e8af467b5a60
Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
421
diff
changeset
|
305 hooks_changegroup_repo_size = OneOf(['True', 'False'], if_missing=False) |
421
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
306 |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
413
diff
changeset
|
307 return _ApplicationUiSettingsForm |
336
05b212954275
Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents:
323
diff
changeset
|
308 |
453
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
452
diff
changeset
|
309 def DefaultPermissionsForm(perms_choices, register_choices, create_choices): |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
452
diff
changeset
|
310 class _DefaultPermissionsForm(formencode.Schema): |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
452
diff
changeset
|
311 allow_extra_fields = True |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
452
diff
changeset
|
312 filter_extra_fields = True |
454
63c697d1a631
added logic for changin defualt permissions, and option to overwrite all defualt permissions on each repository
Marcin Kuzminski <marcin@python-works.com>
parents:
453
diff
changeset
|
313 overwrite_default = OneOf(['true', 'false'], if_missing='false') |
453
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
452
diff
changeset
|
314 default_perm = OneOf(perms_choices) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
452
diff
changeset
|
315 default_register = OneOf(register_choices) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
452
diff
changeset
|
316 default_create = OneOf(create_choices) |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
452
diff
changeset
|
317 |
3ed2d46a2ca7
permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents:
452
diff
changeset
|
318 return _DefaultPermissionsForm |