3 final class PhabricatorUserApproveTransaction
4 extends PhabricatorUserTransactionType
{
6 const TRANSACTIONTYPE
= 'user.approve';
8 public function generateOldValue($object) {
9 return (bool)$object->getIsApproved();
12 public function generateNewValue($object, $value) {
16 public function applyInternalEffects($object, $value) {
17 $object->setIsApproved((int)$value);
20 public function applyExternalEffects($object, $value) {
23 $actor = $this->getActor();
25 'Phabricator Account "%s" Approved',
26 $user->getUsername());
31 'Your Phabricator account (%s) has been approved by %s. You can '.
34 $actor->getUsername()),
35 PhabricatorEnv
::getProductionURI('/'));
37 $mail = id(new PhabricatorMetaMTAMail())
38 ->addTos(array($user->getPHID()))
39 ->addCCs(array($actor->getPHID()))
40 ->setSubject('[Phabricator] '.$title)
41 ->setForceDelivery(true)
46 public function getTitle() {
47 $new = $this->getNewValue();
50 '%s approved this user.',
51 $this->renderAuthor());
54 '%s rejected this user.',
55 $this->renderAuthor());
59 public function shouldHideForFeed() {
63 public function validateTransactions($object, array $xactions) {
64 $actor = $this->getActor();
67 foreach ($xactions as $xaction) {
68 $is_approved = (bool)$object->getIsApproved();
70 if ((bool)$xaction->getNewValue() === $is_approved) {
74 $is_admin = $actor->getIsAdmin();
75 $is_omnipotent = $actor->isOmnipotent();
77 if (!$is_admin && !$is_omnipotent) {
78 $errors[] = $this->newInvalidError(
79 pht('You must be an administrator to approve users.'));
86 public function getRequiredCapabilities(
88 PhabricatorApplicationTransaction
$xaction) {
90 // Unlike normal user edits, approvals require admin permissions, which
91 // is enforced by validateTransactions().