Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / people / xaction / PhabricatorUserApproveTransaction.php
blob213b381d1a83d2ccc2b483285825afdbecad0a93
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 '%s Account "%s" Approved',
26 PlatformSymbols::getPlatformServerName(),
27 $user->getUsername());
29 $body = sprintf(
30 "%s\n\n %s\n\n",
31 pht(
32 'Your %s account (%s) has been approved by %s. You can '.
33 'login here:',
34 PlatformSymbols::getPlatformServerName(),
35 $user->getUsername(),
36 $actor->getUsername()),
37 PhabricatorEnv::getProductionURI('/'));
39 $mail = id(new PhabricatorMetaMTAMail())
40 ->addTos(array($user->getPHID()))
41 ->addCCs(array($actor->getPHID()))
42 ->setSubject(
43 pht(
44 '[%s] %s',
45 PlatformSymbols::getPlatformServerName(),
46 $title))
47 ->setForceDelivery(true)
48 ->setBody($body)
49 ->saveAndSend();
52 public function getTitle() {
53 $new = $this->getNewValue();
54 if ($new) {
55 return pht(
56 '%s approved this user.',
57 $this->renderAuthor());
58 } else {
59 return pht(
60 '%s rejected this user.',
61 $this->renderAuthor());
65 public function shouldHideForFeed() {
66 return true;
69 public function validateTransactions($object, array $xactions) {
70 $actor = $this->getActor();
71 $errors = array();
73 foreach ($xactions as $xaction) {
74 $is_approved = (bool)$object->getIsApproved();
76 if ((bool)$xaction->getNewValue() === $is_approved) {
77 continue;
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.'));
89 return $errors;
92 public function getRequiredCapabilities(
93 $object,
94 PhabricatorApplicationTransaction $xaction) {
96 // Unlike normal user edits, approvals require admin permissions, which
97 // is enforced by validateTransactions().
99 return null;