##// END OF EJS Templates
backported fix for #337
marcink -
r1899:0f463fa8 default
parent child Browse files
Show More
@@ -38,7 +38,7 b' from rhodecode.lib.auth import authentic'
38 from rhodecode.lib.exceptions import LdapImportError
38 from rhodecode.lib.exceptions import LdapImportError
39 from rhodecode.model.user import UserModel
39 from rhodecode.model.user import UserModel
40 from rhodecode.model.repo import RepoModel
40 from rhodecode.model.repo import RepoModel
41 from rhodecode.model.db import User, UsersGroup, Group
41 from rhodecode.model.db import User, UsersGroup, Group, Repository
42 from rhodecode import BACKENDS
42 from rhodecode import BACKENDS
43
43
44 log = logging.getLogger(__name__)
44 log = logging.getLogger(__name__)
@@ -122,15 +122,20 b' def ValidReposGroup(edit, old_data):'
122 def validate_python(self, value, state):
122 def validate_python(self, value, state):
123 #TODO WRITE VALIDATIONS
123 # TODO WRITE VALIDATIONS
124 group_name = value.get('group_name')
124 group_name = value.get('group_name')
125 group_parent_id = int(value.get('group_parent_id') or -1)
125 group_parent_id = value.get('group_parent_id')
126
126
127 # slugify repo group just in case :)
127 # slugify repo group just in case :)
128 slug = repo_name_slug(group_name)
128 slug = repo_name_slug(group_name)
129
129
130 # check for parent of self
130 # check for parent of self
131 if edit and old_data['group_id'] == group_parent_id:
131 parent_of_self = lambda: (
132 e_dict = {'group_parent_id':_('Cannot assign this group '
132 old_data['group_id'] == int(group_parent_id)
133 'as parent')}
133 if group_parent_id else False
134 )
135 if edit and parent_of_self():
136 e_dict = {
137 'group_parent_id': _('Cannot assign this group as parent')
138 }
134 raise formencode.Invalid('', value, state,
139 raise formencode.Invalid('', value, state,
135 error_dict=e_dict)
140 error_dict=e_dict)
136
141
@@ -140,12 +145,29 b' def ValidReposGroup(edit, old_data):'
140 old_data.get('group_id')).group_name
145 old_data.get('group_id')).group_name
141
146
142 if old_gname != group_name or not edit:
147 if old_gname != group_name or not edit:
143 # check filesystem
148
144 gr = Group.query().filter(Group.group_name == slug)\
149 # check group
145 .filter(Group.group_parent_id == group_parent_id).scalar()
150 gr = Group.query()\
151 .filter(Group.group_name == slug)\
152 .filter(Group.group_parent_id == group_parent_id)\
153 .scalar()
146
154
147 if gr:
155 if gr:
148 e_dict = {'group_name':_('This group already exists')}
156 e_dict = {
157 'group_name': _('This group already exists')
158 }
159 raise formencode.Invalid('', value, state,
160 error_dict=e_dict)
161
162 # check for same repo
163 repo = Repository.query()\
164 .filter(Repository.repo_name == slug)\
165 .scalar()
166
167 if repo:
168 e_dict = {
169 'group_name': _('Repository with this name already exists')
170 }
149 raise formencode.Invalid('', value, state,
171 raise formencode.Invalid('', value, state,
150 error_dict=e_dict)
172 error_dict=e_dict)
151
173
General Comments 0
You need to be logged in to leave comments. Login now