From 67da5d6e4bcafddb936811e0f01c6853663989be Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Fri, 3 May 2013 15:47:39 -0700 Subject: [PATCH] Add Subscribe option to maniphest Summary: Same as //Subscribe//, //Unsubscribe// and //Automatically Subscribed// in differential. Manually updated library map as windows is fun! Test Plan: Subscribe, Unsubscribe! Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D5809 --- src/__phutil_library_map__.php | 1 + .../PhabricatorApplicationManiphest.php | 2 + .../ManiphestSubscribeController.php | 40 +++++++++++++++++++ .../ManiphestTaskDetailController.php | 23 ++++++++++- .../editor/ManiphestTransactionEditor.php | 34 ++++++++++++++++ 5 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 src/applications/maniphest/controller/ManiphestSubscribeController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 7d2227df74..1dc265f7ac 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -633,6 +633,7 @@ phutil_register_library_map(array( 'ManiphestSavedQueryListController' => 'applications/maniphest/controller/ManiphestSavedQueryListController.php', 'ManiphestSearchIndexer' => 'applications/maniphest/search/ManiphestSearchIndexer.php', 'ManiphestSubpriorityController' => 'applications/maniphest/controller/ManiphestSubpriorityController.php', + 'ManiphestSubscribeController' => 'applications/maniphest/controller/ManiphestSubscribeController.php', 'ManiphestTask' => 'applications/maniphest/storage/ManiphestTask.php', 'ManiphestTaskAuxiliaryStorage' => 'applications/maniphest/storage/ManiphestTaskAuxiliaryStorage.php', 'ManiphestTaskDescriptionChangeController' => 'applications/maniphest/controller/ManiphestTaskDescriptionChangeController.php', diff --git a/src/applications/maniphest/application/PhabricatorApplicationManiphest.php b/src/applications/maniphest/application/PhabricatorApplicationManiphest.php index 335ce73b4e..5baf3e56bb 100644 --- a/src/applications/maniphest/application/PhabricatorApplicationManiphest.php +++ b/src/applications/maniphest/application/PhabricatorApplicationManiphest.php @@ -73,6 +73,8 @@ final class PhabricatorApplicationManiphest extends PhabricatorApplication { 'edit/(?:(?P[1-9]\d*)/)?' => 'ManiphestSavedQueryEditController', 'delete/(?P[1-9]\d*)/' => 'ManiphestSavedQueryDeleteController', ), + 'subscribe/(?Padd|rem)/(?P[1-9]\d*)/' + => 'ManiphestSubscribeController', ), ); } diff --git a/src/applications/maniphest/controller/ManiphestSubscribeController.php b/src/applications/maniphest/controller/ManiphestSubscribeController.php new file mode 100644 index 0000000000..46e7aef934 --- /dev/null +++ b/src/applications/maniphest/controller/ManiphestSubscribeController.php @@ -0,0 +1,40 @@ +id = $data['id']; + $this->action = $data['action']; + } + + public function processRequest() { + + $request = $this->getRequest(); + $user = $request->getUser(); + + $task = id(new ManiphestTask())->load($this->id); + if (!$task) { + return new Aphront404Response(); + } + + switch ($this->action) { + case 'add': + ManiphestTransactionEditor::addCC( + $task, + $user); + break; + case 'rem': + ManiphestTransactionEditor::removeCC( + $task, + $user); + break; + default: + return new Aphront400Response(); + } + + return id(new AphrontRedirectResponse())->setURI('/T'.$task->getID()); + } +} diff --git a/src/applications/maniphest/controller/ManiphestTaskDetailController.php b/src/applications/maniphest/controller/ManiphestTaskDetailController.php index 09637d7c26..ffe573d521 100644 --- a/src/applications/maniphest/controller/ManiphestTaskDetailController.php +++ b/src/applications/maniphest/controller/ManiphestTaskDetailController.php @@ -383,6 +383,8 @@ final class ManiphestTaskDetailController extends ManiphestController { private function buildActionView(ManiphestTask $task) { $viewer = $this->getRequest()->getUser(); + $viewer_phid = $viewer->getPHID(); + $viewer_is_cc = in_array($viewer_phid, $task->getCCPHIDs()); $id = $task->getID(); $phid = $task->getPHID(); @@ -397,12 +399,31 @@ final class ManiphestTaskDetailController extends ManiphestController { ->setIcon('edit') ->setHref($this->getApplicationURI("/task/edit/{$id}/"))); + if ($task->getOwnerPHID() === $viewer_phid) { + $view->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Automatically Subscribed')) + ->setDisabled(true) + ->setIcon('subscribe-auto')); + } else { + $action = $viewer_is_cc ? 'rem' : 'add'; + $name = $viewer_is_cc ? 'Unsubscribe' : 'Subscribe'; + $icon = $viewer_is_cc ? 'subscribe-delete' : 'subscribe-add'; + + $view->addAction( + id(new PhabricatorActionView()) + ->setName(pht($name)) + ->setHref("/maniphest/subscribe/{$action}/{$id}/") + ->setRenderAsForm(true) + ->setUser($viewer) + ->setIcon($icon)); + } + $view->addAction( id(new PhabricatorActionView()) ->setName(pht('Merge Duplicates')) ->setHref("/search/attach/{$phid}/TASK/merge/") ->setWorkflow(true) - ->setWorkflow(true) ->setIcon('merge')); $view->addAction( diff --git a/src/applications/maniphest/editor/ManiphestTransactionEditor.php b/src/applications/maniphest/editor/ManiphestTransactionEditor.php index a31d5eba34..92a76c69b5 100644 --- a/src/applications/maniphest/editor/ManiphestTransactionEditor.php +++ b/src/applications/maniphest/editor/ManiphestTransactionEditor.php @@ -438,5 +438,39 @@ final class ManiphestTransactionEditor extends PhabricatorEditor { return (double)(2 << 32); } + public static function addCC( + ManiphestTask $task, + PhabricatorUser $user) { + $current_ccs = $task->getCCPHIDs(); + $new_ccs = array_merge($current_ccs, array($user->getPHID())); + $transaction = new ManiphestTransaction(); + $transaction->setTaskID($task->getID()); + $transaction->setAuthorPHID($user->getPHID()); + $transaction->setTransactionType(ManiphestTransactionType::TYPE_CCS); + $transaction->setNewValue(array_unique($new_ccs)); + $transaction->setOldValue($current_ccs); + + id(new ManiphestTransactionEditor()) + ->setActor($user) + ->applyTransactions($task, array($transaction)); + } + + public static function removeCC( + ManiphestTask $task, + PhabricatorUser $user) { + $current_ccs = $task->getCCPHIDs(); + $new_ccs = array_diff($current_ccs, array($user->getPHID())); + + $transaction = new ManiphestTransaction(); + $transaction->setTaskID($task->getID()); + $transaction->setAuthorPHID($user->getPHID()); + $transaction->setTransactionType(ManiphestTransactionType::TYPE_CCS); + $transaction->setNewValue(array_unique($new_ccs)); + $transaction->setOldValue($current_ccs); + + id(new ManiphestTransactionEditor()) + ->setActor($user) + ->applyTransactions($task, array($transaction)); + } }