##// 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 38 from rhodecode.lib.exceptions import LdapImportError
39 39 from rhodecode.model.user import UserModel
40 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 42 from rhodecode import BACKENDS
43 43
44 44 log = logging.getLogger(__name__)
@@ -122,15 +122,20 b' def ValidReposGroup(edit, old_data):'
122 122 def validate_python(self, value, state):
123 123 #TODO WRITE VALIDATIONS
124 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 127 # slugify repo group just in case :)
128 128 slug = repo_name_slug(group_name)
129 129
130 130 # check for parent of self
131 if edit and old_data['group_id'] == group_parent_id:
132 e_dict = {'group_parent_id':_('Cannot assign this group '
133 'as parent')}
131 parent_of_self = lambda: (
132 old_data['group_id'] == int(group_parent_id)
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 139 raise formencode.Invalid('', value, state,
135 140 error_dict=e_dict)
136 141
@@ -140,12 +145,29 b' def ValidReposGroup(edit, old_data):'
140 145 old_data.get('group_id')).group_name
141 146
142 147 if old_gname != group_name or not edit:
143 # check filesystem
144 gr = Group.query().filter(Group.group_name == slug)\
145 .filter(Group.group_parent_id == group_parent_id).scalar()
148
149 # check group
150 gr = Group.query()\
151 .filter(Group.group_name == slug)\
152 .filter(Group.group_parent_id == group_parent_id)\
153 .scalar()
146 154
147 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 171 raise formencode.Invalid('', value, state,
150 172 error_dict=e_dict)
151 173
General Comments 0
You need to be logged in to leave comments. Login now