##// END OF EJS Templates
repos, repo groups, user groups: allow to use disabled users in owner field....
marcink -
r224:c6a3436d default
parent child Browse files
Show More
@@ -246,11 +246,10 b' class RepoGroupsController(BaseControlle'
246 246 repo_group=c.repo_group)
247 247
248 248 repo_group_form = RepoGroupForm(
249 edit=True,
250 old_data=c.repo_group.get_dict(),
249 edit=True, old_data=c.repo_group.get_dict(),
251 250 available_groups=c.repo_groups_choices,
252 can_create_in_root=can_create_in_root,
253 )()
251 can_create_in_root=can_create_in_root, allow_disabled=True)()
252
254 253 try:
255 254 form_result = repo_group_form.to_python(dict(request.POST))
256 255 gr_name = form_result['group_name']
@@ -307,9 +307,9 b' class ReposController(BaseRepoController'
307 307 'repo_group': repo.group.get_dict() if repo.group else {},
308 308 'repo_type': repo.repo_type,
309 309 }
310 _form = RepoForm(edit=True, old_data=old_data,
311 repo_groups=c.repo_groups_choices,
312 landing_revs=c.landing_revs_choices)()
310 _form = RepoForm(
311 edit=True, old_data=old_data, repo_groups=c.repo_groups_choices,
312 landing_revs=c.landing_revs_choices, allow_disabled=True)()
313 313
314 314 try:
315 315 form_result = _form.to_python(dict(request.POST))
@@ -209,9 +209,9 b' class UserGroupsController(BaseControlle'
209 209
210 210 available_members = [safe_unicode(x[0]) for x in c.available_members]
211 211
212 users_group_form = UserGroupForm(edit=True,
213 old_data=c.user_group.get_dict(),
214 available_members=available_members)()
212 users_group_form = UserGroupForm(
213 edit=True, old_data=c.user_group.get_dict(),
214 available_members=available_members, allow_disabled=True)()
215 215
216 216 try:
217 217 form_result = users_group_form.to_python(request.POST)
@@ -138,7 +138,11 b' def UserForm(edit=False, available_langu'
138 138 return _UserForm
139 139
140 140
141 def UserGroupForm(edit=False, old_data={}, available_members=[]):
141 def UserGroupForm(edit=False, old_data=None, available_members=None,
142 allow_disabled=False):
143 old_data = old_data or {}
144 available_members = available_members or []
145
142 146 class _UserGroupForm(formencode.Schema):
143 147 allow_extra_fields = True
144 148 filter_extra_fields = True
@@ -157,14 +161,18 b' def UserGroupForm(edit=False, old_data={'
157 161 available_members, hideList=False, testValueList=True,
158 162 if_missing=None, not_empty=False
159 163 )
160 #this is user group owner
161 user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser())
162
164 # this is user group owner
165 user = All(
166 v.UnicodeString(not_empty=True),
167 v.ValidRepoUser(allow_disabled))
163 168 return _UserGroupForm
164 169
165 170
166 def RepoGroupForm(edit=False, old_data={}, available_groups=[],
167 can_create_in_root=False):
171 def RepoGroupForm(edit=False, old_data=None, available_groups=None,
172 can_create_in_root=False, allow_disabled=False):
173 old_data = old_data or {}
174 available_groups = available_groups or []
175
168 176 class _RepoGroupForm(formencode.Schema):
169 177 allow_extra_fields = True
170 178 filter_extra_fields = False
@@ -178,11 +186,14 b' def RepoGroupForm(edit=False, old_data={'
178 186 group_parent_id = v.OneOf(available_groups, hideList=False,
179 187 testValueList=True, not_empty=True)
180 188 enable_locking = v.StringBoolean(if_missing=False)
181 chained_validators = [v.ValidRepoGroup(edit, old_data, can_create_in_root)]
189 chained_validators = [
190 v.ValidRepoGroup(edit, old_data, can_create_in_root)]
182 191
183 192 if edit:
184 #this is repo group owner
185 user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser())
193 # this is repo group owner
194 user = All(
195 v.UnicodeString(not_empty=True),
196 v.ValidRepoUser(allow_disabled))
186 197
187 198 return _RepoGroupForm
188 199
@@ -221,7 +232,8 b' def PasswordResetForm():'
221 232 return _PasswordResetForm
222 233
223 234
224 def RepoForm(edit=False, old_data=None, repo_groups=None, landing_revs=None):
235 def RepoForm(edit=False, old_data=None, repo_groups=None, landing_revs=None,
236 allow_disabled=False):
225 237 old_data = old_data or {}
226 238 repo_groups = repo_groups or []
227 239 landing_revs = landing_revs or []
@@ -248,7 +260,9 b' def RepoForm(edit=False, old_data=None, '
248 260
249 261 if edit:
250 262 # this is repo owner
251 user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser())
263 user = All(
264 v.UnicodeString(not_empty=True),
265 v.ValidRepoUser(allow_disabled))
252 266 clone_uri_change = v.UnicodeString(
253 267 not_empty=False, if_missing=v.Missing)
254 268
@@ -193,21 +193,26 b' def ValidRegex(msg=None):'
193 193 return _validator
194 194
195 195
196 def ValidRepoUser():
196 def ValidRepoUser(allow_disabled=False):
197 197 class _validator(formencode.validators.FancyValidator):
198 198 messages = {
199 'invalid_username': _(u'Username %(username)s is not valid')
199 'invalid_username': _(u'Username %(username)s is not valid'),
200 'disabled_username': _(u'Username %(username)s is disabled')
200 201 }
201 202
202 203 def validate_python(self, value, state):
203 204 try:
204 User.query().filter(User.active == true())\
205 .filter(User.username == value).one()
205 user = User.query().filter(User.username == value).one()
206 206 except Exception:
207 207 msg = M(self, 'invalid_username', state, username=value)
208 208 raise formencode.Invalid(
209 209 msg, value, state, error_dict={'username': msg}
210 210 )
211 if user and (not allow_disabled and not user.active):
212 msg = M(self, 'disabled_username', state, username=value)
213 raise formencode.Invalid(
214 msg, value, state, error_dict={'username': msg}
215 )
211 216
212 217 return _validator
213 218
General Comments 0
You need to be logged in to leave comments. Login now