Show More
@@ -246,11 +246,10 b' class RepoGroupsController(BaseControlle' | |||||
246 | repo_group=c.repo_group) |
|
246 | repo_group=c.repo_group) | |
247 |
|
247 | |||
248 | repo_group_form = RepoGroupForm( |
|
248 | repo_group_form = RepoGroupForm( | |
249 | edit=True, |
|
249 | edit=True, old_data=c.repo_group.get_dict(), | |
250 | old_data=c.repo_group.get_dict(), |
|
|||
251 | available_groups=c.repo_groups_choices, |
|
250 | available_groups=c.repo_groups_choices, | |
252 | can_create_in_root=can_create_in_root, |
|
251 | can_create_in_root=can_create_in_root, allow_disabled=True)() | |
253 | )() |
|
252 | ||
254 | try: |
|
253 | try: | |
255 | form_result = repo_group_form.to_python(dict(request.POST)) |
|
254 | form_result = repo_group_form.to_python(dict(request.POST)) | |
256 | gr_name = form_result['group_name'] |
|
255 | gr_name = form_result['group_name'] |
@@ -307,9 +307,9 b' class ReposController(BaseRepoController' | |||||
307 | 'repo_group': repo.group.get_dict() if repo.group else {}, |
|
307 | 'repo_group': repo.group.get_dict() if repo.group else {}, | |
308 | 'repo_type': repo.repo_type, |
|
308 | 'repo_type': repo.repo_type, | |
309 | } |
|
309 | } | |
310 |
_form = RepoForm( |
|
310 | _form = RepoForm( | |
311 |
|
|
311 | edit=True, old_data=old_data, repo_groups=c.repo_groups_choices, | |
312 |
|
|
312 | landing_revs=c.landing_revs_choices, allow_disabled=True)() | |
313 |
|
313 | |||
314 | try: |
|
314 | try: | |
315 | form_result = _form.to_python(dict(request.POST)) |
|
315 | form_result = _form.to_python(dict(request.POST)) |
@@ -209,9 +209,9 b' class UserGroupsController(BaseControlle' | |||||
209 |
|
209 | |||
210 | available_members = [safe_unicode(x[0]) for x in c.available_members] |
|
210 | available_members = [safe_unicode(x[0]) for x in c.available_members] | |
211 |
|
211 | |||
212 |
users_group_form = UserGroupForm( |
|
212 | users_group_form = UserGroupForm( | |
213 |
|
|
213 | edit=True, old_data=c.user_group.get_dict(), | |
214 |
|
|
214 | available_members=available_members, allow_disabled=True)() | |
215 |
|
215 | |||
216 | try: |
|
216 | try: | |
217 | form_result = users_group_form.to_python(request.POST) |
|
217 | form_result = users_group_form.to_python(request.POST) |
@@ -138,7 +138,11 b' def UserForm(edit=False, available_langu' | |||||
138 | return _UserForm |
|
138 | return _UserForm | |
139 |
|
139 | |||
140 |
|
140 | |||
141 |
def UserGroupForm(edit=False, old_data= |
|
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 | class _UserGroupForm(formencode.Schema): |
|
146 | class _UserGroupForm(formencode.Schema): | |
143 | allow_extra_fields = True |
|
147 | allow_extra_fields = True | |
144 | filter_extra_fields = True |
|
148 | filter_extra_fields = True | |
@@ -157,14 +161,18 b' def UserGroupForm(edit=False, old_data={' | |||||
157 | available_members, hideList=False, testValueList=True, |
|
161 | available_members, hideList=False, testValueList=True, | |
158 | if_missing=None, not_empty=False |
|
162 | if_missing=None, not_empty=False | |
159 | ) |
|
163 | ) | |
160 | #this is user group owner |
|
164 | # this is user group owner | |
161 | user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser()) |
|
165 | user = All( | |
162 |
|
166 | v.UnicodeString(not_empty=True), | ||
|
167 | v.ValidRepoUser(allow_disabled)) | |||
163 | return _UserGroupForm |
|
168 | return _UserGroupForm | |
164 |
|
169 | |||
165 |
|
170 | |||
166 |
def RepoGroupForm(edit=False, old_data= |
|
171 | def RepoGroupForm(edit=False, old_data=None, available_groups=None, | |
167 | can_create_in_root=False): |
|
172 | can_create_in_root=False, allow_disabled=False): | |
|
173 | old_data = old_data or {} | |||
|
174 | available_groups = available_groups or [] | |||
|
175 | ||||
168 | class _RepoGroupForm(formencode.Schema): |
|
176 | class _RepoGroupForm(formencode.Schema): | |
169 | allow_extra_fields = True |
|
177 | allow_extra_fields = True | |
170 | filter_extra_fields = False |
|
178 | filter_extra_fields = False | |
@@ -178,11 +186,14 b' def RepoGroupForm(edit=False, old_data={' | |||||
178 | group_parent_id = v.OneOf(available_groups, hideList=False, |
|
186 | group_parent_id = v.OneOf(available_groups, hideList=False, | |
179 | testValueList=True, not_empty=True) |
|
187 | testValueList=True, not_empty=True) | |
180 | enable_locking = v.StringBoolean(if_missing=False) |
|
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 | if edit: |
|
192 | if edit: | |
184 | #this is repo group owner |
|
193 | # this is repo group owner | |
185 | user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser()) |
|
194 | user = All( | |
|
195 | v.UnicodeString(not_empty=True), | |||
|
196 | v.ValidRepoUser(allow_disabled)) | |||
186 |
|
197 | |||
187 | return _RepoGroupForm |
|
198 | return _RepoGroupForm | |
188 |
|
199 | |||
@@ -221,7 +232,8 b' def PasswordResetForm():' | |||||
221 | return _PasswordResetForm |
|
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 | old_data = old_data or {} |
|
237 | old_data = old_data or {} | |
226 | repo_groups = repo_groups or [] |
|
238 | repo_groups = repo_groups or [] | |
227 | landing_revs = landing_revs or [] |
|
239 | landing_revs = landing_revs or [] | |
@@ -248,7 +260,9 b' def RepoForm(edit=False, old_data=None, ' | |||||
248 |
|
260 | |||
249 | if edit: |
|
261 | if edit: | |
250 | # this is repo owner |
|
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 | clone_uri_change = v.UnicodeString( |
|
266 | clone_uri_change = v.UnicodeString( | |
253 | not_empty=False, if_missing=v.Missing) |
|
267 | not_empty=False, if_missing=v.Missing) | |
254 |
|
268 |
@@ -193,21 +193,26 b' def ValidRegex(msg=None):' | |||||
193 | return _validator |
|
193 | return _validator | |
194 |
|
194 | |||
195 |
|
195 | |||
196 | def ValidRepoUser(): |
|
196 | def ValidRepoUser(allow_disabled=False): | |
197 | class _validator(formencode.validators.FancyValidator): |
|
197 | class _validator(formencode.validators.FancyValidator): | |
198 | messages = { |
|
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 | def validate_python(self, value, state): |
|
203 | def validate_python(self, value, state): | |
203 | try: |
|
204 | try: | |
204 |
User.query().filter(User. |
|
205 | user = User.query().filter(User.username == value).one() | |
205 | .filter(User.username == value).one() |
|
|||
206 | except Exception: |
|
206 | except Exception: | |
207 | msg = M(self, 'invalid_username', state, username=value) |
|
207 | msg = M(self, 'invalid_username', state, username=value) | |
208 | raise formencode.Invalid( |
|
208 | raise formencode.Invalid( | |
209 | msg, value, state, error_dict={'username': msg} |
|
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 | return _validator |
|
217 | return _validator | |
213 |
|
218 |
General Comments 0
You need to be logged in to leave comments.
Login now