1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-25 21:19:21 +01:00
phorge-phorge/src/applications/people/xaction/PhabricatorUserDisableTransaction.php
epriestley ba83380565 Update the "Notification Test" workflow to use more modern mechanisms
Summary:
Depends on D19860. Ref T13222. Ref T10743. See PHI996.

Long ago, there were different types of feed stories. Over time, there was less and less need for this, and nowadays basically everything is a "transaction" feed story. Each story renders differently, but they're fundamentally all about transactions.

The Notification test controller still uses a custom type of feed story to send notifications. Move away from this, and apply a transaction against the user instead. This has the same ultimate effect, but involves less weird custom code from ages long forgotten.

This doesn't fix the actual problem with these things showing up in feed. Currently, stories always use the same rendering for feed and notifications, and there need to be some additional changes to fix this. So no behavioral change yet, just slightly more reasonable code.

Test Plan: Clicked the button and got some test notifications, with Aphlict running.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13222, T10743

Differential Revision: https://secure.phabricator.com/D19861
2018-12-10 16:02:11 -08:00

77 lines
1.9 KiB
PHP

<?php
final class PhabricatorUserDisableTransaction
extends PhabricatorUserTransactionType {
const TRANSACTIONTYPE = 'user.disable';
public function generateOldValue($object) {
return (bool)$object->getIsDisabled();
}
public function generateNewValue($object, $value) {
return (bool)$value;
}
public function applyInternalEffects($object, $value) {
$object->setIsDisabled((int)$value);
$this->newUserLog(PhabricatorUserLog::ACTION_DISABLE)
->setOldValue((bool)$object->getIsDisabled())
->setNewValue((bool)$value)
->save();
}
public function getTitle() {
$new = $this->getNewValue();
if ($new) {
return pht(
'%s disabled this user.',
$this->renderAuthor());
} else {
return pht(
'%s enabled this user.',
$this->renderAuthor());
}
}
public function shouldHideForFeed() {
// Don't publish feed stories about disabling users, since this can be
// a sensitive action.
return true;
}
public function validateTransactions($object, array $xactions) {
$errors = array();
foreach ($xactions as $xaction) {
$is_disabled = (bool)$object->getIsDisabled();
if ((bool)$xaction->getNewValue() === $is_disabled) {
continue;
}
// You must have the "Can Disable Users" permission to disable a user.
$this->requireApplicationCapability(
PeopleDisableUsersCapability::CAPABILITY);
if ($this->getActingAsPHID() === $object->getPHID()) {
$errors[] = $this->newInvalidError(
pht('You can not enable or disable your own account.'));
}
}
return $errors;
}
public function getRequiredCapabilities(
$object,
PhabricatorApplicationTransaction $xaction) {
// You do not need to be able to edit users to disable them. Instead, this
// requirement is replaced with a requirement that you have the "Can
// Disable Users" permission.
return null;
}
}