Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / people / controller / PhabricatorPeopleDisableController.php
blob9f2718086b50a58602e0388d4ca755430370e213
1 <?php
3 final class PhabricatorPeopleDisableController
4 extends PhabricatorPeopleController {
6 public function shouldRequireAdmin() {
7 return false;
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())
16 ->setViewer($viewer)
17 ->withIDs(array($id))
18 ->executeOne();
19 if (!$user) {
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');
32 if ($is_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;
52 } else {
53 $this->requireApplicationCapability(
54 PeopleDisableUsersCapability::CAPABILITY);
56 $actor = $viewer;
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'))
64 ->appendParagraph(
65 pht(
66 'Try as you might, you find you can not disable your own account.'))
67 ->addCancelButton($done_uri, pht('Curses!'));
70 if ($request->isFormPost()) {
71 $xactions = array();
73 $xactions[] = id(new PhabricatorUserTransaction())
74 ->setTransactionType(PhabricatorUserDisableTransaction::TRANSACTIONTYPE)
75 ->setNewValue($should_disable);
77 id(new PhabricatorUserTransactionEditor())
78 ->setActor($actor)
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');
92 $body = pht(
93 'Disable %s? They will no longer be able to access Phabricator or '.
94 'receive email.',
95 phutil_tag('strong', array(), $user->getUsername()));
97 $submit = pht('Disable User');
98 } else {
99 $title = pht('Enable User?');
100 $short_title = pht('Enable User');
102 $body = pht(
103 'Enable %s? They will be able to access Phabricator and receive '.
104 'email again.',
105 phutil_tag('strong', array(), $user->getUsername()));
107 $submit = pht('Enable User');
110 return $this->newDialog()
111 ->setTitle($title)
112 ->setShortTitle($short_title)
113 ->appendParagraph($body)
114 ->addCancelButton($done_uri)
115 ->addSubmitButton($submit);