Skip to content

Commit 1b61af1

Browse files
committed
Update Subscriptions for handleRequest
Summary: Modernizes Subscriptions Test Plan: Subscribe/Unsubscribe... anything else? Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T8628 Differential Revision: https://secure.phabricator.com/D14630
1 parent 029b1b6 commit 1b61af1

File tree

3 files changed

+27
-44
lines changed

3 files changed

+27
-44
lines changed

src/applications/subscriptions/controller/PhabricatorSubscriptionsEditController.php

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,16 @@
33
final class PhabricatorSubscriptionsEditController
44
extends PhabricatorController {
55

6-
private $phid;
7-
private $action;
8-
9-
public function willProcessRequest(array $data) {
10-
$this->phid = idx($data, 'phid');
11-
$this->action = idx($data, 'action');
12-
}
13-
14-
public function processRequest() {
15-
$request = $this->getRequest();
6+
public function handleRequest(AphrontRequest $request) {
7+
$viewer = $request->getViewer();
8+
$phid = $request->getURIData('phid');
9+
$action = $request->getURIData('action');
1610

1711
if (!$request->isFormPost()) {
1812
return new Aphront400Response();
1913
}
2014

21-
switch ($this->action) {
15+
switch ($action) {
2216
case 'add':
2317
$is_add = true;
2418
break;
@@ -29,11 +23,8 @@ public function processRequest() {
2923
return new Aphront400Response();
3024
}
3125

32-
$user = $request->getUser();
33-
$phid = $this->phid;
34-
3526
$handle = id(new PhabricatorHandleQuery())
36-
->setViewer($user)
27+
->setViewer($viewer)
3728
->withPHIDs(array($phid))
3829
->executeOne();
3930

@@ -45,13 +36,13 @@ public function processRequest() {
4536
// to become more clear?
4637
4738
$object = id(new PhabricatorProjectQuery())
48-
->setViewer($user)
39+
->setViewer($viewer)
4940
->withPHIDs(array($phid))
5041
->needWatchers(true)
5142
->executeOne();
5243
} else {
5344
$object = id(new PhabricatorObjectQuery())
54-
->setViewer($user)
45+
->setViewer($viewer)
5546
->withPHIDs(array($phid))
5647
->executeOne();
5748
}
@@ -63,14 +54,14 @@ public function processRequest() {
6354
$handle->getURI());
6455
}
6556

66-
if ($object->isAutomaticallySubscribed($user->getPHID())) {
57+
if ($object->isAutomaticallySubscribed($viewer->getPHID())) {
6758
return $this->buildErrorResponse(
6859
pht('Automatically Subscribed'),
6960
pht('You are automatically subscribed to this object.'),
7061
$handle->getURI());
7162
}
7263

73-
if (!$object->shouldAllowSubscription($user->getPHID())) {
64+
if (!$object->shouldAllowSubscription($viewer->getPHID())) {
7465
return $this->buildErrorResponse(
7566
pht('You Can Not Subscribe'),
7667
pht('You can not subscribe to this object.'),
@@ -80,11 +71,11 @@ public function processRequest() {
8071
if ($object instanceof PhabricatorApplicationTransactionInterface) {
8172
if ($is_add) {
8273
$xaction_value = array(
83-
'+' => array($user->getPHID()),
74+
'+' => array($viewer->getPHID()),
8475
);
8576
} else {
8677
$xaction_value = array(
87-
'-' => array($user->getPHID()),
78+
'-' => array($viewer->getPHID()),
8879
);
8980
}
9081

@@ -93,7 +84,7 @@ public function processRequest() {
9384
->setNewValue($xaction_value);
9485

9586
$editor = id($object->getApplicationTransactionEditor())
96-
->setActor($user)
87+
->setActor($viewer)
9788
->setContinueOnNoEffect(true)
9889
->setContinueOnMissingFields(true)
9990
->setContentSourceFromRequest($request);
@@ -107,13 +98,13 @@ public function processRequest() {
10798
// PhabriatorApplicationTransactionInterface.
10899

109100
$editor = id(new PhabricatorSubscriptionsEditor())
110-
->setActor($user)
101+
->setActor($viewer)
111102
->setObject($object);
112103

113104
if ($is_add) {
114-
$editor->subscribeExplicit(array($user->getPHID()), $explicit = true);
105+
$editor->subscribeExplicit(array($viewer->getPHID()), $explicit = true);
115106
} else {
116-
$editor->unsubscribe(array($user->getPHID()));
107+
$editor->unsubscribe(array($viewer->getPHID()));
117108
}
118109

119110
$editor->save();
@@ -126,10 +117,10 @@ public function processRequest() {
126117

127118
private function buildErrorResponse($title, $message, $uri) {
128119
$request = $this->getRequest();
129-
$user = $request->getUser();
120+
$viewer = $request->getUser();
130121

131122
$dialog = id(new AphrontDialogView())
132-
->setUser($user)
123+
->setUser($viewer)
133124
->setTitle($title)
134125
->appendChild($message)
135126
->addCancelButton($uri);

src/applications/subscriptions/controller/PhabricatorSubscriptionsListController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ public function shouldAllowPublic() {
88
}
99

1010
public function handleRequest(AphrontRequest $request) {
11-
$viewer = $request->getUser();
11+
$viewer = $request->getViewer();
12+
1213
$object = id(new PhabricatorObjectQuery())
1314
->setViewer($viewer)
1415
->withPHIDs(array($request->getURIData('phid')))

src/applications/subscriptions/controller/PhabricatorSubscriptionsTransactionController.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,13 @@
33
final class PhabricatorSubscriptionsTransactionController
44
extends PhabricatorController {
55

6-
private $phid;
7-
private $changeType;
8-
9-
public function willProcessRequest(array $data) {
10-
$this->phid = idx($data, 'phid');
11-
$this->changeType = idx($data, 'type');
12-
}
13-
14-
public function processRequest() {
15-
$request = $this->getRequest();
16-
17-
$viewer = $request->getUser();
18-
$xaction_phid = $this->phid;
6+
public function handleRequest(AphrontRequest $request) {
7+
$viewer = $request->getViewer();
8+
$phid = $request->getURIData('phid');
9+
$type = $request->getURIData('type');
1910

2011
$xaction = id(new PhabricatorObjectQuery())
21-
->withPHIDs(array($xaction_phid))
12+
->withPHIDs(array($phid))
2213
->setViewer($viewer)
2314
->executeOne();
2415
if (!$xaction) {
@@ -27,7 +18,7 @@ public function processRequest() {
2718

2819
$old = $xaction->getOldValue();
2920
$new = $xaction->getNewValue();
30-
switch ($this->changeType) {
21+
switch ($type) {
3122
case 'add':
3223
$subscriber_phids = array_diff($new, $old);
3324
break;
@@ -53,7 +44,7 @@ public function processRequest() {
5344
unset($handles[$author_phid]);
5445
}
5546

56-
switch ($this->changeType) {
47+
switch ($type) {
5748
case 'add':
5849
$title = pht(
5950
'All %d subscribers added by %s',

0 commit comments

Comments
 (0)