Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / people / xaction / PhabricatorUserApproveTransaction.php
blob1084f0c8fa6018182c467bbe9256352a7daa24c7
1 <?php
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) {
13 return (bool)$value;
16 public function applyInternalEffects($object, $value) {
17 $object->setIsApproved((int)$value);
20 public function applyExternalEffects($object, $value) {
21 $user = $object;
23 $actor = $this->getActor();
24 $title = pht(
25 'Phabricator Account "%s" Approved',
26 $user->getUsername());
28 $body = sprintf(
29 "%s\n\n %s\n\n",
30 pht(
31 'Your Phabricator account (%s) has been approved by %s. You can '.
32 'login here:',
33 $user->getUsername(),
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)
42 ->setBody($body)
43 ->saveAndSend();
46 public function getTitle() {
47 $new = $this->getNewValue();
48 if ($new) {
49 return pht(
50 '%s approved this user.',
51 $this->renderAuthor());
52 } else {
53 return pht(
54 '%s rejected this user.',
55 $this->renderAuthor());
59 public function shouldHideForFeed() {
60 return true;
63 public function validateTransactions($object, array $xactions) {
64 $actor = $this->getActor();
65 $errors = array();
67 foreach ($xactions as $xaction) {
68 $is_approved = (bool)$object->getIsApproved();
70 if ((bool)$xaction->getNewValue() === $is_approved) {
71 continue;
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.'));
83 return $errors;
86 public function getRequiredCapabilities(
87 $object,
88 PhabricatorApplicationTransaction $xaction) {
90 // Unlike normal user edits, approvals require admin permissions, which
91 // is enforced by validateTransactions().
93 return null;