From b6130ad49e480cff618d444be6fbf378b19890f3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 28 Jul 2013 17:58:34 -0700 Subject: [PATCH] Restore Ponder question commenting Summary: Ref T3373. Same issues as the other commenting patch; it's huge and the JS is a bit buggy. Backend is fine, though. Test Plan: Made some comments on a question. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3373 Differential Revision: https://secure.phabricator.com/D6610 --- src/__phutil_library_map__.php | 6 +- .../PhabricatorApplicationPonder.php | 3 +- .../PonderAnswerPreviewController.php | 40 ----------- .../PonderCommentSaveController.php | 62 ---------------- .../PonderQuestionCommentController.php | 70 +++++++++++++++++++ .../PonderQuestionViewController.php | 12 +++- 6 files changed, 83 insertions(+), 110 deletions(-) delete mode 100644 src/applications/ponder/controller/PonderAnswerPreviewController.php delete mode 100644 src/applications/ponder/controller/PonderCommentSaveController.php create mode 100644 src/applications/ponder/controller/PonderQuestionCommentController.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 669bf0e0f2..cbaf178d68 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1874,7 +1874,6 @@ phutil_register_library_map(array( 'PonderAnswerEditController' => 'applications/ponder/controller/PonderAnswerEditController.php', 'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php', 'PonderAnswerListView' => 'applications/ponder/view/PonderAnswerListView.php', - 'PonderAnswerPreviewController' => 'applications/ponder/controller/PonderAnswerPreviewController.php', 'PonderAnswerQuery' => 'applications/ponder/query/PonderAnswerQuery.php', 'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php', 'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php', @@ -1887,7 +1886,6 @@ phutil_register_library_map(array( 'PonderCommentListView' => 'applications/ponder/view/PonderCommentListView.php', 'PonderCommentMail' => 'applications/ponder/mail/PonderCommentMail.php', 'PonderCommentQuery' => 'applications/ponder/query/PonderCommentQuery.php', - 'PonderCommentSaveController' => 'applications/ponder/controller/PonderCommentSaveController.php', 'PonderConstants' => 'applications/ponder/constants/PonderConstants.php', 'PonderController' => 'applications/ponder/controller/PonderController.php', 'PonderDAO' => 'applications/ponder/storage/PonderDAO.php', @@ -1898,6 +1896,7 @@ phutil_register_library_map(array( 'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php', 'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php', 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', + 'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php', 'PonderQuestionDetailView' => 'applications/ponder/view/PonderQuestionDetailView.php', 'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php', 'PonderQuestionEditor' => 'applications/ponder/editor/PonderQuestionEditor.php', @@ -3999,7 +3998,6 @@ phutil_register_library_map(array( 'PonderAnswerEditController' => 'PonderController', 'PonderAnswerEditor' => 'PhabricatorApplicationTransactionEditor', 'PonderAnswerListView' => 'AphrontView', - 'PonderAnswerPreviewController' => 'PonderController', 'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PonderAnswerSaveController' => 'PonderController', 'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction', @@ -4016,7 +4014,6 @@ phutil_register_library_map(array( 'PonderCommentListView' => 'AphrontView', 'PonderCommentMail' => 'PonderMail', 'PonderCommentQuery' => 'PhabricatorQuery', - 'PonderCommentSaveController' => 'PonderController', 'PonderController' => 'PhabricatorController', 'PonderDAO' => 'PhabricatorLiskDAO', 'PonderLiterals' => 'PonderConstants', @@ -4034,6 +4031,7 @@ phutil_register_library_map(array( 4 => 'PhabricatorPolicyInterface', 5 => 'PhabricatorTokenReceiverInterface', ), + 'PonderQuestionCommentController' => 'PonderController', 'PonderQuestionDetailView' => 'AphrontView', 'PonderQuestionEditController' => 'PonderController', 'PonderQuestionEditor' => 'PhabricatorApplicationTransactionEditor', diff --git a/src/applications/ponder/application/PhabricatorApplicationPonder.php b/src/applications/ponder/application/PhabricatorApplicationPonder.php index ad2e154407..35c31a95d9 100644 --- a/src/applications/ponder/application/PhabricatorApplicationPonder.php +++ b/src/applications/ponder/application/PhabricatorApplicationPonder.php @@ -53,12 +53,11 @@ final class PhabricatorApplicationPonder extends PhabricatorApplication { 'answer/add/' => 'PonderAnswerSaveController', 'answer/edit/(?P\d+)/' => 'PonderAnswerEditController', 'answer/comment/(?P\d+)/' => 'PonderAnswerCommentController', - 'answer/preview/' => 'PonderAnswerPreviewController', 'question/edit/(?:(?P\d+)/)?' => 'PonderQuestionEditController', + 'question/comment/(?P\d+)/' => 'PonderQuestionCommentController', 'question/preview/' => 'PonderQuestionPreviewController', 'question/(?Popen|close)/(?P[1-9]\d*)/' => 'PonderQuestionStatusController', - 'comment/add/' => 'PonderCommentSaveController', '(?Pquestion)/vote/' => 'PonderVoteSaveController', '(?Panswer)/vote/' => 'PonderVoteSaveController' ), diff --git a/src/applications/ponder/controller/PonderAnswerPreviewController.php b/src/applications/ponder/controller/PonderAnswerPreviewController.php deleted file mode 100644 index 68f400dd0e..0000000000 --- a/src/applications/ponder/controller/PonderAnswerPreviewController.php +++ /dev/null @@ -1,40 +0,0 @@ -getRequest(); - $viewer = $request->getUser(); - $question_id = $request->getInt('question_id'); - - $question = id(new PonderQuestionQuery()) - ->setViewer($viewer) - ->withIDs(array($question_id)) - ->executeOne(); - if (!$question) { - return new Aphront404Response(); - } - - $author_phid = $viewer->getPHID(); - $object_phids = array($author_phid); - $handles = $this->loadViewerHandles($object_phids); - - $answer = new PonderAnswer(); - $answer->setContent($request->getStr('content')); - $answer->setAuthorPHID($author_phid); - - $view = new PonderPostBodyView(); - $view - ->setQuestion($question) - ->setTarget($answer) - ->setPreview(true) - ->setUser($viewer) - ->setHandles($handles) - ->setAction(PonderLiterals::LITERAL_ANSWERED); - - return id(new AphrontAjaxResponse()) - ->setContent($view->render()); - } - -} diff --git a/src/applications/ponder/controller/PonderCommentSaveController.php b/src/applications/ponder/controller/PonderCommentSaveController.php deleted file mode 100644 index a3af847977..0000000000 --- a/src/applications/ponder/controller/PonderCommentSaveController.php +++ /dev/null @@ -1,62 +0,0 @@ -getRequest(); - if (!$request->isFormPost()) { - return new Aphront400Response(); - } - - $user = $request->getUser(); - $question_id = $request->getInt('question_id'); - $question = id(new PonderQuestionQuery()) - ->setViewer($user) - ->withIDs(array($question_id)) - ->executeOne(); - if (!$question) { - return new Aphront404Response(); - } - - $question->attachRelated(); - - $target = $request->getStr('target'); - $objects = id(new PhabricatorObjectHandleData(array($target))) - ->setViewer($user) - ->loadHandles(); - if (!$objects) { - return new Aphront404Response(); - } - - $content = $request->getStr('content'); - - if (!strlen(trim($content))) { - $dialog = new AphrontDialogView(); - $dialog->setUser($request->getUser()); - $dialog->setTitle(pht('Empty Comment')); - $dialog->appendChild(phutil_tag('p', array(), pht( - 'Your comment must not be empty.'))); - $dialog->addCancelButton('/Q'.$question_id); - - return id(new AphrontDialogResponse())->setDialog($dialog); - } - - $res = new PonderComment(); - $res - ->setContent($content) - ->setAuthorPHID($user->getPHID()) - ->setTargetPHID($target); - - id(new PonderCommentEditor()) - ->setQuestion($question) - ->setComment($res) - ->setTargetPHID($target) - ->setActor($user) - ->save(); - - return id(new AphrontRedirectResponse()) - ->setURI( - id(new PhutilURI('/Q'. $question->getID()))); - } - -} diff --git a/src/applications/ponder/controller/PonderQuestionCommentController.php b/src/applications/ponder/controller/PonderQuestionCommentController.php new file mode 100644 index 0000000000..173f277bb7 --- /dev/null +++ b/src/applications/ponder/controller/PonderQuestionCommentController.php @@ -0,0 +1,70 @@ +id = $data['id']; + } + + public function processRequest() { + $request = $this->getRequest(); + $viewer = $request->getUser(); + + if (!$request->isFormPost()) { + return new Aphront400Response(); + } + + $question = id(new PonderQuestionQuery()) + ->setViewer($viewer) + ->withIDs(array($this->id)) + ->executeOne(); + if (!$question) { + return new Aphront404Response(); + } + + $is_preview = $request->isPreviewRequest(); +// $draft = PhabricatorDraft::buildFromRequest($request); + + $qid = $question->getID(); + $view_uri = "Q{$qid}"; + + $xactions = array(); + $xactions[] = id(new PonderQuestionTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) + ->attachComment( + id(new PonderQuestionTransactionComment()) + ->setContent($request->getStr('comment'))); + + $editor = id(new PonderQuestionEditor()) + ->setActor($viewer) + ->setContinueOnNoEffect($request->isContinueRequest()) + ->setContentSourceFromRequest($request) + ->setIsPreview($is_preview); + + try { + $xactions = $editor->applyTransactions($question, $xactions); + } catch (PhabricatorApplicationTransactionNoEffectException $ex) { + return id(new PhabricatorApplicationTransactionNoEffectResponse()) + ->setCancelURI($view_uri) + ->setException($ex); + } + +// if ($draft) { +// $draft->replaceOrDelete(); +// } + + if ($request->isAjax()) { + return id(new PhabricatorApplicationTransactionResponse()) + ->setViewer($viewer) + ->setTransactions($xactions) + ->setIsPreview($is_preview) + ->setAnchorOffset($request->getStr('anchor')); + } else { + return id(new AphrontRedirectResponse()) + ->setURI($view_uri); + } + } + +} diff --git a/src/applications/ponder/controller/PonderQuestionViewController.php b/src/applications/ponder/controller/PonderQuestionViewController.php index 475d6c4634..287b710ea8 100644 --- a/src/applications/ponder/controller/PonderQuestionViewController.php +++ b/src/applications/ponder/controller/PonderQuestionViewController.php @@ -152,6 +152,7 @@ final class PonderQuestionViewController extends PonderController { private function buildQuestionTransactions(PonderQuestion $question) { $viewer = $this->getRequest()->getUser(); + $id = $question->getID(); $xactions = id(new PonderQuestionTransactionQuery()) ->setViewer($viewer) @@ -174,9 +175,16 @@ final class PonderQuestionViewController extends PonderController { ->setTransactions($xactions) ->setMarkupEngine($engine); - // TODO: Add comment form. + $add_comment = id(new PhabricatorApplicationTransactionCommentView()) + ->setUser($viewer) + ->setShowPreview(false) + ->setAction($this->getApplicationURI("/question/comment/{$id}/")) + ->setSubmitButtonName(pht('Comment')); - return $timeline; + return array( + $timeline, + $add_comment, + ); } private function buildAnswers(array $answers) {