3 final class PhabricatorSubscriptionsEditController
4 extends PhabricatorController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getViewer();
8 $phid = $request->getURIData('phid');
9 $action = $request->getURIData('action');
11 if (!$request->isFormOrHisecPost()) {
12 return new Aphront400Response();
23 return new Aphront400Response();
26 $handle = id(new PhabricatorHandleQuery())
28 ->withPHIDs(array($phid))
31 $object = id(new PhabricatorObjectQuery())
33 ->withPHIDs(array($phid))
36 if (!($object instanceof PhabricatorSubscribableInterface
)) {
37 return $this->buildErrorResponse(
39 pht('This object is not subscribable.'),
43 if ($object->isAutomaticallySubscribed($viewer->getPHID())) {
44 return $this->buildErrorResponse(
45 pht('Automatically Subscribed'),
46 pht('You are automatically subscribed to this object.'),
50 if ($object instanceof PhabricatorApplicationTransactionInterface
) {
52 $xaction_value = array(
53 '+' => array($viewer->getPHID()),
56 $xaction_value = array(
57 '-' => array($viewer->getPHID()),
61 $xaction = id($object->getApplicationTransactionTemplate())
62 ->setTransactionType(PhabricatorTransactions
::TYPE_SUBSCRIBERS
)
63 ->setNewValue($xaction_value);
65 $editor = id($object->getApplicationTransactionEditor())
67 ->setCancelURI($handle->getURI())
68 ->setContinueOnNoEffect(true)
69 ->setContinueOnMissingFields(true)
70 ->setContentSourceFromRequest($request);
72 $editor->applyTransactions($object, array($xaction));
75 // TODO: Eventually, get rid of this once everything implements
76 // PhabricatorApplicationTransactionInterface.
78 $editor = id(new PhabricatorSubscriptionsEditor())
83 $editor->subscribeExplicit(array($viewer->getPHID()), $explicit = true);
85 $editor->unsubscribe(array($viewer->getPHID()));
91 // TODO: We should just render the "Unsubscribe" action and swap it out
92 // in the document for Ajax requests.
93 return id(new AphrontReloadResponse())->setURI($handle->getURI());
96 private function buildErrorResponse($title, $message, $uri) {
97 $request = $this->getRequest();
98 $viewer = $request->getUser();
100 $dialog = id(new AphrontDialogView())
103 ->appendChild($message)
104 ->addCancelButton($uri);
106 return id(new AphrontDialogResponse())->setDialog($dialog);