3 final class PhabricatorPeopleRenameController
4 extends PhabricatorPeopleController
{
6 public function shouldRequireAdmin() {
10 public function handleRequest(AphrontRequest
$request) {
11 $viewer = $this->getViewer();
13 $id = $request->getURIData('id');
15 $user = id(new PhabricatorPeopleQuery())
20 return new Aphront404Response();
23 $done_uri = $this->getApplicationURI("manage/{$id}/");
25 if (!$viewer->getIsAdmin()) {
26 $dialog = $this->newDialog()
27 ->setTitle(pht('Change Username'))
30 'You can not change usernames because you are not an '.
31 'administrator. Only administrators can change usernames.'))
32 ->addCancelButton($done_uri, pht('Okay'));
34 $message_body = PhabricatorAuthMessage
::loadMessageText(
36 PhabricatorAuthChangeUsernameMessageType
::MESSAGEKEY
);
37 if (strlen($message_body)) {
38 $dialog->appendRemarkup($message_body);
44 $validation_exception = null;
45 $username = $user->getUsername();
46 if ($request->isFormOrHisecPost()) {
47 $username = $request->getStr('username');
50 $xactions[] = id(new PhabricatorUserTransaction())
52 PhabricatorUserUsernameTransaction
::TRANSACTIONTYPE
)
53 ->setNewValue($username);
55 $editor = id(new PhabricatorUserTransactionEditor())
57 ->setContentSourceFromRequest($request)
58 ->setCancelURI($done_uri)
59 ->setContinueOnMissingFields(true);
62 $editor->applyTransactions($user, $xactions);
63 return id(new AphrontRedirectResponse())->setURI($done_uri);
64 } catch (PhabricatorApplicationTransactionValidationException
$ex) {
65 $validation_exception = $ex;
70 $instructions = array();
72 $instructions[] = pht(
73 'If you rename this user, the old username will no longer be tied '.
74 'to the user account. Anything which uses the old username in raw '.
75 'text (like old commit messages) may no longer associate correctly.');
77 $instructions[] = pht(
78 'It is generally safe to rename users, but changing usernames may '.
79 'create occasional minor complications or confusion with text that '.
80 'contains the old username.');
82 $instructions[] = pht(
83 'The user will receive an email notifying them that you changed their '.
86 $instructions[] = null;
88 $form = id(new AphrontFormView())
90 id(new AphrontFormStaticControl())
91 ->setLabel(pht('Old Username'))
92 ->setValue($user->getUsername()))
94 id(new AphrontFormTextControl())
95 ->setLabel(pht('New Username'))
97 ->setName('username'));
99 $dialog = $this->newDialog()
100 ->setTitle(pht('Change Username'))
101 ->setValidationException($validation_exception);
103 foreach ($instructions as $instruction) {
104 $dialog->appendParagraph($instruction);
109 ->addSubmitButton(pht('Rename User'))
110 ->addCancelButton($done_uri);