Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / people / xaction / PhabricatorUserDisableTransaction.php
blobf259e78ee45d8b89a4ee85ca17dc74b347af0993
1 <?php
3 final class PhabricatorUserDisableTransaction
4 extends PhabricatorUserTransactionType {
6 const TRANSACTIONTYPE = 'user.disable';
8 public function generateOldValue($object) {
9 return (bool)$object->getIsDisabled();
12 public function generateNewValue($object, $value) {
13 return (bool)$value;
16 public function applyInternalEffects($object, $value) {
17 $object->setIsDisabled((int)$value);
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());
33 public function shouldHideForFeed() {
34 // Don't publish feed stories about disabling users, since this can be
35 // a sensitive action.
36 return true;
39 public function validateTransactions($object, array $xactions) {
40 $errors = array();
42 foreach ($xactions as $xaction) {
43 $is_disabled = (bool)$object->getIsDisabled();
45 if ((bool)$xaction->getNewValue() === $is_disabled) {
46 continue;
49 // You must have the "Can Disable Users" permission to disable a user.
50 $this->requireApplicationCapability(
51 PeopleDisableUsersCapability::CAPABILITY);
53 if ($this->getActingAsPHID() === $object->getPHID()) {
54 $errors[] = $this->newInvalidError(
55 pht('You can not enable or disable your own account.'));
59 return $errors;
62 public function getRequiredCapabilities(
63 $object,
64 PhabricatorApplicationTransaction $xaction) {
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.
70 return null;