@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 PhabricatorUserDisableTransaction
4 extends PhabricatorUserTransactionType {
5
6 const TRANSACTIONTYPE = 'user.disable';
7
8 public function generateOldValue($object) {
9 return (bool)$object->getIsDisabled();
10 }
11
12 public function generateNewValue($object, $value) {
13 return (bool)$value;
14 }
15
16 public function applyInternalEffects($object, $value) {
17 $object->setIsDisabled((int)$value);
18 }
19
20 public function getTitle() {
21 $new = $this->getNewValue();
22 if ($new) {
23 return pht(
24 '%s disabled this user.',
25 $this->renderAuthor());
26 } else {
27 return pht(
28 '%s enabled this user.',
29 $this->renderAuthor());
30 }
31 }
32
33 public function shouldHideForFeed() {
34 // Don't publish feed stories about disabling users, since this can be
35 // a sensitive action.
36 return true;
37 }
38
39 public function validateTransactions($object, array $xactions) {
40 $errors = array();
41
42 foreach ($xactions as $xaction) {
43 $is_disabled = (bool)$object->getIsDisabled();
44
45 if ((bool)$xaction->getNewValue() === $is_disabled) {
46 continue;
47 }
48
49 // You must have the "Can Disable Users" permission to disable a user.
50 $this->requireApplicationCapability(
51 PeopleDisableUsersCapability::CAPABILITY);
52
53 if ($this->getActingAsPHID() === $object->getPHID()) {
54 $errors[] = $this->newInvalidError(
55 pht('You can not enable or disable your own account.'));
56 }
57 }
58
59 return $errors;
60 }
61
62 public function getRequiredCapabilities(
63 $object,
64 PhabricatorApplicationTransaction $xaction) {
65
66 // You do not need to be able to edit users to disable them. Instead, this
67 // requirement is replaced with a requirement that you have the "Can
68 // Disable Users" permission.
69
70 return null;
71 }
72}