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: