3 final class PhabricatorPeopleDisableController
4 extends PhabricatorPeopleController
{
6 public function shouldRequireAdmin() {
10 public function handleRequest(AphrontRequest
$request) {
11 $viewer = $this->getViewer();
12 $id = $request->getURIData('id');
13 $via = $request->getURIData('via');
15 $user = id(new PhabricatorPeopleQuery())
20 return new Aphront404Response();
23 // NOTE: We reach this controller via the administrative "Disable User"
24 // on profiles and also via the "X" action on the approval queue. We do
25 // things slightly differently depending on the context the actor is in.
27 // In particular, disabling via "Disapprove" requires you be an
28 // administrator (and bypasses the "Can Disable Users" permission).
29 // Disabling via "Disable" requires the permission only.
31 $is_disapprove = ($via == 'disapprove');
33 $done_uri = $this->getApplicationURI('query/approval/');
35 if (!$viewer->getIsAdmin()) {
36 return $this->newDialog()
37 ->setTitle(pht('No Permission'))
38 ->appendParagraph(pht('Only administrators can disapprove users.'))
39 ->addCancelButton($done_uri);
42 if ($user->getIsApproved()) {
43 return $this->newDialog()
44 ->setTitle(pht('Already Approved'))
45 ->appendParagraph(pht('This user has already been approved.'))
46 ->addCancelButton($done_uri);
49 // On the "Disapprove" flow, bypass the "Can Disable Users" permission.
50 $actor = PhabricatorUser
::getOmnipotentUser();
51 $should_disable = true;
53 $this->requireApplicationCapability(
54 PeopleDisableUsersCapability
::CAPABILITY
);
57 $done_uri = $this->getApplicationURI("manage/{$id}/");
58 $should_disable = !$user->getIsDisabled();
61 if ($viewer->getPHID() == $user->getPHID()) {
62 return $this->newDialog()
63 ->setTitle(pht('Something Stays Your Hand'))
66 'Try as you might, you find you can not disable your own account.'))
67 ->addCancelButton($done_uri, pht('Curses!'));
70 if ($request->isFormPost()) {
73 $xactions[] = id(new PhabricatorUserTransaction())
74 ->setTransactionType(PhabricatorUserDisableTransaction
::TRANSACTIONTYPE
)
75 ->setNewValue($should_disable);
77 id(new PhabricatorUserTransactionEditor())
79 ->setActingAsPHID($viewer->getPHID())
80 ->setContentSourceFromRequest($request)
81 ->setContinueOnMissingFields(true)
82 ->setContinueOnNoEffect(true)
83 ->applyTransactions($user, $xactions);
85 return id(new AphrontRedirectResponse())->setURI($done_uri);
88 if ($should_disable) {
89 $title = pht('Disable User?');
90 $short_title = pht('Disable User');
93 'Disable %s? They will no longer be able to access Phabricator or '.
95 phutil_tag('strong', array(), $user->getUsername()));
97 $submit = pht('Disable User');
99 $title = pht('Enable User?');
100 $short_title = pht('Enable User');
103 'Enable %s? They will be able to access Phabricator and receive '.
105 phutil_tag('strong', array(), $user->getUsername()));
107 $submit = pht('Enable User');
110 return $this->newDialog()
112 ->setShortTitle($short_title)
113 ->appendParagraph($body)
114 ->addCancelButton($done_uri)
115 ->addSubmitButton($submit);