From bbba6241c2a1f02ddce6d7da05dc2e1c3fefa229 Mon Sep 17 00:00:00 2001 From: lkassianik Date: Thu, 30 Apr 2015 17:38:04 -0700 Subject: [PATCH] Calendar events should support comments Summary: Closes T7956, Calendar events should support comments. Test Plan: Open event, add comment, save, comment should appear in timeline. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T7956 Differential Revision: https://secure.phabricator.com/D12640 --- src/__phutil_library_map__.php | 2 + .../PhabricatorCalendarApplication.php | 2 + ...bricatorCalendarEventCommentController.php | 69 +++++++++++++++++++ ...PhabricatorCalendarEventViewController.php | 15 ++++ .../editor/PhabricatorCalendarEventEditor.php | 3 + 5 files changed, 91 insertions(+) create mode 100644 src/applications/calendar/controller/PhabricatorCalendarEventCommentController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 457be534e8..189da4ee91 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1483,6 +1483,7 @@ phutil_register_library_map(array( 'PhabricatorCalendarDAO' => 'applications/calendar/storage/PhabricatorCalendarDAO.php', 'PhabricatorCalendarEvent' => 'applications/calendar/storage/PhabricatorCalendarEvent.php', 'PhabricatorCalendarEventCancelController' => 'applications/calendar/controller/PhabricatorCalendarEventCancelController.php', + 'PhabricatorCalendarEventCommentController' => 'applications/calendar/controller/PhabricatorCalendarEventCommentController.php', 'PhabricatorCalendarEventEditController' => 'applications/calendar/controller/PhabricatorCalendarEventEditController.php', 'PhabricatorCalendarEventEditor' => 'applications/calendar/editor/PhabricatorCalendarEventEditor.php', 'PhabricatorCalendarEventInvalidEpochException' => 'applications/calendar/exception/PhabricatorCalendarEventInvalidEpochException.php', @@ -4818,6 +4819,7 @@ phutil_register_library_map(array( 'PhabricatorFlaggableInterface', ), 'PhabricatorCalendarEventCancelController' => 'PhabricatorCalendarController', + 'PhabricatorCalendarEventCommentController' => 'PhabricatorCalendarController', 'PhabricatorCalendarEventEditController' => 'PhabricatorCalendarController', 'PhabricatorCalendarEventEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorCalendarEventInvalidEpochException' => 'Exception', diff --git a/src/applications/calendar/application/PhabricatorCalendarApplication.php b/src/applications/calendar/application/PhabricatorCalendarApplication.php index b0b5d817ff..c77e697ae8 100644 --- a/src/applications/calendar/application/PhabricatorCalendarApplication.php +++ b/src/applications/calendar/application/PhabricatorCalendarApplication.php @@ -55,6 +55,8 @@ final class PhabricatorCalendarApplication extends PhabricatorApplication { => 'PhabricatorCalendarEventCancelController', '(?Pjoin|decline|accept)/(?P[1-9]\d*)/' => 'PhabricatorCalendarEventJoinController', + 'comment/(?P[1-9]\d*)/' + => 'PhabricatorCalendarEventCommentController', ), ), ); diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventCommentController.php b/src/applications/calendar/controller/PhabricatorCalendarEventCommentController.php new file mode 100644 index 0000000000..4d31b020c4 --- /dev/null +++ b/src/applications/calendar/controller/PhabricatorCalendarEventCommentController.php @@ -0,0 +1,69 @@ +id = idx($data, 'id'); + } + + public function handleRequest(AphrontRequest $request) { + $user = $request->getUser(); + + if (!$request->isFormPost()) { + return new Aphront400Response(); + } + + $event = id(new PhabricatorCalendarEventQuery()) + ->setViewer($user) + ->withIDs(array($this->id)) + ->executeOne(); + if (!$event) { + return new Aphront404Response(); + } + + $is_preview = $request->isPreviewRequest(); + $draft = PhabricatorDraft::buildFromRequest($request); + + $view_uri = '/'.$event->getMonogram(); + + $xactions = array(); + $xactions[] = id(new PhabricatorCalendarEventTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) + ->attachComment( + id(new PhabricatorCalendarEventTransactionComment()) + ->setContent($request->getStr('comment'))); + + $editor = id(new PhabricatorCalendarEventEditor()) + ->setActor($user) + ->setContinueOnNoEffect($request->isContinueRequest()) + ->setContentSourceFromRequest($request) + ->setIsPreview($is_preview); + + try { + $xactions = $editor->applyTransactions($event, $xactions); + } catch (PhabricatorApplicationTransactionNoEffectException $ex) { + return id(new PhabricatorApplicationTransactionNoEffectResponse()) + ->setCancelURI($view_uri) + ->setException($ex); + } + + if ($draft) { + $draft->replaceOrDelete(); + } + + if ($request->isAjax() && $is_preview) { + return id(new PhabricatorApplicationTransactionResponse()) + ->setViewer($user) + ->setTransactions($xactions) + ->setIsPreview($is_preview); + } else { + return id(new AphrontRedirectResponse()) + ->setURI($view_uri); + } + } + +} diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php index 0019ad0717..32ca36f306 100644 --- a/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarEventViewController.php @@ -43,11 +43,26 @@ final class PhabricatorCalendarEventViewController ->setHeader($header) ->addPropertyList($properties); + $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); + $add_comment_header = $is_serious + ? pht('Add Comment') + : pht('Add To Plate'); + $draft = PhabricatorDraft::newFromUserAndKey($viewer, $event->getPHID()); + $add_comment_form = id(new PhabricatorApplicationTransactionCommentView()) + ->setUser($viewer) + ->setObjectPHID($event->getPHID()) + ->setDraft($draft) + ->setHeaderText($add_comment_header) + ->setAction( + $this->getApplicationURI('/event/comment/'.$event->getID().'/')) + ->setSubmitButtonName(pht('Add Comment')); + return $this->buildApplicationPage( array( $crumbs, $box, $timeline, + $add_comment_form, ), array( 'title' => $page_title, diff --git a/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php b/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php index ea8b006ffd..340facf36c 100644 --- a/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php +++ b/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php @@ -22,6 +22,7 @@ final class PhabricatorCalendarEventEditor $types[] = PhabricatorCalendarEventTransaction::TYPE_CANCEL; $types[] = PhabricatorCalendarEventTransaction::TYPE_INVITE; + $types[] = PhabricatorTransactions::TYPE_COMMENT; $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; @@ -119,6 +120,7 @@ final class PhabricatorCalendarEventEditor $object->setIsCancelled((int)$xaction->getNewValue()); return; case PhabricatorCalendarEventTransaction::TYPE_INVITE: + case PhabricatorTransactions::TYPE_COMMENT: case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: case PhabricatorTransactions::TYPE_EDGE: @@ -167,6 +169,7 @@ final class PhabricatorCalendarEventEditor ->save(); } return; + case PhabricatorTransactions::TYPE_COMMENT: case PhabricatorTransactions::TYPE_VIEW_POLICY: case PhabricatorTransactions::TYPE_EDIT_POLICY: case PhabricatorTransactions::TYPE_EDGE: