@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.

Put Disable/Admin flags on profiles

Summary: Ref T4065. Moves the "disable / enable" and "make / unmake administrator" actions to profiles.

Test Plan: Disabled and enabled users, and made and unmade administrators.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4065

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

+165 -118
+2
src/__phutil_library_map__.php
··· 1808 1808 'PhabricatorPeopleDeleteController' => 'applications/people/controller/PhabricatorPeopleDeleteController.php', 1809 1809 'PhabricatorPeopleDisableController' => 'applications/people/controller/PhabricatorPeopleDisableController.php', 1810 1810 'PhabricatorPeopleEditController' => 'applications/people/controller/PhabricatorPeopleEditController.php', 1811 + 'PhabricatorPeopleEmpowerController' => 'applications/people/controller/PhabricatorPeopleEmpowerController.php', 1811 1812 'PhabricatorPeopleHovercardEventListener' => 'applications/people/event/PhabricatorPeopleHovercardEventListener.php', 1812 1813 'PhabricatorPeopleLdapController' => 'applications/people/controller/PhabricatorPeopleLdapController.php', 1813 1814 'PhabricatorPeopleListController' => 'applications/people/controller/PhabricatorPeopleListController.php', ··· 4613 4614 'PhabricatorPeopleDeleteController' => 'PhabricatorPeopleController', 4614 4615 'PhabricatorPeopleDisableController' => 'PhabricatorPeopleController', 4615 4616 'PhabricatorPeopleEditController' => 'PhabricatorPeopleController', 4617 + 'PhabricatorPeopleEmpowerController' => 'PhabricatorPeopleController', 4616 4618 'PhabricatorPeopleHovercardEventListener' => 'PhabricatorEventListener', 4617 4619 'PhabricatorPeopleLdapController' => 'PhabricatorPeopleController', 4618 4620 'PhabricatorPeopleListController' =>
+5 -1
src/applications/people/application/PhabricatorApplicationPeople.php
··· 42 42 '(query/(?P<key>[^/]+)/)?' => 'PhabricatorPeopleListController', 43 43 'logs/' => 'PhabricatorPeopleLogsController', 44 44 'approve/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleApproveController', 45 - 'disable/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleDisableController', 45 + '(?P<via>disapprove)/(?P<id>[1-9]\d*)/' 46 + => 'PhabricatorPeopleDisableController', 47 + '(?P<via>disable)/(?P<id>[1-9]\d*)/' 48 + => 'PhabricatorPeopleDisableController', 49 + 'empower/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleEmpowerController', 46 50 'delete/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleDeleteController', 47 51 'rename/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleRenameController', 48 52 'edit/(?:(?P<id>[1-9]\d*)/(?:(?P<view>\w+)/)?)?'
+54 -15
src/applications/people/controller/PhabricatorPeopleDisableController.php
··· 4 4 extends PhabricatorPeopleController { 5 5 6 6 private $id; 7 + private $via; 7 8 8 9 public function willProcessRequest(array $data) { 9 - $this->id = idx($data, 'id'); 10 + $this->id = $data['id']; 11 + $this->via = $data['via']; 10 12 } 11 13 12 14 public function processRequest() { 13 - 14 15 $request = $this->getRequest(); 15 16 $admin = $request->getUser(); 16 17 ··· 22 23 return new Aphront404Response(); 23 24 } 24 25 25 - $done_uri = $this->getApplicationURI('query/approval/'); 26 + // NOTE: We reach this controller via the administrative "Disable User" 27 + // on profiles and also via the "X" action on the approval queue. We do 28 + // things slightly differently depending on the context the actor is in. 29 + 30 + $is_disapprove = ($this->via == 'disapprove'); 31 + if ($is_disapprove) { 32 + $done_uri = $this->getApplicationURI('query/approval/'); 33 + $should_disable = true; 34 + } else { 35 + $done_uri = '/p/'.$user->getUsername().'/'; 36 + $should_disable = !$user->getIsDisabled(); 37 + } 38 + 39 + if ($admin->getPHID() == $user->getPHID()) { 40 + return $this->newDialog() 41 + ->setTitle(pht('Something Stays Your Hand')) 42 + ->appendParagraph( 43 + pht( 44 + 'Try as you might, you find you can not disable your '. 45 + 'own account.')) 46 + ->addCancelButton($done_uri, pht('Curses!')); 47 + } 26 48 27 49 if ($request->isFormPost()) { 28 50 id(new PhabricatorUserEditor()) 29 51 ->setActor($admin) 30 - ->disableUser($user, true); 52 + ->disableUser($user, $should_disable); 31 53 32 54 return id(new AphrontRedirectResponse())->setURI($done_uri); 33 55 } 34 56 35 - $dialog = id(new AphrontDialogView()) 36 - ->setUser($admin) 37 - ->setTitle(pht('Confirm Disable')) 38 - ->appendChild( 39 - pht( 40 - 'Disable %s? They will no longer be able to access Phabricator or '. 41 - 'receive email.', 42 - phutil_tag('strong', array(), $user->getUsername()))) 43 - ->addCancelButton($done_uri) 44 - ->addSubmitButton(pht('Disable Account')); 57 + if ($should_disable) { 58 + $title = pht('Disable User?'); 59 + $short_title = pht('Disable User'); 60 + 61 + $body = pht( 62 + 'Disable %s? They will no longer be able to access Phabricator or '. 63 + 'receive email.', 64 + phutil_tag('strong', array(), $user->getUsername())); 45 65 46 - return id(new AphrontDialogResponse())->setDialog($dialog); 66 + $submit = pht('Disable User'); 67 + } else { 68 + $title = pht('Enable User?'); 69 + $short_title = pht('Enable User'); 70 + 71 + $body = pht( 72 + 'Enable %s? They will be able to access Phabricator and receive '. 73 + 'email again.', 74 + phutil_tag('strong', array(), $user->getUsername())); 75 + 76 + $submit = pht('Enable User'); 77 + } 78 + 79 + return $this->newDialog() 80 + ->setTitle($title) 81 + ->setShortTitle($short_title) 82 + ->appendParagraph($body) 83 + ->addCancelButton($done_uri) 84 + ->addSubmitButton($submit); 47 85 } 86 + 48 87 }
-101
src/applications/people/controller/PhabricatorPeopleEditController.php
··· 35 35 $nav->setBaseURI(new PhutilURI($base_uri)); 36 36 $nav->addLabel(pht('User Information')); 37 37 $nav->addFilter('basic', pht('Basic Information')); 38 - $nav->addFilter('role', pht('Edit Roles')); 39 38 $nav->addFilter('cert', pht('Conduit Certificate')); 40 39 $nav->addFilter('profile', 41 40 pht('View Profile'), '/p/'.$user->getUsername().'/'); ··· 60 59 switch ($view) { 61 60 case 'basic': 62 61 $response = $this->processBasicRequest($user); 63 - break; 64 - case 'role': 65 - $response = $this->processRoleRequest($user); 66 62 break; 67 63 case 'cert': 68 64 $response = $this->processCertificateRequest($user); ··· 322 318 } else { 323 319 $title = pht('Create New User'); 324 320 } 325 - 326 - $form_box = id(new PHUIObjectBoxView()) 327 - ->setHeaderText($title) 328 - ->setFormErrors($errors) 329 - ->setForm($form); 330 - 331 - return array($form_box); 332 - } 333 - 334 - private function processRoleRequest(PhabricatorUser $user) { 335 - $request = $this->getRequest(); 336 - $admin = $request->getUser(); 337 - 338 - $is_self = ($user->getID() == $admin->getID()); 339 - 340 - $errors = array(); 341 - 342 - if ($request->isFormPost()) { 343 - 344 - $log_template = PhabricatorUserLog::initializeNewLog( 345 - $admin, 346 - $user->getPHID(), 347 - null); 348 - 349 - $logs = array(); 350 - 351 - if ($is_self) { 352 - $errors[] = pht("You can not edit your own role."); 353 - } else { 354 - $new_admin = (bool)$request->getBool('is_admin'); 355 - $old_admin = (bool)$user->getIsAdmin(); 356 - if ($new_admin != $old_admin) { 357 - id(new PhabricatorUserEditor()) 358 - ->setActor($admin) 359 - ->makeAdminUser($user, $new_admin); 360 - } 361 - 362 - $new_disabled = (bool)$request->getBool('is_disabled'); 363 - $old_disabled = (bool)$user->getIsDisabled(); 364 - if ($new_disabled != $old_disabled) { 365 - id(new PhabricatorUserEditor()) 366 - ->setActor($admin) 367 - ->disableUser($user, $new_disabled); 368 - } 369 - } 370 - 371 - if (!$errors) { 372 - return id(new AphrontRedirectResponse()) 373 - ->setURI($request->getRequestURI()->alter('saved', 'true')); 374 - } 375 - } 376 - 377 - $form = id(new AphrontFormView()) 378 - ->setUser($admin) 379 - ->setAction($request->getRequestURI()->alter('saved', null)); 380 - 381 - if ($is_self) { 382 - $inst = pht('NOTE: You can not edit your own role.'); 383 - $form->appendChild( 384 - phutil_tag('p', array('class' => 'aphront-form-instructions'), $inst)); 385 - } 386 - 387 - $form 388 - ->appendChild($this->getRoleInstructions()) 389 - ->appendChild( 390 - id(new AphrontFormCheckboxControl()) 391 - ->addCheckbox( 392 - 'is_admin', 393 - 1, 394 - pht('Administrator'), 395 - $user->getIsAdmin()) 396 - ->setDisabled($is_self)) 397 - ->appendChild( 398 - id(new AphrontFormCheckboxControl()) 399 - ->addCheckbox( 400 - 'is_disabled', 401 - 1, 402 - pht('Disabled'), 403 - $user->getIsDisabled()) 404 - ->setDisabled($is_self)) 405 - ->appendChild( 406 - id(new AphrontFormCheckboxControl()) 407 - ->addCheckbox( 408 - 'is_agent', 409 - 1, 410 - pht('System Agent (Bot/Script User)'), 411 - $user->getIsSystemAgent()) 412 - ->setDisabled(true)); 413 - 414 - if (!$is_self) { 415 - $form 416 - ->appendChild( 417 - id(new AphrontFormSubmitControl()) 418 - ->setValue(pht('Edit Role'))); 419 - } 420 - 421 - $title = pht('Edit Role'); 422 321 423 322 $form_box = id(new PHUIObjectBoxView()) 424 323 ->setHeaderText($title)
+71
src/applications/people/controller/PhabricatorPeopleEmpowerController.php
··· 1 + <?php 2 + 3 + final class PhabricatorPeopleEmpowerController 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 + if ($user->getPHID() == $admin->getPHID()) { 27 + return $this->newDialog() 28 + ->setTitle(pht('Your Way is Blocked')) 29 + ->appendParagraph( 30 + pht( 31 + 'After a time, your efforts fail. You can not adjust your own '. 32 + 'status as an administrator.')) 33 + ->addCancelButton($profile_uri, pht('Accept Fate')); 34 + } 35 + 36 + if ($request->isFormPost()) { 37 + id(new PhabricatorUserEditor()) 38 + ->setActor($admin) 39 + ->makeAdminUser($user, !$user->getIsAdmin()); 40 + 41 + return id(new AphrontRedirectResponse())->setURI($profile_uri); 42 + } 43 + 44 + if ($user->getIsAdmin()) { 45 + $title = pht('Remove as Administrator?'); 46 + $short = pht('Remove Administrator'); 47 + $body = pht( 48 + 'Remove %s as an administrator? They will no longer be able to '. 49 + 'perform administrative functions on this Phabricator install.', 50 + phutil_tag('strong', array(), $user->getUsername())); 51 + $submit = pht('Remove Administrator'); 52 + } else { 53 + $title = pht('Make Administrator?'); 54 + $short = pht('Make Administrator'); 55 + $body = pht( 56 + 'Empower %s as an admistrator? They will be able to create users, '. 57 + 'approve users, make and remove administrators, delete accounts, and '. 58 + 'perform other administrative functions on this Phabricator install.', 59 + phutil_tag('strong', array(), $user->getUsername())); 60 + $submit = pht('Make Administrator'); 61 + } 62 + 63 + return $this->newDialog() 64 + ->setTitle($title) 65 + ->setShortTitle($short) 66 + ->appendParagraph($body) 67 + ->addCancelButton($profile_uri) 68 + ->addSubmitButton($submit); 69 + } 70 + 71 + }
+1 -1
src/applications/people/controller/PhabricatorPeopleListController.php
··· 92 92 ->setIcon('disable') 93 93 ->setName(pht('Disable')) 94 94 ->setWorkflow(true) 95 - ->setHref($this->getApplicationURI('disable/'.$user_id.'/'))); 95 + ->setHref($this->getApplicationURI('disapprove/'.$user_id.'/'))); 96 96 $item->addAction( 97 97 id(new PHUIListItemView()) 98 98 ->setIcon('like')
+32
src/applications/people/controller/PhabricatorPeopleProfileController.php
··· 64 64 ->setWorkflow(!$can_edit)); 65 65 66 66 if ($viewer->getIsAdmin()) { 67 + if ($user->getIsAdmin()) { 68 + $empower_icon = 'lower-priority'; 69 + $empower_name = pht('Remove Administrator'); 70 + } else { 71 + $empower_icon = 'raise-priority'; 72 + $empower_name = pht('Make Administrator'); 73 + } 74 + 75 + $actions->addAction( 76 + id(new PhabricatorActionView()) 77 + ->setIcon($empower_icon) 78 + ->setName($empower_name) 79 + ->setDisabled(($user->getPHID() == $viewer->getPHID())) 80 + ->setWorkflow(true) 81 + ->setHref($this->getApplicationURI('empower/'.$user->getID().'/'))); 82 + 67 83 $actions->addAction( 68 84 id(new PhabricatorActionView()) 69 85 ->setIcon('tag') 70 86 ->setName(pht('Change Username')) 71 87 ->setWorkflow(true) 72 88 ->setHref($this->getApplicationURI('rename/'.$user->getID().'/'))); 89 + 90 + if ($user->getIsDisabled()) { 91 + $disable_icon = 'enable'; 92 + $disable_name = pht('Enable User'); 93 + } else { 94 + $disable_icon = 'disable'; 95 + $disable_name = pht('Disable User'); 96 + } 97 + 98 + $actions->addAction( 99 + id(new PhabricatorActionView()) 100 + ->setIcon($disable_icon) 101 + ->setName($disable_name) 102 + ->setDisabled(($user->getPHID() == $viewer->getPHID())) 103 + ->setWorkflow(true) 104 + ->setHref($this->getApplicationURI('disable/'.$user->getID().'/'))); 73 105 74 106 $actions->addAction( 75 107 id(new PhabricatorActionView())