@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move "Change Username" from weird edit panel to standard object action

Summary: Ref T4065. Make this work in a more standard way which administrators have a reasonable shot at finding and using. See D8662 for discussion.

Test Plan: Changed a user's username.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4065

Differential Revision: https://secure.phabricator.com/D8663

+124 -95
+2
src/__phutil_library_map__.php
··· 1818 1818 'PhabricatorPeopleProfileEditController' => 'applications/people/controller/PhabricatorPeopleProfileEditController.php', 1819 1819 'PhabricatorPeopleProfilePictureController' => 'applications/people/controller/PhabricatorPeopleProfilePictureController.php', 1820 1820 'PhabricatorPeopleQuery' => 'applications/people/query/PhabricatorPeopleQuery.php', 1821 + 'PhabricatorPeopleRenameController' => 'applications/people/controller/PhabricatorPeopleRenameController.php', 1821 1822 'PhabricatorPeopleSearchEngine' => 'applications/people/query/PhabricatorPeopleSearchEngine.php', 1822 1823 'PhabricatorPeopleTestDataGenerator' => 'applications/people/lipsum/PhabricatorPeopleTestDataGenerator.php', 1823 1824 'PhabricatorPhameConfigOptions' => 'applications/phame/config/PhabricatorPhameConfigOptions.php', ··· 4626 4627 'PhabricatorPeopleProfileEditController' => 'PhabricatorPeopleController', 4627 4628 'PhabricatorPeopleProfilePictureController' => 'PhabricatorPeopleController', 4628 4629 'PhabricatorPeopleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 4630 + 'PhabricatorPeopleRenameController' => 'PhabricatorPeopleController', 4629 4631 'PhabricatorPeopleSearchEngine' => 'PhabricatorApplicationSearchEngine', 4630 4632 'PhabricatorPeopleTestDataGenerator' => 'PhabricatorTestDataGenerator', 4631 4633 'PhabricatorPhameConfigOptions' => 'PhabricatorApplicationConfigOptions',
+1
src/applications/people/application/PhabricatorApplicationPeople.php
··· 44 44 'approve/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleApproveController', 45 45 'disable/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleDisableController', 46 46 'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleDeleteController', 47 + 'rename/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleRenameController', 47 48 'edit/(?:(?P<id>[1-9]\d*)/(?:(?P<view>\w+)/)?)?' 48 49 => 'PhabricatorPeopleEditController', 49 50 'ldap/' => 'PhabricatorPeopleLdapController',
+1 -1
src/applications/people/controller/PhabricatorPeopleDeleteController.php
··· 34 34 if ($request->isFormPost()) { 35 35 $v_username = $request->getStr('username'); 36 36 37 - if (!$v_username) { 37 + if (!strlen($v_username)) { 38 38 $errors[] = pht( 39 39 'You must type the username to confirm that you want to delete '. 40 40 'this user account.');
+1 -94
src/applications/people/controller/PhabricatorPeopleEditController.php
··· 39 39 $nav->addFilter('cert', pht('Conduit Certificate')); 40 40 $nav->addFilter('profile', 41 41 pht('View Profile'), '/p/'.$user->getUsername().'/'); 42 - $nav->addLabel(pht('Special')); 43 - $nav->addFilter('rename', pht('Change Username')); 44 42 if ($user->getIsSystemAgent()) { 43 + $nav->addLabel(pht('Special')); 45 44 $nav->addFilter('picture', pht('Set Account Picture')); 46 45 } 47 46 ··· 71 70 break; 72 71 case 'cert': 73 72 $response = $this->processCertificateRequest($user); 74 - break; 75 - case 'rename': 76 - $response = $this->processRenameRequest($user); 77 73 break; 78 74 case 'picture': 79 75 $response = $this->processSetAccountPicture($user); ··· 475 471 476 472 $form_box = id(new PHUIObjectBoxView()) 477 473 ->setHeaderText($title) 478 - ->setForm($form); 479 - 480 - return array($form_box); 481 - } 482 - 483 - private function processRenameRequest(PhabricatorUser $user) { 484 - $request = $this->getRequest(); 485 - $admin = $request->getUser(); 486 - 487 - $e_username = true; 488 - $username = $user->getUsername(); 489 - 490 - $errors = array(); 491 - if ($request->isFormPost()) { 492 - 493 - $username = $request->getStr('username'); 494 - if (!strlen($username)) { 495 - $e_username = pht('Required'); 496 - $errors[] = pht('New username is required.'); 497 - } else if ($username == $user->getUsername()) { 498 - $e_username = pht('Invalid'); 499 - $errors[] = pht('New username must be different from old username.'); 500 - } else if (!PhabricatorUser::validateUsername($username)) { 501 - $e_username = pht('Invalid'); 502 - $errors[] = PhabricatorUser::describeValidUsername(); 503 - } 504 - 505 - if (!$errors) { 506 - try { 507 - 508 - id(new PhabricatorUserEditor()) 509 - ->setActor($admin) 510 - ->changeUsername($user, $username); 511 - 512 - return id(new AphrontRedirectResponse()) 513 - ->setURI($request->getRequestURI()->alter('saved', true)); 514 - } catch (AphrontQueryDuplicateKeyException $ex) { 515 - $e_username = pht('Not Unique'); 516 - $errors[] = pht('Another user already has that username.'); 517 - } 518 - } 519 - } 520 - 521 - $inst1 = pht('Be careful when renaming users!'); 522 - $inst2 = pht('The old username will no longer be tied to the user, so '. 523 - 'anything which uses it (like old commit messages) will no longer '. 524 - 'associate correctly. And if you give a user a username which some '. 525 - 'other user used to have, username lookups will begin returning '. 526 - 'the wrong user.'); 527 - $inst3 = pht('It is generally safe to rename newly created users (and '. 528 - 'test users and so on), but less safe to rename established users '. 529 - 'and unsafe to reissue a username.'); 530 - $inst4 = pht('Users who rely on password auth will need to reset their '. 531 - 'passwordafter their username is changed (their username is part '. 532 - 'of the salt in the password hash). They will receive an email '. 533 - 'with instructions on how to do this.'); 534 - 535 - $form = new AphrontFormView(); 536 - $form 537 - ->setUser($admin) 538 - ->setAction($request->getRequestURI()) 539 - ->appendChild(hsprintf( 540 - '<p class="aphront-form-instructions">'. 541 - '<strong>%s</strong> '. 542 - '%s'. 543 - '</p>'. 544 - '<p class="aphront-form-instructions">'. 545 - '%s'. 546 - '</p>'. 547 - '<p class="aphront-form-instructions">'. 548 - '%s'. 549 - '</p>', $inst1, $inst2, $inst3, $inst4)) 550 - ->appendChild( 551 - id(new AphrontFormStaticControl()) 552 - ->setLabel(pht('Old Username')) 553 - ->setValue($user->getUsername())) 554 - ->appendChild( 555 - id(new AphrontFormTextControl()) 556 - ->setLabel(pht('New Username')) 557 - ->setValue($username) 558 - ->setName('username') 559 - ->setError($e_username)) 560 - ->appendChild( 561 - id(new AphrontFormSubmitControl()) 562 - ->setValue(pht('Change Username'))); 563 - 564 - $form_box = id(new PHUIObjectBoxView()) 565 - ->setHeaderText(pht('Change Username')) 566 - ->setFormErrors($errors) 567 474 ->setForm($form); 568 475 569 476 return array($form_box);
+7
src/applications/people/controller/PhabricatorPeopleProfileController.php
··· 63 63 if ($viewer->getIsAdmin()) { 64 64 $actions->addAction( 65 65 id(new PhabricatorActionView()) 66 + ->setIcon('tag') 67 + ->setName(pht('Change Username')) 68 + ->setWorkflow(true) 69 + ->setHref($this->getApplicationURI('rename/'.$user->getID().'/'))); 70 + 71 + $actions->addAction( 72 + id(new PhabricatorActionView()) 66 73 ->setIcon('delete') 67 74 ->setName(pht('Delete User')) 68 75 ->setDisabled(($user->getPHID() == $viewer->getPHID()))
+112
src/applications/people/controller/PhabricatorPeopleRenameController.php
··· 1 + <?php 2 + 3 + final class PhabricatorPeopleRenameController 4 + extends PhabricatorPeopleController { 5 + 6 + private $id; 7 + 8 + public function willProcessRequest(array $data) { 9 + $this->id = $data['id']; 10 + } 11 + 12 + public function processRequest() { 13 + $request = $this->getRequest(); 14 + $admin = $request->getUser(); 15 + 16 + $user = id(new PhabricatorPeopleQuery()) 17 + ->setViewer($admin) 18 + ->withIDs(array($this->id)) 19 + ->executeOne(); 20 + if (!$user) { 21 + return new Aphront404Response(); 22 + } 23 + 24 + $profile_uri = '/p/'.$user->getUsername(); 25 + 26 + $errors = array(); 27 + 28 + $v_username = $user->getUsername(); 29 + $e_username = true; 30 + if ($request->isFormPost()) { 31 + $v_username = $request->getStr('username'); 32 + 33 + 34 + if (!strlen($v_username)) { 35 + $e_username = pht('Required'); 36 + $errors[] = pht('New username is required.'); 37 + } else if ($v_username == $user->getUsername()) { 38 + $e_username = pht('Invalid'); 39 + $errors[] = pht('New username must be different from old username.'); 40 + } else if (!PhabricatorUser::validateUsername($v_username)) { 41 + $e_username = pht('Invalid'); 42 + $errors[] = PhabricatorUser::describeValidUsername(); 43 + } 44 + 45 + if (!$errors) { 46 + try { 47 + id(new PhabricatorUserEditor()) 48 + ->setActor($admin) 49 + ->changeUsername($user, $v_username); 50 + 51 + $new_uri = '/p/'.$v_username.'/'; 52 + 53 + return id(new AphrontRedirectResponse())->setURI($new_uri); 54 + } catch (AphrontQueryDuplicateKeyException $ex) { 55 + $e_username = pht('Not Unique'); 56 + $errors[] = pht('Another user already has that username.'); 57 + } 58 + } 59 + } 60 + 61 + $inst1 = pht( 62 + 'Be careful when renaming users!'); 63 + 64 + $inst2 = pht( 65 + 'The old username will no longer be tied to the user, so anything '. 66 + 'which uses it (like old commit messages) will no longer associate '. 67 + 'correctly. (And, if you give a user a username which some other user '. 68 + 'used to have, username lookups will begin returning the wrong user.)'); 69 + 70 + $inst3 = pht( 71 + 'It is generally safe to rename newly created users (and test users '. 72 + 'and so on), but less safe to rename established users and unsafe to '. 73 + 'reissue a username.'); 74 + 75 + $inst4 = pht( 76 + 'Users who rely on password authentication will need to reset their '. 77 + 'password after their username is changed (their username is part of '. 78 + 'the salt in the password hash). They will receive an email with '. 79 + 'instructions on how to do this.'); 80 + 81 + $form = id(new AphrontFormView()) 82 + ->setUser($admin) 83 + ->appendChild( 84 + id(new AphrontFormStaticControl()) 85 + ->setLabel(pht('Old Username')) 86 + ->setValue($user->getUsername())) 87 + ->appendChild( 88 + id(new AphrontFormTextControl()) 89 + ->setLabel(pht('New Username')) 90 + ->setValue($v_username) 91 + ->setName('username') 92 + ->setError($e_username)); 93 + 94 + if ($errors) { 95 + $errors = id(new AphrontErrorView())->setErrors($errors); 96 + } 97 + 98 + return $this->newDialog() 99 + ->setWidth(AphrontDialogView::WIDTH_FORM) 100 + ->setTitle(pht('Change Username')) 101 + ->appendChild($errors) 102 + ->appendParagraph($inst1) 103 + ->appendParagraph($inst2) 104 + ->appendParagraph($inst3) 105 + ->appendParagraph($inst4) 106 + ->appendParagraph(null) 107 + ->appendChild($form->buildLayoutView()) 108 + ->addSubmitButton(pht('Rename User')) 109 + ->addCancelButton($profile_uri); 110 + } 111 + 112 + }