1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-02-23 03:59:25 +01:00

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
This commit is contained in:
epriestley 2013-07-28 17:58:34 -07:00
parent d4b24a2c07
commit b6130ad49e
6 changed files with 83 additions and 110 deletions

View file

@ -1874,7 +1874,6 @@ phutil_register_library_map(array(
'PonderAnswerEditController' => 'applications/ponder/controller/PonderAnswerEditController.php', 'PonderAnswerEditController' => 'applications/ponder/controller/PonderAnswerEditController.php',
'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php', 'PonderAnswerEditor' => 'applications/ponder/editor/PonderAnswerEditor.php',
'PonderAnswerListView' => 'applications/ponder/view/PonderAnswerListView.php', 'PonderAnswerListView' => 'applications/ponder/view/PonderAnswerListView.php',
'PonderAnswerPreviewController' => 'applications/ponder/controller/PonderAnswerPreviewController.php',
'PonderAnswerQuery' => 'applications/ponder/query/PonderAnswerQuery.php', 'PonderAnswerQuery' => 'applications/ponder/query/PonderAnswerQuery.php',
'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php', 'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php',
'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php', 'PonderAnswerTransaction' => 'applications/ponder/storage/PonderAnswerTransaction.php',
@ -1887,7 +1886,6 @@ phutil_register_library_map(array(
'PonderCommentListView' => 'applications/ponder/view/PonderCommentListView.php', 'PonderCommentListView' => 'applications/ponder/view/PonderCommentListView.php',
'PonderCommentMail' => 'applications/ponder/mail/PonderCommentMail.php', 'PonderCommentMail' => 'applications/ponder/mail/PonderCommentMail.php',
'PonderCommentQuery' => 'applications/ponder/query/PonderCommentQuery.php', 'PonderCommentQuery' => 'applications/ponder/query/PonderCommentQuery.php',
'PonderCommentSaveController' => 'applications/ponder/controller/PonderCommentSaveController.php',
'PonderConstants' => 'applications/ponder/constants/PonderConstants.php', 'PonderConstants' => 'applications/ponder/constants/PonderConstants.php',
'PonderController' => 'applications/ponder/controller/PonderController.php', 'PonderController' => 'applications/ponder/controller/PonderController.php',
'PonderDAO' => 'applications/ponder/storage/PonderDAO.php', 'PonderDAO' => 'applications/ponder/storage/PonderDAO.php',
@ -1898,6 +1896,7 @@ phutil_register_library_map(array(
'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php', 'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php',
'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php', 'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php',
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php',
'PonderQuestionDetailView' => 'applications/ponder/view/PonderQuestionDetailView.php', 'PonderQuestionDetailView' => 'applications/ponder/view/PonderQuestionDetailView.php',
'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php', 'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php',
'PonderQuestionEditor' => 'applications/ponder/editor/PonderQuestionEditor.php', 'PonderQuestionEditor' => 'applications/ponder/editor/PonderQuestionEditor.php',
@ -3999,7 +3998,6 @@ phutil_register_library_map(array(
'PonderAnswerEditController' => 'PonderController', 'PonderAnswerEditController' => 'PonderController',
'PonderAnswerEditor' => 'PhabricatorApplicationTransactionEditor', 'PonderAnswerEditor' => 'PhabricatorApplicationTransactionEditor',
'PonderAnswerListView' => 'AphrontView', 'PonderAnswerListView' => 'AphrontView',
'PonderAnswerPreviewController' => 'PonderController',
'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PonderAnswerQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PonderAnswerSaveController' => 'PonderController', 'PonderAnswerSaveController' => 'PonderController',
'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction', 'PonderAnswerTransaction' => 'PhabricatorApplicationTransaction',
@ -4016,7 +4014,6 @@ phutil_register_library_map(array(
'PonderCommentListView' => 'AphrontView', 'PonderCommentListView' => 'AphrontView',
'PonderCommentMail' => 'PonderMail', 'PonderCommentMail' => 'PonderMail',
'PonderCommentQuery' => 'PhabricatorQuery', 'PonderCommentQuery' => 'PhabricatorQuery',
'PonderCommentSaveController' => 'PonderController',
'PonderController' => 'PhabricatorController', 'PonderController' => 'PhabricatorController',
'PonderDAO' => 'PhabricatorLiskDAO', 'PonderDAO' => 'PhabricatorLiskDAO',
'PonderLiterals' => 'PonderConstants', 'PonderLiterals' => 'PonderConstants',
@ -4034,6 +4031,7 @@ phutil_register_library_map(array(
4 => 'PhabricatorPolicyInterface', 4 => 'PhabricatorPolicyInterface',
5 => 'PhabricatorTokenReceiverInterface', 5 => 'PhabricatorTokenReceiverInterface',
), ),
'PonderQuestionCommentController' => 'PonderController',
'PonderQuestionDetailView' => 'AphrontView', 'PonderQuestionDetailView' => 'AphrontView',
'PonderQuestionEditController' => 'PonderController', 'PonderQuestionEditController' => 'PonderController',
'PonderQuestionEditor' => 'PhabricatorApplicationTransactionEditor', 'PonderQuestionEditor' => 'PhabricatorApplicationTransactionEditor',

View file

@ -53,12 +53,11 @@ final class PhabricatorApplicationPonder extends PhabricatorApplication {
'answer/add/' => 'PonderAnswerSaveController', 'answer/add/' => 'PonderAnswerSaveController',
'answer/edit/(?P<id>\d+)/' => 'PonderAnswerEditController', 'answer/edit/(?P<id>\d+)/' => 'PonderAnswerEditController',
'answer/comment/(?P<id>\d+)/' => 'PonderAnswerCommentController', 'answer/comment/(?P<id>\d+)/' => 'PonderAnswerCommentController',
'answer/preview/' => 'PonderAnswerPreviewController',
'question/edit/(?:(?P<id>\d+)/)?' => 'PonderQuestionEditController', 'question/edit/(?:(?P<id>\d+)/)?' => 'PonderQuestionEditController',
'question/comment/(?P<id>\d+)/' => 'PonderQuestionCommentController',
'question/preview/' => 'PonderQuestionPreviewController', 'question/preview/' => 'PonderQuestionPreviewController',
'question/(?P<status>open|close)/(?P<id>[1-9]\d*)/' => 'question/(?P<status>open|close)/(?P<id>[1-9]\d*)/' =>
'PonderQuestionStatusController', 'PonderQuestionStatusController',
'comment/add/' => 'PonderCommentSaveController',
'(?P<kind>question)/vote/' => 'PonderVoteSaveController', '(?P<kind>question)/vote/' => 'PonderVoteSaveController',
'(?P<kind>answer)/vote/' => 'PonderVoteSaveController' '(?P<kind>answer)/vote/' => 'PonderVoteSaveController'
), ),

View file

@ -1,40 +0,0 @@
<?php
final class PonderAnswerPreviewController
extends PonderController {
public function processRequest() {
$request = $this->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());
}
}

View file

@ -1,62 +0,0 @@
<?php
final class PonderCommentSaveController extends PonderController {
public function processRequest() {
$request = $this->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())));
}
}

View file

@ -0,0 +1,70 @@
<?php
final class PonderQuestionCommentController extends PonderController {
private $id;
public function willProcessRequest(array $data) {
$this->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);
}
}
}

View file

@ -152,6 +152,7 @@ final class PonderQuestionViewController extends PonderController {
private function buildQuestionTransactions(PonderQuestion $question) { private function buildQuestionTransactions(PonderQuestion $question) {
$viewer = $this->getRequest()->getUser(); $viewer = $this->getRequest()->getUser();
$id = $question->getID();
$xactions = id(new PonderQuestionTransactionQuery()) $xactions = id(new PonderQuestionTransactionQuery())
->setViewer($viewer) ->setViewer($viewer)
@ -174,9 +175,16 @@ final class PonderQuestionViewController extends PonderController {
->setTransactions($xactions) ->setTransactions($xactions)
->setMarkupEngine($engine); ->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) { private function buildAnswers(array $answers) {