mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Allow username changes which modify letter case to go through as valid
Summary: Fixes T13446. Currently, the validation logic here rejects a rename like "alice" to "ALICE" (which changes only letter case) but this is a permissible rename. Allow collisions that collide with the same user to permit this rename. Also, fix an issue where an empty rename was treated improperly. Test Plan: - Renamed "alice" to "ALICE". - Before: username collision error. - After: clean rename. - Renamed "alice" to "orange" (an existing user). Got an error. - Renamed "alice" to "", "!@#$", etc (invalid usernames). Got sensible errors. Maniphest Tasks: T13446 Differential Revision: https://secure.phabricator.com/D20890
This commit is contained in:
parent
6bada7db4c
commit
f5f2a0bc56
1 changed files with 15 additions and 6 deletions
|
@ -71,21 +71,30 @@ final class PhabricatorUserUsernameTransaction
|
|||
}
|
||||
|
||||
if (!strlen($new)) {
|
||||
$errors[] = $this->newRequiredError(
|
||||
pht('New username is required.'), $xaction);
|
||||
$errors[] = $this->newInvalidError(
|
||||
pht('New username is required.'),
|
||||
$xaction);
|
||||
} else if (!PhabricatorUser::validateUsername($new)) {
|
||||
$errors[] = $this->newInvalidError(
|
||||
PhabricatorUser::describeValidUsername(), $xaction);
|
||||
PhabricatorUser::describeValidUsername(),
|
||||
$xaction);
|
||||
}
|
||||
|
||||
$user = id(new PhabricatorPeopleQuery())
|
||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||
->withUsernames(array($new))
|
||||
->executeOne();
|
||||
|
||||
if ($user) {
|
||||
$errors[] = $this->newInvalidError(
|
||||
pht('Another user already has that username.'), $xaction);
|
||||
// See T13446. We may be changing the letter case of a username, which
|
||||
// is a perfectly fine edit.
|
||||
$is_self = ($user->getPHID() === $object->getPHID());
|
||||
if (!$is_self) {
|
||||
$errors[] = $this->newInvalidError(
|
||||
pht(
|
||||
'Another user already has the username "%s".',
|
||||
$new),
|
||||
$xaction);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue