Differential D19887 Diff 47489 src/applications/people/controller/PhabricatorPeopleRenameController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/controller/PhabricatorPeopleRenameController.php
Show All 16 Lines | public function handleRequest(AphrontRequest $request) { | ||||
$done_uri = $this->getApplicationURI("manage/{$id}/"); | $done_uri = $this->getApplicationURI("manage/{$id}/"); | ||||
id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( | id(new PhabricatorAuthSessionEngine())->requireHighSecuritySession( | ||||
$viewer, | $viewer, | ||||
$request, | $request, | ||||
$done_uri); | $done_uri); | ||||
$errors = array(); | $validation_exception = null; | ||||
$username = $user->getUsername(); | |||||
$v_username = $user->getUsername(); | |||||
$e_username = true; | |||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$v_username = $request->getStr('username'); | $username = $request->getStr('username'); | ||||
$xactions = array(); | |||||
if (!strlen($v_username)) { | $xactions[] = id(new PhabricatorUserTransaction()) | ||||
$e_username = pht('Required'); | ->setTransactionType( | ||||
$errors[] = pht('New username is required.'); | PhabricatorUserUsernameTransaction::TRANSACTIONTYPE) | ||||
} else if ($v_username == $user->getUsername()) { | ->setNewValue($username); | ||||
$e_username = pht('Invalid'); | |||||
$errors[] = pht('New username must be different from old username.'); | |||||
} else if (!PhabricatorUser::validateUsername($v_username)) { | |||||
$e_username = pht('Invalid'); | |||||
$errors[] = PhabricatorUser::describeValidUsername(); | |||||
} | |||||
if (!$errors) { | $editor = id(new PhabricatorUserTransactionEditor()) | ||||
try { | |||||
id(new PhabricatorUserEditor()) | |||||
->setActor($viewer) | ->setActor($viewer) | ||||
->changeUsername($user, $v_username); | ->setContentSourceFromRequest($request) | ||||
->setContinueOnMissingFields(true); | |||||
try { | |||||
$editor->applyTransactions($user, $xactions); | |||||
return id(new AphrontRedirectResponse())->setURI($done_uri); | return id(new AphrontRedirectResponse())->setURI($done_uri); | ||||
} catch (AphrontDuplicateKeyQueryException $ex) { | } catch (PhabricatorApplicationTransactionValidationException $ex) { | ||||
$e_username = pht('Not Unique'); | $validation_exception = $ex; | ||||
$errors[] = pht('Another user already has that username.'); | |||||
} | |||||
} | } | ||||
} | } | ||||
$inst1 = pht( | $inst1 = pht( | ||||
'Be careful when renaming users!'); | 'Be careful when renaming users!'); | ||||
$inst2 = pht( | $inst2 = pht( | ||||
'The old username will no longer be tied to the user, so anything '. | 'The old username will no longer be tied to the user, so anything '. | ||||
'which uses it (like old commit messages) will no longer associate '. | 'which uses it (like old commit messages) will no longer associate '. | ||||
Show All 19 Lines | $form = id(new AphrontFormView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormStaticControl()) | id(new AphrontFormStaticControl()) | ||||
->setLabel(pht('Old Username')) | ->setLabel(pht('Old Username')) | ||||
->setValue($user->getUsername())) | ->setValue($user->getUsername())) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setLabel(pht('New Username')) | ->setLabel(pht('New Username')) | ||||
->setValue($v_username) | ->setValue($username) | ||||
->setName('username') | ->setName('username')); | ||||
epriestley: I think this does the wrong thing if you do this:
- Edit `alice`.
- Try to change her name… | |||||
->setError($e_username)); | |||||
if ($errors) { | |||||
$errors = id(new PHUIInfoView())->setErrors($errors); | |||||
} | |||||
return $this->newDialog() | return $this->newDialog() | ||||
->setWidth(AphrontDialogView::WIDTH_FORM) | ->setWidth(AphrontDialogView::WIDTH_FORM) | ||||
->setTitle(pht('Change Username')) | ->setTitle(pht('Change Username')) | ||||
->appendChild($errors) | ->setValidationException($validation_exception) | ||||
Done Inline ActionsThis just kinda worked, but I figured it out by looking around at similar callers, so let me know if this old/bad/etc. amckinley: This just kinda worked, but I figured it out by looking around at similar callers, so let me… | |||||
Not Done Inline ActionsThis is good / modern. It's sort of "less modern" than real EditEngine but we don't have a Grand Abstraction For All Weird Forms and I don't think there's one anywhere on the horizon. epriestley: This is good / modern. It's sort of "less modern" than real EditEngine but we don't have a… | |||||
->appendParagraph($inst1) | ->appendParagraph($inst1) | ||||
->appendParagraph($inst2) | ->appendParagraph($inst2) | ||||
->appendParagraph($inst3) | ->appendParagraph($inst3) | ||||
->appendParagraph($inst4) | ->appendParagraph($inst4) | ||||
->appendParagraph($inst5) | ->appendParagraph($inst5) | ||||
->appendParagraph(null) | ->appendParagraph(null) | ||||
->appendForm($form) | ->appendForm($form) | ||||
->addSubmitButton(pht('Rename User')) | ->addSubmitButton(pht('Rename User')) | ||||
->addCancelButton($done_uri); | ->addCancelButton($done_uri); | ||||
} | } | ||||
} | } |
I think this does the wrong thing if you do this:
Or maybe more simply just type in an invalid username like @@@ BONGLORD @@@. Your creative work is discarded, I think?