1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +01:00

Update Legalpad to use comment transactions

Summary: Updates Legalpad to use comment transactions

Test Plan: Leave some comments.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D17867
This commit is contained in:
Chad Little 2017-05-10 15:27:42 -07:00
parent e1a97616cb
commit 28a23e3822
4 changed files with 9 additions and 102 deletions

View file

@ -1404,7 +1404,6 @@ phutil_register_library_map(array(
'LegalpadDefaultViewCapability' => 'applications/legalpad/capability/LegalpadDefaultViewCapability.php', 'LegalpadDefaultViewCapability' => 'applications/legalpad/capability/LegalpadDefaultViewCapability.php',
'LegalpadDocument' => 'applications/legalpad/storage/LegalpadDocument.php', 'LegalpadDocument' => 'applications/legalpad/storage/LegalpadDocument.php',
'LegalpadDocumentBody' => 'applications/legalpad/storage/LegalpadDocumentBody.php', 'LegalpadDocumentBody' => 'applications/legalpad/storage/LegalpadDocumentBody.php',
'LegalpadDocumentCommentController' => 'applications/legalpad/controller/LegalpadDocumentCommentController.php',
'LegalpadDocumentDatasource' => 'applications/legalpad/typeahead/LegalpadDocumentDatasource.php', 'LegalpadDocumentDatasource' => 'applications/legalpad/typeahead/LegalpadDocumentDatasource.php',
'LegalpadDocumentDoneController' => 'applications/legalpad/controller/LegalpadDocumentDoneController.php', 'LegalpadDocumentDoneController' => 'applications/legalpad/controller/LegalpadDocumentDoneController.php',
'LegalpadDocumentEditController' => 'applications/legalpad/controller/LegalpadDocumentEditController.php', 'LegalpadDocumentEditController' => 'applications/legalpad/controller/LegalpadDocumentEditController.php',
@ -6436,7 +6435,6 @@ phutil_register_library_map(array(
'LegalpadDAO', 'LegalpadDAO',
'PhabricatorMarkupInterface', 'PhabricatorMarkupInterface',
), ),
'LegalpadDocumentCommentController' => 'LegalpadController',
'LegalpadDocumentDatasource' => 'PhabricatorTypeaheadDatasource', 'LegalpadDocumentDatasource' => 'PhabricatorTypeaheadDatasource',
'LegalpadDocumentDoneController' => 'LegalpadController', 'LegalpadDocumentDoneController' => 'LegalpadController',
'LegalpadDocumentEditController' => 'LegalpadController', 'LegalpadDocumentEditController' => 'LegalpadController',

View file

@ -57,7 +57,6 @@ final class PhabricatorLegalpadApplication extends PhabricatorApplication {
=> 'LegalpadDocumentListController', => 'LegalpadDocumentListController',
$this->getEditRoutePattern('edit/') $this->getEditRoutePattern('edit/')
=> 'LegalpadDocumentEditController', => 'LegalpadDocumentEditController',
'comment/(?P<id>\d+)/' => 'LegalpadDocumentCommentController',
'view/(?P<id>\d+)/' => 'LegalpadDocumentManageController', 'view/(?P<id>\d+)/' => 'LegalpadDocumentManageController',
'done/' => 'LegalpadDocumentDoneController', 'done/' => 'LegalpadDocumentDoneController',
'verify/(?P<code>[^/]+)/' 'verify/(?P<code>[^/]+)/'

View file

@ -1,72 +0,0 @@
<?php
final class LegalpadDocumentCommentController extends LegalpadController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$document = id(new LegalpadDocumentQuery())
->setViewer($viewer)
->withIDs(array($id))
->needDocumentBodies(true)
->executeOne();
if (!$document) {
return new Aphront404Response();
}
$is_preview = $request->isPreviewRequest();
$draft = PhabricatorDraft::buildFromRequest($request);
$document_uri = $this->getApplicationURI('view/'.$document->getID());
$comment = $request->getStr('comment');
$xactions = array();
if (strlen($comment)) {
$xactions[] = id(new LegalpadTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
->attachComment(
id(new LegalpadTransactionComment())
->setDocumentID($document->getID())
->setLineNumber(0)
->setLineLength(0)
->setContent($comment));
}
$editor = id(new LegalpadDocumentEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect($request->isContinueRequest())
->setIsPreview($is_preview);
try {
$xactions = $editor->applyTransactions($document, $xactions);
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
return id(new PhabricatorApplicationTransactionNoEffectResponse())
->setCancelURI($document_uri)
->setException($ex);
}
if ($draft) {
$draft->replaceOrDelete();
}
if ($request->isAjax() && $is_preview) {
return id(new PhabricatorApplicationTransactionResponse())
->setViewer($viewer)
->setTransactions($xactions)
->setIsPreview($is_preview);
} else {
return id(new AphrontRedirectResponse())->setURI($document_uri);
}
}
}

View file

@ -37,6 +37,7 @@ final class LegalpadDocumentManageController extends LegalpadController {
$document, $document,
new LegalpadTransactionQuery(), new LegalpadTransactionQuery(),
$engine); $engine);
$timeline->setQuoteRef($document->getMonogram());
$title = $document_body->getTitle(); $title = $document_body->getTitle();
@ -50,9 +51,7 @@ final class LegalpadDocumentManageController extends LegalpadController {
$properties = $this->buildPropertyView($document, $engine); $properties = $this->buildPropertyView($document, $engine);
$document_view = $this->buildDocumentView($document, $engine); $document_view = $this->buildDocumentView($document, $engine);
$comment_form_id = celerity_generate_unique_node_id(); $comment_form = $this->buildCommentView($document, $timeline);
$add_comment = $this->buildAddCommentView($document, $comment_form_id);
$crumbs = $this->buildApplicationCrumbs(); $crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb( $crumbs->addTextCrumb(
@ -69,7 +68,7 @@ final class LegalpadDocumentManageController extends LegalpadController {
$properties, $properties,
$document_view, $document_view,
$timeline, $timeline,
$add_comment, $comment_form,
)); ));
return $this->newPage() return $this->newPage()
@ -181,31 +180,14 @@ final class LegalpadDocumentManageController extends LegalpadController {
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY); ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
} }
private function buildAddCommentView( private function buildCommentView(LegalpadDocument $document, $timeline) {
LegalpadDocument $document,
$comment_form_id) {
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$box = id(new LegalpadDocumentEditEngine())
->setViewer($viewer)
->buildEditEngineCommentView($document)
->setTransactionTimeline($timeline);
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $document->getPHID()); return $box;
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
$title = $is_serious
? pht('Add Comment')
: pht('Debate Legislation');
$form = id(new PhabricatorApplicationTransactionCommentView())
->setUser($viewer)
->setObjectPHID($document->getPHID())
->setFormID($comment_form_id)
->setHeaderText($title)
->setDraft($draft)
->setSubmitButtonName(pht('Add Comment'))
->setAction($this->getApplicationURI('/comment/'.$document->getID().'/'))
->setRequestURI($this->getRequest()->getRequestURI());
return $form;
} }
} }