Path: blob/master/src/applications/people/xaction/PhabricatorUserDisableTransaction.php
12256 views
<?php12final class PhabricatorUserDisableTransaction3extends PhabricatorUserTransactionType {45const TRANSACTIONTYPE = 'user.disable';67public function generateOldValue($object) {8return (bool)$object->getIsDisabled();9}1011public function generateNewValue($object, $value) {12return (bool)$value;13}1415public function applyInternalEffects($object, $value) {16$object->setIsDisabled((int)$value);17}1819public function getTitle() {20$new = $this->getNewValue();21if ($new) {22return pht(23'%s disabled this user.',24$this->renderAuthor());25} else {26return pht(27'%s enabled this user.',28$this->renderAuthor());29}30}3132public function shouldHideForFeed() {33// Don't publish feed stories about disabling users, since this can be34// a sensitive action.35return true;36}3738public function validateTransactions($object, array $xactions) {39$errors = array();4041foreach ($xactions as $xaction) {42$is_disabled = (bool)$object->getIsDisabled();4344if ((bool)$xaction->getNewValue() === $is_disabled) {45continue;46}4748// You must have the "Can Disable Users" permission to disable a user.49$this->requireApplicationCapability(50PeopleDisableUsersCapability::CAPABILITY);5152if ($this->getActingAsPHID() === $object->getPHID()) {53$errors[] = $this->newInvalidError(54pht('You can not enable or disable your own account.'));55}56}5758return $errors;59}6061public function getRequiredCapabilities(62$object,63PhabricatorApplicationTransaction $xaction) {6465// You do not need to be able to edit users to disable them. Instead, this66// requirement is replaced with a requirement that you have the "Can67// Disable Users" permission.6869return null;70}71}727374