3 final class PhabricatorUserEmpowerTransaction
4 extends PhabricatorUserTransactionType
{
6 const TRANSACTIONTYPE
= 'user.admin';
8 public function generateOldValue($object) {
9 return (bool)$object->getIsAdmin();
12 public function generateNewValue($object, $value) {
16 public function applyInternalEffects($object, $value) {
17 $object->setIsAdmin((int)$value);
20 public function validateTransactions($object, array $xactions) {
22 $actor = $this->getActor();
25 foreach ($xactions as $xaction) {
26 $old = $xaction->getOldValue();
27 $new = $xaction->getNewValue();
33 if ($user->getPHID() === $actor->getPHID()) {
34 $errors[] = $this->newInvalidError(
35 pht('After a time, your efforts fail. You can not adjust your own '.
36 'status as an administrator.'), $xaction);
39 $is_admin = $actor->getIsAdmin();
40 $is_omnipotent = $actor->isOmnipotent();
42 if (!$is_admin && !$is_omnipotent) {
43 $errors[] = $this->newInvalidError(
44 pht('You must be an administrator to create administrators.'),
52 public function getTitle() {
53 $new = $this->getNewValue();
56 '%s empowered this user as an administrator.',
57 $this->renderAuthor());
60 '%s defrocked this user.',
61 $this->renderAuthor());
65 public function getTitleForFeed() {
66 $new = $this->getNewValue();
69 '%s empowered %s as an administrator.',
70 $this->renderAuthor(),
71 $this->renderObject());
75 $this->renderAuthor(),
76 $this->renderObject());
80 public function getRequiredCapabilities(
82 PhabricatorApplicationTransaction
$xaction) {
84 // Unlike normal user edits, admin promotions require admin
85 // permissions, which is enforced by validateTransactions().
90 public function shouldTryMFA(
92 PhabricatorApplicationTransaction
$xaction) {