forms.py
694 lines
| 28.2 KiB
| text/x-python
|
PythonLexer
r547 | """ this is forms validation classes | |||
http://formencode.org/module-formencode.validators.html | ||||
for list off all availible validators | ||||
we can create our own validators | ||||
The table below outlines the options which can be used in a schema in addition to the validators themselves | ||||
pre_validators [] These validators will be applied before the schema | ||||
chained_validators [] These validators will be applied after the schema | ||||
allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present | ||||
filter_extra_fields False If True, then keys that aren't associated with a validator are removed | ||||
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. | ||||
r1203 | 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 | |||
r547 | <name> = formencode.validators.<name of validator> | |||
<name> must equal form name | ||||
list=[1,2,3,4,5] | ||||
for SELECT use formencode.All(OneOf(list), Int()) | ||||
r1203 | ||||
r547 | """ | |||
r761 | import os | |||
import re | ||||
import logging | ||||
r1298 | import traceback | |||
r761 | ||||
import formencode | ||||
r547 | from formencode import All | |||
from formencode.validators import UnicodeString, OneOf, Int, Number, Regex, \ | ||||
r972 | Email, Bool, StringBoolean, Set | |||
r761 | ||||
r547 | from pylons.i18n.translation import _ | |||
r1022 | from webhelpers.pylonslib.secure_form import authentication_token | |||
r761 | ||||
r1533 | from rhodecode.config.routing import ADMIN_PREFIX | |||
r1022 | from rhodecode.lib.utils import repo_name_slug | |||
r761 | from rhodecode.lib.auth import authenticate, get_crypt_password | |||
r705 | from rhodecode.lib.exceptions import LdapImportError | |||
r629 | from rhodecode.model.user import UserModel | |||
from rhodecode.model.repo import RepoModel | ||||
r1323 | from rhodecode.model.db import User, UsersGroup, Group | |||
r761 | from rhodecode import BACKENDS | |||
r547 | log = logging.getLogger(__name__) | |||
#this is needed to translate the messages using _() in validators | ||||
class State_obj(object): | ||||
_ = staticmethod(_) | ||||
r629 | ||||
r1271 | #============================================================================== | |||
r547 | # VALIDATORS | |||
r1271 | #============================================================================== | |||
r547 | class ValidAuthToken(formencode.validators.FancyValidator): | |||
messages = {'invalid_token':_('Token mismatch')} | ||||
def validate_python(self, value, state): | ||||
if value != authentication_token(): | ||||
raise formencode.Invalid(self.message('invalid_token', state, | ||||
search_number=value), value, state) | ||||
r629 | ||||
def ValidUsername(edit, old_data): | ||||
r547 | class _ValidUsername(formencode.validators.FancyValidator): | |||
r629 | ||||
r547 | def validate_python(self, value, state): | |||
if value in ['default', 'new_user']: | ||||
raise formencode.Invalid(_('Invalid username'), value, state) | ||||
r629 | #check if user is unique | |||
r547 | old_un = None | |||
if edit: | ||||
r629 | old_un = UserModel().get(old_data.get('user_id')).username | |||
if old_un != value or not edit: | ||||
r1530 | if User.get_by_username(value, case_insensitive=True): | |||
r1271 | raise formencode.Invalid(_('This username already ' | |||
'exists') , value, state) | ||||
r745 | ||||
r960 | if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+$', value) is None: | |||
r743 | raise formencode.Invalid(_('Username may only contain ' | |||
r1271 | 'alphanumeric characters ' | |||
'underscores, periods or dashes ' | ||||
'and must begin with alphanumeric ' | ||||
'character'), value, state) | ||||
r745 | ||||
r629 | return _ValidUsername | |||
r959 | ||||
def ValidUsersGroup(edit, old_data): | ||||
class _ValidUsersGroup(formencode.validators.FancyValidator): | ||||
def validate_python(self, value, state): | ||||
if value in ['default']: | ||||
raise formencode.Invalid(_('Invalid group name'), value, state) | ||||
#check if group is unique | ||||
r972 | old_ugname = None | |||
r959 | if edit: | |||
r1271 | old_ugname = UsersGroup.get( | |||
old_data.get('users_group_id')).users_group_name | ||||
r959 | ||||
r972 | if old_ugname != value or not edit: | |||
r1271 | if UsersGroup.get_by_group_name(value, cache=False, | |||
r959 | case_insensitive=True): | |||
r1271 | raise formencode.Invalid(_('This users group ' | |||
'already exists') , value, | ||||
state) | ||||
r959 | ||||
if re.match(r'^[a-zA-Z0-9]{1}[a-zA-Z0-9\-\_\.]+$', value) is None: | ||||
raise formencode.Invalid(_('Group name may only contain ' | ||||
r1271 | 'alphanumeric characters ' | |||
'underscores, periods or dashes ' | ||||
'and must begin with alphanumeric ' | ||||
'character'), value, state) | ||||
r959 | ||||
return _ValidUsersGroup | ||||
r1345 | def ValidReposGroup(edit, old_data): | |||
class _ValidReposGroup(formencode.validators.FancyValidator): | ||||
def validate_python(self, value, state): | ||||
#TODO WRITE VALIDATIONS | ||||
r1347 | group_name = value.get('group_name') | |||
r1539 | group_parent_id = int(value.get('group_parent_id') or -1) | |||
r1345 | ||||
# slugify repo group just in case :) | ||||
slug = repo_name_slug(group_name) | ||||
r1349 | # check for parent of self | |||
r1363 | if edit and old_data['group_id'] == group_parent_id: | |||
r1349 | e_dict = {'group_parent_id':_('Cannot assign this group ' | |||
'as parent')} | ||||
raise formencode.Invalid('', value, state, | ||||
error_dict=e_dict) | ||||
r1347 | old_gname = None | |||
if edit: | ||||
old_gname = Group.get( | ||||
old_data.get('group_id')).group_name | ||||
r1345 | ||||
r1347 | if old_gname != group_name or not edit: | |||
# check filesystem | ||||
gr = Group.query().filter(Group.group_name == slug)\ | ||||
.filter(Group.group_parent_id == group_parent_id).scalar() | ||||
if gr: | ||||
e_dict = {'group_name':_('This group already exists')} | ||||
raise formencode.Invalid('', value, state, | ||||
error_dict=e_dict) | ||||
r1345 | return _ValidReposGroup | |||
r959 | ||||
r547 | class ValidPassword(formencode.validators.FancyValidator): | |||
r629 | ||||
r547 | def to_python(self, value, state): | |||
r722 | ||||
r547 | if value: | |||
r722 | ||||
if value.get('password'): | ||||
try: | ||||
value['password'] = get_crypt_password(value['password']) | ||||
except UnicodeEncodeError: | ||||
e_dict = {'password':_('Invalid characters in password')} | ||||
raise formencode.Invalid('', value, state, error_dict=e_dict) | ||||
if value.get('password_confirmation'): | ||||
try: | ||||
value['password_confirmation'] = \ | ||||
get_crypt_password(value['password_confirmation']) | ||||
except UnicodeEncodeError: | ||||
e_dict = {'password_confirmation':_('Invalid characters in password')} | ||||
raise formencode.Invalid('', value, state, error_dict=e_dict) | ||||
r728 | if value.get('new_password'): | |||
try: | ||||
value['new_password'] = \ | ||||
get_crypt_password(value['new_password']) | ||||
except UnicodeEncodeError: | ||||
e_dict = {'new_password':_('Invalid characters in password')} | ||||
raise formencode.Invalid('', value, state, error_dict=e_dict) | ||||
r722 | return value | |||
class ValidPasswordsMatch(formencode.validators.FancyValidator): | ||||
def validate_python(self, value, state): | ||||
r1597 | ||||
pass_val = value.get('password') or value.get('new_password') | ||||
if pass_val != value['password_confirmation']: | ||||
r722 | e_dict = {'password_confirmation': | |||
Augusto Herrmann
|
r1472 | _('Passwords do not match')} | ||
r722 | raise formencode.Invalid('', value, state, error_dict=e_dict) | |||
r629 | ||||
r547 | class ValidAuth(formencode.validators.FancyValidator): | |||
messages = { | ||||
r1594 | 'invalid_password':_('invalid password'), | |||
'invalid_login':_('invalid user name'), | ||||
'disabled_account':_('Your account is disabled') | ||||
} | ||||
# error mapping | ||||
r547 | e_dict = {'username':messages['invalid_login'], | |||
'password':messages['invalid_password']} | ||||
e_dict_disable = {'username':messages['disabled_account']} | ||||
r629 | ||||
r547 | def validate_python(self, value, state): | |||
password = value['password'] | ||||
username = value['username'] | ||||
r1530 | user = User.get_by_username(username) | |||
r699 | ||||
r761 | if authenticate(username, password): | |||
r699 | return value | |||
else: | ||||
if user and user.active is False: | ||||
r547 | log.warning('user %s is disabled', username) | |||
raise formencode.Invalid(self.message('disabled_account', | ||||
state=State_obj), | ||||
value, state, | ||||
error_dict=self.e_dict_disable) | ||||
r699 | else: | |||
log.warning('user %s not authenticated', username) | ||||
raise formencode.Invalid(self.message('invalid_password', | ||||
state=State_obj), value, state, | ||||
error_dict=self.e_dict) | ||||
r629 | ||||
r547 | class ValidRepoUser(formencode.validators.FancyValidator): | |||
r629 | ||||
r547 | def to_python(self, value, state): | |||
try: | ||||
r1361 | User.query().filter(User.active == True)\ | |||
r547 | .filter(User.username == value).one() | |||
except Exception: | ||||
raise formencode.Invalid(_('This username is not valid'), | ||||
value, state) | ||||
r1323 | return value | |||
r547 | ||||
r629 | def ValidRepoName(edit, old_data): | |||
r547 | class _ValidRepoName(formencode.validators.FancyValidator): | |||
r1323 | def to_python(self, value, state): | |||
r629 | ||||
r1323 | repo_name = value.get('repo_name') | |||
slug = repo_name_slug(repo_name) | ||||
r1533 | if slug in [ADMIN_PREFIX, '']: | |||
r1323 | e_dict = {'repo_name': _('This repository name is disallowed')} | |||
raise formencode.Invalid('', value, state, error_dict=e_dict) | ||||
r1324 | if value.get('repo_group'): | |||
gr = Group.get(value.get('repo_group')) | ||||
group_path = gr.full_path | ||||
r1346 | # value needs to be aware of group name in order to check | |||
r1550 | # db key This is an actual just the name to store in the | |||
r1361 | # database | |||
r1346 | repo_name_full = group_path + Group.url_sep() + repo_name | |||
r1594 | ||||
r1324 | else: | |||
group_path = '' | ||||
repo_name_full = repo_name | ||||
r1323 | value['repo_name_full'] = repo_name_full | |||
r1550 | rename = old_data.get('repo_name') != repo_name_full | |||
create = not edit | ||||
if rename or create: | ||||
r1323 | ||||
r1324 | if group_path != '': | |||
r1323 | if RepoModel().get_by_repo_name(repo_name_full,): | |||
e_dict = {'repo_name':_('This repository already ' | ||||
r1550 | 'exists in a group "%s"') % | |||
r1323 | gr.group_name} | |||
raise formencode.Invalid('', value, state, | ||||
error_dict=e_dict) | ||||
r1550 | elif Group.get_by_group_name(repo_name_full): | |||
e_dict = {'repo_name':_('There is a group with this' | ||||
' name already "%s"') % | ||||
repo_name_full} | ||||
raise formencode.Invalid('', value, state, | ||||
error_dict=e_dict) | ||||
r1323 | ||||
r1550 | elif RepoModel().get_by_repo_name(repo_name_full): | |||
r1324 | e_dict = {'repo_name':_('This repository ' | |||
'already exists')} | ||||
r1323 | raise formencode.Invalid('', value, state, | |||
error_dict=e_dict) | ||||
r1550 | ||||
r1323 | return value | |||
r629 | ||||
r547 | return _ValidRepoName | |||
r1366 | def ValidForkName(): | |||
class _ValidForkName(formencode.validators.FancyValidator): | ||||
def to_python(self, value, state): | ||||
r1514 | ||||
repo_name = value.get('fork_name') | ||||
slug = repo_name_slug(repo_name) | ||||
r1533 | if slug in [ADMIN_PREFIX, '']: | |||
r1514 | e_dict = {'repo_name': _('This repository name is disallowed')} | |||
raise formencode.Invalid('', value, state, error_dict=e_dict) | ||||
if RepoModel().get_by_repo_name(repo_name): | ||||
e_dict = {'fork_name':_('This repository ' | ||||
'already exists')} | ||||
raise formencode.Invalid('', value, state, | ||||
error_dict=e_dict) | ||||
r1366 | return value | |||
return _ValidForkName | ||||
r1345 | def SlugifyName(): | |||
class _SlugifyName(formencode.validators.FancyValidator): | ||||
r1323 | ||||
def to_python(self, value, state): | ||||
return repo_name_slug(value) | ||||
r1345 | return _SlugifyName | |||
r1323 | ||||
r1261 | def ValidCloneUri(): | |||
from mercurial.httprepo import httprepository, httpsrepository | ||||
from rhodecode.lib.utils import make_ui | ||||
class _ValidCloneUri(formencode.validators.FancyValidator): | ||||
r1298 | ||||
r1261 | def to_python(self, value, state): | |||
if not value: | ||||
pass | ||||
elif value.startswith('https'): | ||||
try: | ||||
r1298 | httpsrepository(make_ui('db'), value).capabilities | |||
except Exception, e: | ||||
log.error(traceback.format_exc()) | ||||
r1261 | raise formencode.Invalid(_('invalid clone url'), value, | |||
state) | ||||
elif value.startswith('http'): | ||||
try: | ||||
r1298 | httprepository(make_ui('db'), value).capabilities | |||
except Exception, e: | ||||
log.error(traceback.format_exc()) | ||||
r1261 | raise formencode.Invalid(_('invalid clone url'), value, | |||
state) | ||||
else: | ||||
raise formencode.Invalid(_('Invalid clone url, provide a ' | ||||
'valid clone http\s url'), value, | ||||
state) | ||||
r1298 | return value | |||
r1261 | ||||
return _ValidCloneUri | ||||
r659 | def ValidForkType(old_data): | |||
class _ValidForkType(formencode.validators.FancyValidator): | ||||
def to_python(self, value, state): | ||||
if old_data['repo_type'] != value: | ||||
r1261 | raise formencode.Invalid(_('Fork have to be the same ' | |||
'type as original'), value, state) | ||||
r1366 | ||||
r659 | return value | |||
return _ValidForkType | ||||
r547 | class ValidPerms(formencode.validators.FancyValidator): | |||
r1013 | messages = {'perm_new_member_name':_('This username or users group name' | |||
' is not valid')} | ||||
r629 | ||||
r547 | def to_python(self, value, state): | |||
perms_update = [] | ||||
perms_new = [] | ||||
#build a list of permission to update and new permission to create | ||||
for k, v in value.items(): | ||||
r1015 | #means new added member to permissions | |||
if k.startswith('perm_new_member'): | ||||
new_perm = value.get('perm_new_member', False) | ||||
new_member = value.get('perm_new_member_name', False) | ||||
new_type = value.get('perm_new_member_type') | ||||
r1013 | ||||
r1015 | if new_member and new_perm: | |||
if (new_member, new_perm, new_type) not in perms_new: | ||||
perms_new.append((new_member, new_perm, new_type)) | ||||
elif k.startswith('u_perm_') or k.startswith('g_perm_'): | ||||
member = k[7:] | ||||
t = {'u':'user', | ||||
'g':'users_group'}[k[0]] | ||||
if member == 'default': | ||||
if value['private']: | ||||
#set none for default when updating to private repo | ||||
v = 'repository.none' | ||||
perms_update.append((member, v, t)) | ||||
r547 | value['perms_updates'] = perms_update | |||
value['perms_new'] = perms_new | ||||
r1014 | ||||
#update permissions | ||||
r1013 | for k, v, t in perms_new: | |||
r547 | try: | |||
r1013 | if t is 'user': | |||
r1345 | self.user_db = User.query()\ | |||
r1013 | .filter(User.active == True)\ | |||
.filter(User.username == k).one() | ||||
if t is 'users_group': | ||||
r1345 | self.user_db = UsersGroup.query()\ | |||
r1013 | .filter(UsersGroup.users_group_active == True)\ | |||
.filter(UsersGroup.users_group_name == k).one() | ||||
r547 | except Exception: | |||
r1013 | msg = self.message('perm_new_member_name', | |||
r547 | state=State_obj) | |||
r742 | raise formencode.Invalid(msg, value, state, | |||
r1013 | error_dict={'perm_new_member_name':msg}) | |||
r547 | return value | |||
r629 | ||||
r547 | class ValidSettings(formencode.validators.FancyValidator): | |||
r629 | ||||
r547 | def to_python(self, value, state): | |||
#settings form can't edit user | ||||
if value.has_key('user'): | ||||
del['value']['user'] | ||||
r629 | ||||
r547 | return value | |||
r629 | ||||
r547 | class ValidPath(formencode.validators.FancyValidator): | |||
def to_python(self, value, state): | ||||
r631 | ||||
if not os.path.isdir(value): | ||||
r629 | msg = _('This is not a valid path') | |||
r631 | raise formencode.Invalid(msg, value, state, | |||
r629 | error_dict={'paths_root_path':msg}) | |||
r631 | return value | |||
r547 | ||||
def UniqSystemEmail(old_data): | ||||
class _UniqSystemEmail(formencode.validators.FancyValidator): | ||||
def to_python(self, value, state): | ||||
r741 | value = value.lower() | |||
r547 | if old_data.get('email') != value: | |||
r1345 | user = User.query().filter(User.email == value).scalar() | |||
if user: | ||||
raise formencode.Invalid( | ||||
_("This e-mail address is already taken"), | ||||
value, state) | ||||
r547 | return value | |||
r629 | ||||
r547 | return _UniqSystemEmail | |||
r629 | ||||
r547 | class ValidSystemEmail(formencode.validators.FancyValidator): | |||
def to_python(self, value, state): | ||||
r741 | value = value.lower() | |||
r1345 | user = User.query().filter(User.email == value).scalar() | |||
if user is None: | ||||
raise formencode.Invalid(_("This e-mail address doesn't exist.") , | ||||
value, state) | ||||
r629 | ||||
return value | ||||
r547 | ||||
r705 | class LdapLibValidator(formencode.validators.FancyValidator): | |||
def to_python(self, value, state): | ||||
try: | ||||
import ldap | ||||
except ImportError: | ||||
raise LdapImportError | ||||
return value | ||||
Thayne Harbaugh
|
r991 | class AttrLoginValidator(formencode.validators.FancyValidator): | ||
r775 | ||||
def to_python(self, value, state): | ||||
Thayne Harbaugh
|
r991 | if not value or not isinstance(value, (str, unicode)): | ||
r1015 | raise formencode.Invalid(_("The LDAP Login attribute of the CN " | |||
"must be specified - this is the name " | ||||
"of the attribute that is equivalent " | ||||
"to 'username'"), | ||||
Thayne Harbaugh
|
r991 | value, state) | ||
r775 | ||||
return value | ||||
r547 | #=============================================================================== | |||
r1203 | # FORMS | |||
r547 | #=============================================================================== | |||
class LoginForm(formencode.Schema): | ||||
allow_extra_fields = True | ||||
filter_extra_fields = True | ||||
username = UnicodeString( | ||||
strip=True, | ||||
min=1, | ||||
not_empty=True, | ||||
messages={ | ||||
r1357 | 'empty':_('Please enter a login'), | |||
'tooShort':_('Enter a value %(min)i characters long or more')} | ||||
r547 | ) | |||
password = UnicodeString( | ||||
strip=True, | ||||
r1357 | min=3, | |||
r547 | not_empty=True, | |||
messages={ | ||||
r1357 | 'empty':_('Please enter a password'), | |||
'tooShort':_('Enter %(min)i characters or more')} | ||||
r547 | ) | |||
chained_validators = [ValidAuth] | ||||
r629 | ||||
r547 | def UserForm(edit=False, old_data={}): | |||
class _UserForm(formencode.Schema): | ||||
allow_extra_fields = True | ||||
filter_extra_fields = True | ||||
r742 | username = All(UnicodeString(strip=True, min=1, not_empty=True), | |||
ValidUsername(edit, old_data)) | ||||
r547 | if edit: | |||
r722 | new_password = All(UnicodeString(strip=True, min=6, not_empty=False)) | |||
r1597 | password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=False)) | |||
r547 | admin = StringBoolean(if_missing=False) | |||
else: | ||||
r722 | password = All(UnicodeString(strip=True, min=6, not_empty=True)) | |||
r1597 | password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=False)) | |||
r547 | active = StringBoolean(if_missing=False) | |||
name = UnicodeString(strip=True, min=1, not_empty=True) | ||||
lastname = UnicodeString(strip=True, min=1, not_empty=True) | ||||
email = All(Email(not_empty=True), UniqSystemEmail(old_data)) | ||||
r629 | ||||
r1597 | chained_validators = [ValidPasswordsMatch, ValidPassword] | |||
r722 | ||||
r547 | return _UserForm | |||
r959 | ||||
r972 | def UsersGroupForm(edit=False, old_data={}, available_members=[]): | |||
r959 | class _UsersGroupForm(formencode.Schema): | |||
allow_extra_fields = True | ||||
filter_extra_fields = True | ||||
users_group_name = All(UnicodeString(strip=True, min=1, not_empty=True), | ||||
ValidUsersGroup(edit, old_data)) | ||||
users_group_active = StringBoolean(if_missing=False) | ||||
r972 | if edit: | |||
users_group_members = OneOf(available_members, hideList=False, | ||||
testValueList=True, | ||||
if_missing=None, not_empty=False) | ||||
r959 | return _UsersGroupForm | |||
r1345 | def ReposGroupForm(edit=False, old_data={}, available_groups=[]): | |||
class _ReposGroupForm(formencode.Schema): | ||||
allow_extra_fields = True | ||||
filter_extra_fields = True | ||||
r1347 | group_name = All(UnicodeString(strip=True, min=1, not_empty=True), | |||
r1345 | SlugifyName()) | |||
r1347 | group_description = UnicodeString(strip=True, min=1, | |||
r1345 | not_empty=True) | |||
r1347 | group_parent_id = OneOf(available_groups, hideList=False, | |||
r1345 | testValueList=True, | |||
if_missing=None, not_empty=False) | ||||
chained_validators = [ValidReposGroup(edit, old_data)] | ||||
return _ReposGroupForm | ||||
r722 | def RegisterForm(edit=False, old_data={}): | |||
class _RegisterForm(formencode.Schema): | ||||
allow_extra_fields = True | ||||
filter_extra_fields = True | ||||
r742 | username = All(ValidUsername(edit, old_data), | |||
UnicodeString(strip=True, min=1, not_empty=True)) | ||||
r722 | password = All(UnicodeString(strip=True, min=6, not_empty=True)) | |||
password_confirmation = All(UnicodeString(strip=True, min=6, not_empty=True)) | ||||
active = StringBoolean(if_missing=False) | ||||
name = UnicodeString(strip=True, min=1, not_empty=True) | ||||
lastname = UnicodeString(strip=True, min=1, not_empty=True) | ||||
email = All(Email(not_empty=True), UniqSystemEmail(old_data)) | ||||
chained_validators = [ValidPasswordsMatch, ValidPassword] | ||||
return _RegisterForm | ||||
r547 | ||||
def PasswordResetForm(): | ||||
class _PasswordResetForm(formencode.Schema): | ||||
allow_extra_fields = True | ||||
filter_extra_fields = True | ||||
r629 | email = All(ValidSystemEmail(), Email(not_empty=True)) | |||
r547 | return _PasswordResetForm | |||
r1112 | def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(), | |||
repo_groups=[]): | ||||
r547 | class _RepoForm(formencode.Schema): | |||
allow_extra_fields = True | ||||
filter_extra_fields = False | ||||
r742 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), | |||
r1345 | SlugifyName()) | |||
r1261 | clone_uri = All(UnicodeString(strip=True, min=1, not_empty=False), | |||
ValidCloneUri()()) | ||||
r1159 | repo_group = OneOf(repo_groups, hideList=True) | |||
r1112 | repo_type = OneOf(supported_backends) | |||
r547 | description = UnicodeString(strip=True, min=1, not_empty=True) | |||
private = StringBoolean(if_missing=False) | ||||
r810 | enable_statistics = StringBoolean(if_missing=False) | |||
r962 | enable_downloads = StringBoolean(if_missing=False) | |||
r1112 | ||||
r547 | if edit: | |||
r1014 | #this is repo owner | |||
r1323 | user = All(UnicodeString(not_empty=True), ValidRepoUser) | |||
r629 | ||||
r1323 | chained_validators = [ValidRepoName(edit, old_data), ValidPerms] | |||
r547 | return _RepoForm | |||
r710 | def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys()): | |||
r547 | class _RepoForkForm(formencode.Schema): | |||
allow_extra_fields = True | ||||
filter_extra_fields = False | ||||
r742 | fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), | |||
r1345 | SlugifyName()) | |||
r547 | description = UnicodeString(strip=True, min=1, not_empty=True) | |||
private = StringBoolean(if_missing=False) | ||||
r710 | repo_type = All(ValidForkType(old_data), OneOf(supported_backends)) | |||
r1366 | ||||
chained_validators = [ValidForkName()] | ||||
r547 | return _RepoForkForm | |||
r1594 | def RepoSettingsForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(), | |||
repo_groups=[]): | ||||
r547 | class _RepoForm(formencode.Schema): | |||
allow_extra_fields = True | ||||
filter_extra_fields = False | ||||
r742 | repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), | |||
r1345 | SlugifyName()) | |||
r547 | description = UnicodeString(strip=True, min=1, not_empty=True) | |||
r1594 | repo_group = OneOf(repo_groups, hideList=True) | |||
r547 | private = StringBoolean(if_missing=False) | |||
r629 | ||||
r1594 | chained_validators = [ValidRepoName(edit, old_data), ValidPerms, | |||
ValidSettings] | ||||
r547 | return _RepoForm | |||
def ApplicationSettingsForm(): | ||||
class _ApplicationSettingsForm(formencode.Schema): | ||||
allow_extra_fields = True | ||||
filter_extra_fields = False | ||||
r548 | rhodecode_title = UnicodeString(strip=True, min=1, not_empty=True) | |||
rhodecode_realm = UnicodeString(strip=True, min=1, not_empty=True) | ||||
r891 | rhodecode_ga_code = UnicodeString(strip=True, min=1, not_empty=False) | |||
r629 | ||||
r547 | return _ApplicationSettingsForm | |||
r629 | ||||
r547 | def ApplicationUiSettingsForm(): | |||
class _ApplicationUiSettingsForm(formencode.Schema): | ||||
allow_extra_fields = True | ||||
filter_extra_fields = False | ||||
web_push_ssl = OneOf(['true', 'false'], if_missing='false') | ||||
paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=1, not_empty=True)) | ||||
hooks_changegroup_update = OneOf(['True', 'False'], if_missing=False) | ||||
hooks_changegroup_repo_size = OneOf(['True', 'False'], if_missing=False) | ||||
r661 | hooks_pretxnchangegroup_push_logger = OneOf(['True', 'False'], if_missing=False) | |||
hooks_preoutgoing_pull_logger = OneOf(['True', 'False'], if_missing=False) | ||||
r629 | ||||
r547 | return _ApplicationUiSettingsForm | |||
def DefaultPermissionsForm(perms_choices, register_choices, create_choices): | ||||
class _DefaultPermissionsForm(formencode.Schema): | ||||
allow_extra_fields = True | ||||
filter_extra_fields = True | ||||
r705 | overwrite_default = StringBoolean(if_missing=False) | |||
r673 | anonymous = OneOf(['True', 'False'], if_missing=False) | |||
r547 | default_perm = OneOf(perms_choices) | |||
default_register = OneOf(register_choices) | ||||
default_create = OneOf(create_choices) | ||||
r629 | ||||
r547 | return _DefaultPermissionsForm | |||
r705 | ||||
"Lorenzo M. Catucci"
|
r1290 | def LdapSettingsForm(tls_reqcert_choices, search_scope_choices, tls_kind_choices): | ||
r705 | class _LdapSettingsForm(formencode.Schema): | |||
allow_extra_fields = True | ||||
filter_extra_fields = True | ||||
pre_validators = [LdapLibValidator] | ||||
ldap_active = StringBoolean(if_missing=False) | ||||
ldap_host = UnicodeString(strip=True,) | ||||
ldap_port = Number(strip=True,) | ||||
"Lorenzo M. Catucci"
|
r1290 | ldap_tls_kind = OneOf(tls_kind_choices) | ||
Thayne Harbaugh
|
r991 | ldap_tls_reqcert = OneOf(tls_reqcert_choices) | ||
r705 | ldap_dn_user = UnicodeString(strip=True,) | |||
ldap_dn_pass = UnicodeString(strip=True,) | ||||
Thayne Harbaugh
|
r991 | ldap_base_dn = UnicodeString(strip=True,) | ||
ldap_filter = UnicodeString(strip=True,) | ||||
ldap_search_scope = OneOf(search_scope_choices) | ||||
ldap_attr_login = All(AttrLoginValidator, UnicodeString(strip=True,)) | ||||
ldap_attr_firstname = UnicodeString(strip=True,) | ||||
ldap_attr_lastname = UnicodeString(strip=True,) | ||||
ldap_attr_email = UnicodeString(strip=True,) | ||||
r705 | ||||
return _LdapSettingsForm | ||||