mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
users: Fix checking restricted usernames
When editing an existing user, error is being thrown due to restricted usernames check. This is due to the username matching existing username. Also: - Raise the validation error on the field instead of the entire form. - Send error code along with validation error message. - End the validation error message with a full stop for consistency.
This commit is contained in:
1 parent
5b4db1277f
commit
b7cbc56f8a
2 files changed
+12
-4
No files matched your search
@@ -52,12 +52,15 @@ GROUP_CHOICES = (
|
||||
|
||||
class ValidNewUsernameCheckMixin(object):
|
||||
"""Mixin to check if a username is valid for created new user."""
|
||||
def clean(self):
|
||||
def clean_username(self):
|
||||
"""Check for username collisions with system users."""
|
||||
if not self.is_valid_new_username():
|
||||
raise ValidationError(_('Username is taken or is reserved'))
|
||||
username = self.cleaned_data['username']
|
||||
if self.instance.username != username and \
|
||||
not self.is_valid_new_username():
|
||||
raise ValidationError(_('Username is taken or is reserved.'),
|
||||
code='invalid')
|
||||
|
||||
return super().clean()
|
||||
return username
|
||||
|
||||
def is_valid_new_username(self):
|
||||
"""Check for username collisions with system users."""
|
||||
|
||||
Reference in new issue
Block a user