mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +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)) {
|
if (!strlen($new)) {
|
||||||
$errors[] = $this->newRequiredError(
|
$errors[] = $this->newInvalidError(
|
||||||
pht('New username is required.'), $xaction);
|
pht('New username is required.'),
|
||||||
|
$xaction);
|
||||||
} else if (!PhabricatorUser::validateUsername($new)) {
|
} else if (!PhabricatorUser::validateUsername($new)) {
|
||||||
$errors[] = $this->newInvalidError(
|
$errors[] = $this->newInvalidError(
|
||||||
PhabricatorUser::describeValidUsername(), $xaction);
|
PhabricatorUser::describeValidUsername(),
|
||||||
|
$xaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = id(new PhabricatorPeopleQuery())
|
$user = id(new PhabricatorPeopleQuery())
|
||||||
->setViewer(PhabricatorUser::getOmnipotentUser())
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
||||||
->withUsernames(array($new))
|
->withUsernames(array($new))
|
||||||
->executeOne();
|
->executeOne();
|
||||||
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
|
// 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(
|
$errors[] = $this->newInvalidError(
|
||||||
pht('Another user already has that username.'), $xaction);
|
pht(
|
||||||
|
'Another user already has the username "%s".',
|
||||||
|
$new),
|
||||||
|
$xaction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue