3 final class PhabricatorUserUsernameTransaction
4 extends PhabricatorUserTransactionType
{
6 const TRANSACTIONTYPE
= 'user.rename';
8 public function generateOldValue($object) {
9 return $object->getUsername();
12 public function generateNewValue($object, $value) {
16 public function applyInternalEffects($object, $value) {
17 $object->setUsername($value);
20 public function applyExternalEffects($object, $value) {
21 $actor = $this->getActor();
24 $old_username = $this->getOldValue();
25 $new_username = $this->getNewValue();
27 // The SSH key cache currently includes usernames, so dirty it. See T12554
29 PhabricatorAuthSSHKeyQuery
::deleteSSHKeyCache();
31 id(new PhabricatorPeopleUsernameMailEngine())
33 ->setRecipient($object)
34 ->setOldUsername($old_username)
35 ->setNewUsername($new_username)
39 public function getTitle() {
41 '%s renamed this user from %s to %s.',
42 $this->renderAuthor(),
43 $this->renderOldValue(),
44 $this->renderNewValue());
47 public function getTitleForFeed() {
49 '%s renamed %s from %s to %s.',
50 $this->renderAuthor(),
51 $this->renderObject(),
52 $this->renderOldValue(),
53 $this->renderNewValue());
56 public function validateTransactions($object, array $xactions) {
57 $actor = $this->getActor();
60 foreach ($xactions as $xaction) {
61 $new = $xaction->getNewValue();
62 $old = $xaction->getOldValue();
68 if (!$actor->getIsAdmin()) {
69 $errors[] = $this->newInvalidError(
70 pht('You must be an administrator to rename users.'));
74 $errors[] = $this->newInvalidError(
75 pht('New username is required.'),
77 } else if (!PhabricatorUser
::validateUsername($new)) {
78 $errors[] = $this->newInvalidError(
79 PhabricatorUser
::describeValidUsername(),
83 $user = id(new PhabricatorPeopleQuery())
84 ->setViewer(PhabricatorUser
::getOmnipotentUser())
85 ->withUsernames(array($new))
88 // See T13446. We may be changing the letter case of a username, which
89 // is a perfectly fine edit.
90 $is_self = ($user->getPHID() === $object->getPHID());
92 $errors[] = $this->newInvalidError(
94 'Another user already has the username "%s".',
105 public function getRequiredCapabilities(
107 PhabricatorApplicationTransaction
$xaction) {
109 // Unlike normal user edits, renames require admin permissions, which
110 // is enforced by validateTransactions().
115 public function shouldTryMFA(
117 PhabricatorApplicationTransaction
$xaction) {