Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/people/controller/PhabricatorPeopleRenameController.php
12262 views
1
<?php
2
3
final class PhabricatorPeopleRenameController
4
extends PhabricatorPeopleController {
5
6
public function shouldRequireAdmin() {
7
return false;
8
}
9
10
public function handleRequest(AphrontRequest $request) {
11
$viewer = $this->getViewer();
12
13
$id = $request->getURIData('id');
14
15
$user = id(new PhabricatorPeopleQuery())
16
->setViewer($viewer)
17
->withIDs(array($id))
18
->executeOne();
19
if (!$user) {
20
return new Aphront404Response();
21
}
22
23
$done_uri = $this->getApplicationURI("manage/{$id}/");
24
25
if (!$viewer->getIsAdmin()) {
26
$dialog = $this->newDialog()
27
->setTitle(pht('Change Username'))
28
->appendParagraph(
29
pht(
30
'You can not change usernames because you are not an '.
31
'administrator. Only administrators can change usernames.'))
32
->addCancelButton($done_uri, pht('Okay'));
33
34
$message_body = PhabricatorAuthMessage::loadMessageText(
35
$viewer,
36
PhabricatorAuthChangeUsernameMessageType::MESSAGEKEY);
37
if (strlen($message_body)) {
38
$dialog->appendRemarkup($message_body);
39
}
40
41
return $dialog;
42
}
43
44
$validation_exception = null;
45
$username = $user->getUsername();
46
if ($request->isFormOrHisecPost()) {
47
$username = $request->getStr('username');
48
$xactions = array();
49
50
$xactions[] = id(new PhabricatorUserTransaction())
51
->setTransactionType(
52
PhabricatorUserUsernameTransaction::TRANSACTIONTYPE)
53
->setNewValue($username);
54
55
$editor = id(new PhabricatorUserTransactionEditor())
56
->setActor($viewer)
57
->setContentSourceFromRequest($request)
58
->setCancelURI($done_uri)
59
->setContinueOnMissingFields(true);
60
61
try {
62
$editor->applyTransactions($user, $xactions);
63
return id(new AphrontRedirectResponse())->setURI($done_uri);
64
} catch (PhabricatorApplicationTransactionValidationException $ex) {
65
$validation_exception = $ex;
66
}
67
68
}
69
70
$instructions = array();
71
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.');
76
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.');
81
82
$instructions[] = pht(
83
'The user will receive an email notifying them that you changed their '.
84
'username.');
85
86
$instructions[] = null;
87
88
$form = id(new AphrontFormView())
89
->appendChild(
90
id(new AphrontFormStaticControl())
91
->setLabel(pht('Old Username'))
92
->setValue($user->getUsername()))
93
->appendChild(
94
id(new AphrontFormTextControl())
95
->setLabel(pht('New Username'))
96
->setValue($username)
97
->setName('username'));
98
99
$dialog = $this->newDialog()
100
->setTitle(pht('Change Username'))
101
->setValidationException($validation_exception);
102
103
foreach ($instructions as $instruction) {
104
$dialog->appendParagraph($instruction);
105
}
106
107
$dialog
108
->appendForm($form)
109
->addSubmitButton(pht('Rename User'))
110
->addCancelButton($done_uri);
111
112
return $dialog;
113
}
114
115
}
116
117