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