@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<?php
2
3final class PhabricatorPeopleEmpowerController
4 extends PhabricatorPeopleController {
5
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $this->getViewer();
8 $id = $request->getURIData('id');
9
10 $user = id(new PhabricatorPeopleQuery())
11 ->setViewer($viewer)
12 ->withIDs(array($id))
13 ->executeOne();
14 if (!$user) {
15 return new Aphront404Response();
16 }
17
18 $done_uri = $this->getApplicationURI("manage/{$id}/");
19
20 $validation_exception = null;
21 if ($request->isFormOrHisecPost()) {
22 $xactions = array();
23 $xactions[] = id(new PhabricatorUserTransaction())
24 ->setTransactionType(
25 PhabricatorUserEmpowerTransaction::TRANSACTIONTYPE)
26 ->setNewValue(!$user->getIsAdmin());
27
28 $editor = id(new PhabricatorUserTransactionEditor())
29 ->setActor($viewer)
30 ->setContentSourceFromRequest($request)
31 ->setContinueOnMissingFields(true)
32 ->setCancelURI($done_uri);
33
34 try {
35 $editor->applyTransactions($user, $xactions);
36 return id(new AphrontRedirectResponse())->setURI($done_uri);
37 } catch (PhabricatorApplicationTransactionValidationException $ex) {
38 $validation_exception = $ex;
39 }
40 }
41
42 if ($user->getIsAdmin()) {
43 $title = pht('Remove as Administrator?');
44 $short = pht('Remove Administrator');
45 $body = pht(
46 'Remove %s as an administrator? They will no longer be able to '.
47 'perform administrative functions on this server.',
48 phutil_tag('strong', array(), $user->getUsername()));
49 $submit = pht('Remove Administrator');
50 } else {
51 $title = pht('Make Administrator?');
52 $short = pht('Make Administrator');
53 $body = pht(
54 'Empower %s as an administrator? They will be able to create users, '.
55 'approve users, make and remove administrators, delete accounts, and '.
56 'perform other administrative functions on this server.',
57 phutil_tag('strong', array(), $user->getUsername()));
58 $submit = pht('Make Administrator');
59 }
60
61 return $this->newDialog()
62 ->setValidationException($validation_exception)
63 ->setTitle($title)
64 ->setShortTitle($short)
65 ->appendParagraph($body)
66 ->addCancelButton($done_uri)
67 ->addSubmitButton($submit);
68 }
69
70}