mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-19 05:12:41 +01:00
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
This commit is contained in:
parent
029b1b6733
commit
1b61af126f
3 changed files with 27 additions and 44 deletions
|
@ -3,22 +3,16 @@
|
|||
final class PhabricatorSubscriptionsEditController
|
||||
extends PhabricatorController {
|
||||
|
||||
private $phid;
|
||||
private $action;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->phid = idx($data, 'phid');
|
||||
$this->action = idx($data, 'action');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$phid = $request->getURIData('phid');
|
||||
$action = $request->getURIData('action');
|
||||
|
||||
if (!$request->isFormPost()) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
switch ($this->action) {
|
||||
switch ($action) {
|
||||
case 'add':
|
||||
$is_add = true;
|
||||
break;
|
||||
|
@ -29,11 +23,8 @@ final class PhabricatorSubscriptionsEditController
|
|||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$user = $request->getUser();
|
||||
$phid = $this->phid;
|
||||
|
||||
$handle = id(new PhabricatorHandleQuery())
|
||||
->setViewer($user)
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($phid))
|
||||
->executeOne();
|
||||
|
||||
|
@ -45,13 +36,13 @@ final class PhabricatorSubscriptionsEditController
|
|||
// to become more clear?
|
||||
|
||||
$object = id(new PhabricatorProjectQuery())
|
||||
->setViewer($user)
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($phid))
|
||||
->needWatchers(true)
|
||||
->executeOne();
|
||||
} else {
|
||||
$object = id(new PhabricatorObjectQuery())
|
||||
->setViewer($user)
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($phid))
|
||||
->executeOne();
|
||||
}
|
||||
|
@ -63,14 +54,14 @@ final class PhabricatorSubscriptionsEditController
|
|||
$handle->getURI());
|
||||
}
|
||||
|
||||
if ($object->isAutomaticallySubscribed($user->getPHID())) {
|
||||
if ($object->isAutomaticallySubscribed($viewer->getPHID())) {
|
||||
return $this->buildErrorResponse(
|
||||
pht('Automatically Subscribed'),
|
||||
pht('You are automatically subscribed to this object.'),
|
||||
$handle->getURI());
|
||||
}
|
||||
|
||||
if (!$object->shouldAllowSubscription($user->getPHID())) {
|
||||
if (!$object->shouldAllowSubscription($viewer->getPHID())) {
|
||||
return $this->buildErrorResponse(
|
||||
pht('You Can Not Subscribe'),
|
||||
pht('You can not subscribe to this object.'),
|
||||
|
@ -80,11 +71,11 @@ final class PhabricatorSubscriptionsEditController
|
|||
if ($object instanceof PhabricatorApplicationTransactionInterface) {
|
||||
if ($is_add) {
|
||||
$xaction_value = array(
|
||||
'+' => array($user->getPHID()),
|
||||
'+' => array($viewer->getPHID()),
|
||||
);
|
||||
} else {
|
||||
$xaction_value = array(
|
||||
'-' => array($user->getPHID()),
|
||||
'-' => array($viewer->getPHID()),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -93,7 +84,7 @@ final class PhabricatorSubscriptionsEditController
|
|||
->setNewValue($xaction_value);
|
||||
|
||||
$editor = id($object->getApplicationTransactionEditor())
|
||||
->setActor($user)
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect(true)
|
||||
->setContinueOnMissingFields(true)
|
||||
->setContentSourceFromRequest($request);
|
||||
|
@ -107,13 +98,13 @@ final class PhabricatorSubscriptionsEditController
|
|||
// PhabriatorApplicationTransactionInterface.
|
||||
|
||||
$editor = id(new PhabricatorSubscriptionsEditor())
|
||||
->setActor($user)
|
||||
->setActor($viewer)
|
||||
->setObject($object);
|
||||
|
||||
if ($is_add) {
|
||||
$editor->subscribeExplicit(array($user->getPHID()), $explicit = true);
|
||||
$editor->subscribeExplicit(array($viewer->getPHID()), $explicit = true);
|
||||
} else {
|
||||
$editor->unsubscribe(array($user->getPHID()));
|
||||
$editor->unsubscribe(array($viewer->getPHID()));
|
||||
}
|
||||
|
||||
$editor->save();
|
||||
|
@ -126,10 +117,10 @@ final class PhabricatorSubscriptionsEditController
|
|||
|
||||
private function buildErrorResponse($title, $message, $uri) {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
$viewer = $request->getUser();
|
||||
|
||||
$dialog = id(new AphrontDialogView())
|
||||
->setUser($user)
|
||||
->setUser($viewer)
|
||||
->setTitle($title)
|
||||
->appendChild($message)
|
||||
->addCancelButton($uri);
|
||||
|
|
|
@ -8,7 +8,8 @@ final class PhabricatorSubscriptionsListController
|
|||
}
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getUser();
|
||||
$viewer = $request->getViewer();
|
||||
|
||||
$object = id(new PhabricatorObjectQuery())
|
||||
->setViewer($viewer)
|
||||
->withPHIDs(array($request->getURIData('phid')))
|
||||
|
|
|
@ -3,22 +3,13 @@
|
|||
final class PhabricatorSubscriptionsTransactionController
|
||||
extends PhabricatorController {
|
||||
|
||||
private $phid;
|
||||
private $changeType;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->phid = idx($data, 'phid');
|
||||
$this->changeType = idx($data, 'type');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
|
||||
$viewer = $request->getUser();
|
||||
$xaction_phid = $this->phid;
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$phid = $request->getURIData('phid');
|
||||
$type = $request->getURIData('type');
|
||||
|
||||
$xaction = id(new PhabricatorObjectQuery())
|
||||
->withPHIDs(array($xaction_phid))
|
||||
->withPHIDs(array($phid))
|
||||
->setViewer($viewer)
|
||||
->executeOne();
|
||||
if (!$xaction) {
|
||||
|
@ -27,7 +18,7 @@ final class PhabricatorSubscriptionsTransactionController
|
|||
|
||||
$old = $xaction->getOldValue();
|
||||
$new = $xaction->getNewValue();
|
||||
switch ($this->changeType) {
|
||||
switch ($type) {
|
||||
case 'add':
|
||||
$subscriber_phids = array_diff($new, $old);
|
||||
break;
|
||||
|
@ -53,7 +44,7 @@ final class PhabricatorSubscriptionsTransactionController
|
|||
unset($handles[$author_phid]);
|
||||
}
|
||||
|
||||
switch ($this->changeType) {
|
||||
switch ($type) {
|
||||
case 'add':
|
||||
$title = pht(
|
||||
'All %d subscribers added by %s',
|
||||
|
|
Loading…
Reference in a new issue