annotate rhodecode/model/forms.py @ 555:03676d39dd0a

added fault tolerant case when celeryconfig is not present in the directory. small form fixes, and websetup default app title and admin name
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 06 Oct 2010 18:26:59 +0200
parents b75b77ef649d
children 7e536d1af60d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
1 """ this is forms validation classes
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
2 http://formencode.org/module-formencode.validators.html
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
3 for list off all availible validators
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
4
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
5 we can create our own validators
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
6
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
7 The table below outlines the options which can be used in a schema in addition to the validators themselves
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
8 pre_validators [] These validators will be applied before the schema
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
9 chained_validators [] These validators will be applied after the schema
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
10 allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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.
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
14
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
15
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
16 <name> = formencode.validators.<name of validator>
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
17 <name> must equal form name
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
20
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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 _
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 530
diff changeset
27 from rhodecode.lib.auth import check_password, get_crypt_password
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 530
diff changeset
28 from rhodecode.model import meta
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 530
diff changeset
29 from rhodecode.model.user_model import UserModel
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 530
diff changeset
30 from rhodecode.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
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
36 import os
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 530
diff changeset
37 import rhodecode.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
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
48 class ValidAuthToken(formencode.validators.FancyValidator):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
49 messages = {'invalid_token':_('Token mismatch')}
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
50
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
51 def validate_python(self, value, state):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
52
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
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)
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
56
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
57 def ValidUsername(edit, old_data):
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
58 class _ValidUsername(formencode.validators.FancyValidator):
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
59
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
60 def validate_python(self, value, state):
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
61 if value in ['default', 'new_user']:
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
62 raise formencode.Invalid(_('Invalid username'), value, state)
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
63 #check if user is uniq
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
64 sa = meta.Session
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
65 old_un = None
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
66 if edit:
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
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: 356
diff changeset
68
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
69 if old_un != value or not edit:
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
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: 356
diff changeset
71 raise formencode.Invalid(_('This username already exists') ,
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
72 value, state)
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
73 meta.Session.remove()
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
74
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
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):
347
40bccabf4574 fixed bug for user update, when password was always set.
Marcin Kuzminski <marcin@python-works.com>
parents: 329
diff changeset
80 if value:
40bccabf4574 fixed bug for user update, when password was always set.
Marcin Kuzminski <marcin@python-works.com>
parents: 329
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):
415
04e8b31fb245 Changed password crypting scheme to bcrypt, added dependency for setup
Marcin Kuzminski <marcin@python-works.com>
parents: 395
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']
458
00f883abdb0c fixed a bug when given wrong username at login
Marcin Kuzminski <marcin@python-works.com>
parents: 442
diff changeset
98 user = UserModel().get_user_by_name(username)
00f883abdb0c fixed a bug when given wrong username at login
Marcin Kuzminski <marcin@python-works.com>
parents: 442
diff changeset
99 if user is None:
238
a55c17874486 Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
100 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
101 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
102 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
103 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
104 if user.active:
474
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
105 if user.username == username and check_password(password,
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 418
diff changeset
106 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
107 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
108 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
109 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
110 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
111 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
112 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
113 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
114 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
115 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
116 state=State_obj),
227
351013049742 CHanged form error when user account is disabled.
Marcin Kuzminski <marcin@python-works.com>
parents: 201
diff changeset
117 value, state,
351013049742 CHanged form error when user account is disabled.
Marcin Kuzminski <marcin@python-works.com>
parents: 201
diff changeset
118 error_dict=self.e_dict_disable)
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
119
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
120 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
121
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 242
diff changeset
122 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
123 try:
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 418
diff changeset
124 self.user_db = meta.Session.query(User)\
328
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: 320
diff changeset
125 .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: 320
diff changeset
126 .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
127 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
128 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
129 value, state)
442
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 418
diff changeset
130 finally:
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 418
diff changeset
131 meta.Session.remove()
d66a7fa7689b moved loged in user propagation out of forms,
Marcin Kuzminski <marcin@python-works.com>
parents: 418
diff changeset
132
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
133 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
134
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
135 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
136 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
137
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 242
diff changeset
138 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
139 slug = h.repo_name_slug(value)
310
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: 299
diff changeset
140 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: 299
diff changeset
141 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: 299
diff changeset
142 value, state)
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
143 if old_data.get('repo_name') != value or not edit:
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
144 sa = meta.Session
367
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: 363
diff changeset
145 if sa.query(Repository).filter(Repository.repo_name == slug).scalar():
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
146 raise formencode.Invalid(_('This repository already exists') ,
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
147 value, state)
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
148 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
149 return slug
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
150
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
151
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 _ValidRepoName
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
153
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
154 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
155 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
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 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
158 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
159 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
160 #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
161 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
162 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
163 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
164 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
165 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
166 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
167 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
168 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
169 else:
299
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: 296
diff changeset
170 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: 296
diff changeset
171 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: 296
diff changeset
172 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: 296
diff changeset
173 #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: 296
diff changeset
174 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: 296
diff changeset
175 perms_update.append((usr, v))
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
176 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
177 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
178 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
179 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
180 try:
328
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: 320
diff changeset
181 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: 320
diff changeset
182 .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: 320
diff changeset
183 .filter(User.username == k).one()
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
184 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
185 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
186 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
187 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
188 return value
320
05b212954275 Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
189
05b212954275 Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
190 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: 310
diff changeset
191
05b212954275 Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
192 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: 310
diff changeset
193 #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: 310
diff changeset
194 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: 310
diff changeset
195 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: 310
diff changeset
196
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
197 return value
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
198
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
199 class ValidPath(formencode.validators.FancyValidator):
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
200 def to_python(self, value, state):
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
201 isdir = os.path.isdir(value.replace('*', ''))
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
202 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: 381
diff changeset
203 return value
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
204 elif not isdir:
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
205 msg = _('This is not a valid path')
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
206 else:
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
207 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: 381
diff changeset
208
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
209 raise formencode.Invalid(msg, value, state,
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
210 error_dict={'paths_root_path':msg})
474
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
211
489
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
212 def UniqSystemEmail(old_data):
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
213 class _UniqSystemEmail(formencode.validators.FancyValidator):
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
214 def to_python(self, value, state):
490
74b9bed279ae fixed validation of user email in user creation, and editing on admin panel
Marcin Kuzminski <marcin@python-works.com>
parents: 489
diff changeset
215 if old_data.get('email') != value:
489
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
216 sa = meta.Session
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
217 try:
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
218 user = sa.query(User).filter(User.email == value).scalar()
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
219 if user:
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
220 raise formencode.Invalid(_("That e-mail address is already taken") ,
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
221 value, state)
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
222 finally:
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
223 meta.Session.remove()
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
224
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
225 return value
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
226
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
227 return _UniqSystemEmail
475
9dd38344c466 Added validation for uniq email address
Marcin Kuzminski <marcin@python-works.com>
parents: 474
diff changeset
228
474
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
229 class ValidSystemEmail(formencode.validators.FancyValidator):
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
230 def to_python(self, value, state):
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
231 sa = meta.Session
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
232 try:
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
233 user = sa.query(User).filter(User.email == value).scalar()
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
234 if user is None:
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
235 raise formencode.Invalid(_("That e-mail address doesn't exist.") ,
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
236 value, state)
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
237 finally:
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
238 meta.Session.remove()
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
239
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
240 return value
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
241
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
242 #===============================================================================
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
243 # 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
244 #===============================================================================
45
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
245 class LoginForm(formencode.Schema):
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
246 allow_extra_fields = True
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
247 filter_extra_fields = True
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
248 username = UnicodeString(
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
249 strip=True,
527
6d44d3862ec4 fixes #36, removed username, name, lastname, minimal length restrictions,
Marcin Kuzminski <marcin@python-works.com>
parents: 490
diff changeset
250 min=1,
45
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
251 not_empty=True,
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
252 messages={
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
253 'empty':_('Please enter a login'),
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
254 'tooShort':_('Enter a value %(min)i characters long or more')}
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
255 )
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
256
45
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
257 password = UnicodeString(
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
258 strip=True,
529
3a567e329fb6 updated whoosh deps,
Marcin Kuzminski <marcin@python-works.com>
parents: 527
diff changeset
259 min=6,
45
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
260 not_empty=True,
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
261 messages={
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
262 'empty':_('Please enter a password'),
555
03676d39dd0a added fault tolerant case when celeryconfig is not present in the directory.
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
263 'tooShort':_('Enter %(min)i characters or more')}
45
a886f5eba757 implemented admin page login
marcink
parents: 0
diff changeset
264 )
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
265
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
266
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
267 #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
268 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
269
357
ebdd1a89cdd9 Added extra validation in creating users.
Marcin Kuzminski <marcin@python-works.com>
parents: 356
diff changeset
270 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
271 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
272 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
273 filter_extra_fields = True
527
6d44d3862ec4 fixes #36, removed username, name, lastname, minimal length restrictions,
Marcin Kuzminski <marcin@python-works.com>
parents: 490
diff changeset
274 username = All(UnicodeString(strip=True, min=1, 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
275 if edit:
529
3a567e329fb6 updated whoosh deps,
Marcin Kuzminski <marcin@python-works.com>
parents: 527
diff changeset
276 new_password = All(UnicodeString(strip=True, min=6, not_empty=False), ValidPassword)
329
aafd9a98ea58 added admin flag to users editing
Marcin Kuzminski <marcin@python-works.com>
parents: 328
diff changeset
277 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
278 else:
529
3a567e329fb6 updated whoosh deps,
Marcin Kuzminski <marcin@python-works.com>
parents: 527
diff changeset
279 password = All(UnicodeString(strip=True, min=6, 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
280 active = StringBoolean(if_missing=False)
527
6d44d3862ec4 fixes #36, removed username, name, lastname, minimal length restrictions,
Marcin Kuzminski <marcin@python-works.com>
parents: 490
diff changeset
281 name = UnicodeString(strip=True, min=1, not_empty=True)
6d44d3862ec4 fixes #36, removed username, name, lastname, minimal length restrictions,
Marcin Kuzminski <marcin@python-works.com>
parents: 490
diff changeset
282 lastname = UnicodeString(strip=True, min=1, not_empty=True)
489
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 475
diff changeset
283 email = All(Email(not_empty=True), UniqSystemEmail(old_data))
238
a55c17874486 Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
284
a55c17874486 Rewrite of user managment, improved forms, added some user info
Marcin Kuzminski <marcin@python-works.com>
parents: 234
diff changeset
285 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
286
363
98abf8953b87 Added user registration, changed login url schema, moved it into _admin/ for safety
Marcin Kuzminski <marcin@python-works.com>
parents: 357
diff changeset
287 RegisterForm = UserForm
474
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
288
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
289 def PasswordResetForm():
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
290 class _PasswordResetForm(formencode.Schema):
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
291 allow_extra_fields = True
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
292 filter_extra_fields = True
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
293 email = All(ValidSystemEmail(), Email(not_empty=True))
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
294 return _PasswordResetForm
a3d9d24acbec Implemented password reset(forms/models/ tasks) and mailing tasks.
Marcin Kuzminski <marcin@python-works.com>
parents: 458
diff changeset
295
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
296 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
297 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
298 allow_extra_fields = True
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
299 filter_extra_fields = False
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
300 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
527
6d44d3862ec4 fixes #36, removed username, name, lastname, minimal length restrictions,
Marcin Kuzminski <marcin@python-works.com>
parents: 490
diff changeset
301 description = UnicodeString(strip=True, min=1, not_empty=True)
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
302 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
303
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 242
diff changeset
304 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
305 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
306
296
29370bb76fa6 first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents: 265
diff changeset
307 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
308 return _RepoForm
320
05b212954275 Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
309
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 529
diff changeset
310 def RepoForkForm(edit=False, old_data={}):
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 529
diff changeset
311 class _RepoForkForm(formencode.Schema):
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 529
diff changeset
312 allow_extra_fields = True
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 529
diff changeset
313 filter_extra_fields = False
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 529
diff changeset
314 fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 529
diff changeset
315 description = UnicodeString(strip=True, min=1, not_empty=True)
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 529
diff changeset
316 private = StringBoolean(if_missing=False)
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 529
diff changeset
317
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 529
diff changeset
318 return _RepoForkForm
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 529
diff changeset
319
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
320 def RepoSettingsForm(edit=False, old_data={}):
320
05b212954275 Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
321 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: 310
diff changeset
322 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: 310
diff changeset
323 filter_extra_fields = False
356
b0715a788432 Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents: 355
diff changeset
324 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
527
6d44d3862ec4 fixes #36, removed username, name, lastname, minimal length restrictions,
Marcin Kuzminski <marcin@python-works.com>
parents: 490
diff changeset
325 description = UnicodeString(strip=True, min=1, not_empty=True)
320
05b212954275 Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
326 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: 310
diff changeset
327
05b212954275 Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
328 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: 310
diff changeset
329 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: 310
diff changeset
330
05b212954275 Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
331
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 347
diff changeset
332 def ApplicationSettingsForm():
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 347
diff changeset
333 class _ApplicationSettingsForm(formencode.Schema):
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 347
diff changeset
334 allow_extra_fields = True
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 347
diff changeset
335 filter_extra_fields = False
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
336 rhodecode_title = UnicodeString(strip=True, min=1, not_empty=True)
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
337 rhodecode_realm = UnicodeString(strip=True, min=1, not_empty=True)
350
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 347
diff changeset
338
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 347
diff changeset
339 return _ApplicationSettingsForm
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 347
diff changeset
340
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
341 def ApplicationUiSettingsForm():
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
342 class _ApplicationUiSettingsForm(formencode.Schema):
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
343 allow_extra_fields = True
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
344 filter_extra_fields = False
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
345 web_push_ssl = OneOf(['true', 'false'], if_missing='false')
527
6d44d3862ec4 fixes #36, removed username, name, lastname, minimal length restrictions,
Marcin Kuzminski <marcin@python-works.com>
parents: 490
diff changeset
346 paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=1, not_empty=True))
395
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 388
diff changeset
347 hooks_changegroup_update = OneOf(['True', 'False'], if_missing=False)
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 388
diff changeset
348 hooks_changegroup_repo_size = OneOf(['True', 'False'], if_missing=False)
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
349
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
350 return _ApplicationUiSettingsForm
320
05b212954275 Implemented owner settings, as separete posibility to edit repositry by non administrative owner of repository
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
351
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 416
diff changeset
352 def DefaultPermissionsForm(perms_choices, register_choices, create_choices):
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 416
diff changeset
353 class _DefaultPermissionsForm(formencode.Schema):
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 416
diff changeset
354 allow_extra_fields = True
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 416
diff changeset
355 filter_extra_fields = True
418
63c697d1a631 added logic for changin defualt permissions, and option to overwrite all defualt permissions on each repository
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
356 overwrite_default = OneOf(['true', 'false'], if_missing='false')
417
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 416
diff changeset
357 default_perm = OneOf(perms_choices)
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 416
diff changeset
358 default_register = OneOf(register_choices)
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 416
diff changeset
359 default_create = OneOf(create_choices)
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 416
diff changeset
360
3ed2d46a2ca7 permission refactoring,
Marcin Kuzminski <marcin@python-works.com>
parents: 416
diff changeset
361 return _DefaultPermissionsForm