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 '%s Account "%s" Approved',
26 PlatformSymbols
::getPlatformServerName(),
27 $user->getUsername());
32 'Your %s account (%s) has been approved by %s. You can '.
34 PlatformSymbols
::getPlatformServerName(),
36 $actor->getUsername()),
37 PhabricatorEnv
::getProductionURI('/'));
39 $mail = id(new PhabricatorMetaMTAMail())
40 ->addTos(array($user->getPHID()))
41 ->addCCs(array($actor->getPHID()))
45 PlatformSymbols
::getPlatformServerName(),
47 ->setForceDelivery(true)
52 public function getTitle() {
53 $new = $this->getNewValue();
56 '%s approved this user.',
57 $this->renderAuthor());
60 '%s rejected this user.',
61 $this->renderAuthor());
65 public function shouldHideForFeed() {
69 public function validateTransactions($object, array $xactions) {
70 $actor = $this->getActor();
73 foreach ($xactions as $xaction) {
74 $is_approved = (bool)$object->getIsApproved();
76 if ((bool)$xaction->getNewValue() === $is_approved) {
80 $is_admin = $actor->getIsAdmin();
81 $is_omnipotent = $actor->isOmnipotent();
83 if (!$is_admin && !$is_omnipotent) {
84 $errors[] = $this->newInvalidError(
85 pht('You must be an administrator to approve users.'));
92 public function getRequiredCapabilities(
94 PhabricatorApplicationTransaction
$xaction) {
96 // Unlike normal user edits, approvals require admin permissions, which
97 // is enforced by validateTransactions().