@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<?php
2
3final class PhortuneAccountEmailStatusController
4 extends PhortuneAccountController {
5
6 protected function shouldRequireAccountEditCapability() {
7 return true;
8 }
9
10 protected function handleAccountRequest(AphrontRequest $request) {
11 $viewer = $this->getViewer();
12 $account = $this->getAccount();
13
14 $address = id(new PhortuneAccountEmailQuery())
15 ->setViewer($viewer)
16 ->withAccountPHIDs(array($account->getPHID()))
17 ->withIDs(array($request->getURIData('addressID')))
18 ->requireCapabilities(
19 array(
20 PhabricatorPolicyCapability::CAN_VIEW,
21 PhabricatorPolicyCapability::CAN_EDIT,
22 ))
23 ->executeOne();
24 if (!$address) {
25 return new Aphront404Response();
26 }
27
28 $address_uri = $address->getURI();
29
30 $is_enable = false;
31 $is_disable = false;
32
33 $old_status = $address->getStatus();
34 switch ($request->getURIData('action')) {
35 case 'enable':
36 if ($old_status === PhortuneAccountEmailStatus::STATUS_ACTIVE) {
37 return $this->newDialog()
38 ->setTitle(pht('Already Enabled'))
39 ->appendParagraph(
40 pht(
41 'You can not enable this address because it is already '.
42 'active.'))
43 ->addCancelButton($address_uri);
44 }
45
46 if ($old_status === PhortuneAccountEmailStatus::STATUS_UNSUBSCRIBED) {
47 return $this->newDialog()
48 ->setTitle(pht('Permanently Unsubscribed'))
49 ->appendParagraph(
50 pht(
51 'You can not enable this address because it has been '.
52 'permanently unsubscribed.'))
53 ->addCancelButton($address_uri);
54 }
55
56 $new_status = PhortuneAccountEmailStatus::STATUS_ACTIVE;
57 $is_enable = true;
58 break;
59 case 'disable':
60 if ($old_status === PhortuneAccountEmailStatus::STATUS_DISABLED) {
61 return $this->newDialog()
62 ->setTitle(pht('Already Disabled'))
63 ->appendParagraph(
64 pht(
65 'You can not disabled this address because it is already '.
66 'disabled.'))
67 ->addCancelButton($address_uri);
68 }
69
70 if ($old_status === PhortuneAccountEmailStatus::STATUS_UNSUBSCRIBED) {
71 return $this->newDialog()
72 ->setTitle(pht('Permanently Unsubscribed'))
73 ->appendParagraph(
74 pht(
75 'You can not disable this address because it has been '.
76 'permanently unsubscribed.'))
77 ->addCancelButton($address_uri);
78 }
79
80 $new_status = PhortuneAccountEmailStatus::STATUS_DISABLED;
81 $is_disable = true;
82 break;
83 default:
84 return new Aphront404Response();
85 }
86
87 if ($request->isFormOrHisecPost()) {
88 $xactions = array();
89
90 $xactions[] = $address->getApplicationTransactionTemplate()
91 ->setTransactionType(
92 PhortuneAccountEmailStatusTransaction::TRANSACTIONTYPE)
93 ->setNewValue($new_status);
94
95 $address->getApplicationTransactionEditor()
96 ->setActor($viewer)
97 ->setContentSourceFromRequest($request)
98 ->setContinueOnMissingFields(true)
99 ->setContinueOnNoEffect(true)
100 ->setCancelURI($address_uri)
101 ->applyTransactions($address, $xactions);
102
103 return id(new AphrontRedirectResponse())->setURI($address_uri);
104 }
105
106 $dialog = $this->newDialog();
107
108 $body = array();
109
110 if ($is_disable) {
111 $title = pht('Disable Address');
112
113 $body[] = pht(
114 'This address will no longer receive email, and access links will '.
115 'no longer function.');
116
117 $submit = pht('Disable Address');
118 } else {
119 $title = pht('Enable Address');
120
121 $body[] = pht(
122 'This address will receive email again, and existing links '.
123 'to access order history will work again.');
124
125 $submit = pht('Enable Address');
126 }
127
128 foreach ($body as $graph) {
129 $dialog->appendParagraph($graph);
130 }
131
132 return $dialog
133 ->setTitle($title)
134 ->addCancelButton($address_uri)
135 ->addSubmitButton($submit);
136 }
137}