@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 109 lines 2.8 kB view raw
1<?php 2 3final class PhabricatorUserEmpowerTransaction 4 extends PhabricatorUserTransactionType { 5 6 const TRANSACTIONTYPE = 'user.admin'; 7 8 public function generateOldValue($object) { 9 return (bool)$object->getIsAdmin(); 10 } 11 12 public function generateNewValue($object, $value) { 13 return (bool)$value; 14 } 15 16 public function applyInternalEffects($object, $value) { 17 $object->setIsAdmin((int)$value); 18 } 19 20 public function validateTransactions($object, array $xactions) { 21 $user = $object; 22 $actor = $this->getActor(); 23 24 $errors = array(); 25 foreach ($xactions as $xaction) { 26 $old = $xaction->getOldValue(); 27 $new = $xaction->getNewValue(); 28 29 if ($old === $new) { 30 continue; 31 } 32 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); 37 } 38 39 $is_admin = $actor->getIsAdmin(); 40 $is_omnipotent = $actor->isOmnipotent(); 41 42 if (!$is_admin && !$is_omnipotent) { 43 $errors[] = $this->newInvalidError( 44 pht('You must be an administrator to create administrators.'), 45 $xaction); 46 } 47 } 48 49 return $errors; 50 } 51 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 if (PhabricatorEnv::getEnvConfig('phabricator.serious-business')) { 60 return pht( 61 '%s removed the administrator role from this user.', 62 $this->renderAuthor()); 63 } else { 64 return pht( 65 '%s defrocked this user.', 66 $this->renderAuthor()); 67 } 68 } 69 } 70 71 public function getTitleForFeed() { 72 $new = $this->getNewValue(); 73 if ($new) { 74 return pht( 75 '%s empowered %s as an administrator.', 76 $this->renderAuthor(), 77 $this->renderObject()); 78 } else { 79 if (PhabricatorEnv::getEnvConfig('phabricator.serious-business')) { 80 return pht( 81 '%s removed the administrator role from %s.', 82 $this->renderAuthor(), 83 $this->renderObject()); 84 } else { 85 return pht( 86 '%s defrocked %s.', 87 $this->renderAuthor(), 88 $this->renderObject()); 89 } 90 } 91 } 92 93 public function getRequiredCapabilities( 94 $object, 95 PhabricatorApplicationTransaction $xaction) { 96 97 // Unlike normal user edits, admin promotions require admin 98 // permissions, which is enforced by validateTransactions(). 99 100 return null; 101 } 102 103 public function shouldTryMFA( 104 $object, 105 PhabricatorApplicationTransaction $xaction) { 106 return true; 107 } 108 109}