mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +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:
parent
5b4db1277f
commit
b7cbc56f8a
@ -1,6 +1,10 @@
|
||||
# Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [Unreleased]
|
||||
### Fixed
|
||||
- users: Fixed checking restricted usernames.
|
||||
|
||||
## [0.10.0] - 2016-08-12
|
||||
### Added
|
||||
- Added Disks module to show free space of mounted partitions and
|
||||
@ -83,6 +87,7 @@ All notable changes to this project will be documented in this file.
|
||||
- Fixed issue that could allow someone to start a module setup process
|
||||
without being logged in to Plinth.
|
||||
|
||||
[Unreleased]: https://github.com/freedombox/Plinth/compare/v0.10.0...HEAD
|
||||
[0.10.0]: https://github.com/freedombox/Plinth/compare/v0.9.4...v0.10.0
|
||||
[0.9.4]: https://github.com/freedombox/Plinth/compare/v0.9.3...v0.9.4
|
||||
[0.9.3]: https://github.com/freedombox/Plinth/compare/v0.9.2...v0.9.3
|
||||
|
||||
@ -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."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user