Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / people / xaction / PhabricatorUserEmpowerTransaction.php
blobd17418636f1a3221d32909bda030b15cf130b0e3
1 <?php
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) {
13 return (bool)$value;
16 public function applyInternalEffects($object, $value) {
17 $object->setIsAdmin((int)$value);
20 public function validateTransactions($object, array $xactions) {
21 $user = $object;
22 $actor = $this->getActor();
24 $errors = array();
25 foreach ($xactions as $xaction) {
26 $old = $xaction->getOldValue();
27 $new = $xaction->getNewValue();
29 if ($old === $new) {
30 continue;
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.'),
45 $xaction);
49 return $errors;
52 public function getTitle() {
53 $new = $this->getNewValue();
54 if ($new) {
55 return pht(
56 '%s empowered this user as an administrator.',
57 $this->renderAuthor());
58 } else {
59 return pht(
60 '%s defrocked this user.',
61 $this->renderAuthor());
65 public function getTitleForFeed() {
66 $new = $this->getNewValue();
67 if ($new) {
68 return pht(
69 '%s empowered %s as an administrator.',
70 $this->renderAuthor(),
71 $this->renderObject());
72 } else {
73 return pht(
74 '%s defrocked %s.',
75 $this->renderAuthor(),
76 $this->renderObject());
80 public function getRequiredCapabilities(
81 $object,
82 PhabricatorApplicationTransaction $xaction) {
84 // Unlike normal user edits, admin promotions require admin
85 // permissions, which is enforced by validateTransactions().
87 return null;
90 public function shouldTryMFA(
91 $object,
92 PhabricatorApplicationTransaction $xaction) {
93 return true;