From dc2dab94bbda62f12461fb673060b26168656b69 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Thu, 31 Mar 2016 15:29:42 -0700 Subject: [PATCH] Add commenting to Fund Summary: Adds basic commenting to Fund Initiatives. Test Plan: Leave a comment, see comment. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D15554 --- .../autopatches/20160331.fund.comments.1.sql | 18 ++++++ src/__phutil_library_map__.php | 4 ++ .../PhabricatorFundApplication.php | 1 + .../FundInitiativeCommentController.php | 63 +++++++++++++++++++ .../FundInitiativeViewController.php | 31 ++++++++- .../fund/editor/FundInitiativeEditor.php | 1 + .../storage/FundInitiativeTransaction.php | 2 +- .../FundInitiativeTransactionComment.php | 10 +++ 8 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 resources/sql/autopatches/20160331.fund.comments.1.sql create mode 100644 src/applications/fund/controller/FundInitiativeCommentController.php create mode 100644 src/applications/fund/storage/FundInitiativeTransactionComment.php diff --git a/resources/sql/autopatches/20160331.fund.comments.1.sql b/resources/sql/autopatches/20160331.fund.comments.1.sql new file mode 100644 index 0000000000..a4c1e2b5fa --- /dev/null +++ b/resources/sql/autopatches/20160331.fund.comments.1.sql @@ -0,0 +1,18 @@ +CREATE TABLE {$NAMESPACE}_fund.fund_initiativetransaction_comment ( + id INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT, + phid VARCHAR(64) NOT NULL, + transactionPHID VARCHAR(64), + authorPHID VARCHAR(64) NOT NULL, + viewPolicy VARCHAR(64) NOT NULL, + editPolicy VARCHAR(64) NOT NULL, + commentVersion INT UNSIGNED NOT NULL, + content LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT}, + contentSource LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT}, + isDeleted BOOL NOT NULL, + dateCreated INT UNSIGNED NOT NULL, + dateModified INT UNSIGNED NOT NULL, + + UNIQUE KEY `key_phid` (phid), + UNIQUE KEY `key_version` (transactionPHID, commentVersion) + +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index a718c4edfc..c4bc803f52 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1024,6 +1024,7 @@ phutil_register_library_map(array( 'FundInitiative' => 'applications/fund/storage/FundInitiative.php', 'FundInitiativeBackController' => 'applications/fund/controller/FundInitiativeBackController.php', 'FundInitiativeCloseController' => 'applications/fund/controller/FundInitiativeCloseController.php', + 'FundInitiativeCommentController' => 'applications/fund/controller/FundInitiativeCommentController.php', 'FundInitiativeEditController' => 'applications/fund/controller/FundInitiativeEditController.php', 'FundInitiativeEditor' => 'applications/fund/editor/FundInitiativeEditor.php', 'FundInitiativeFulltextEngine' => 'applications/fund/search/FundInitiativeFulltextEngine.php', @@ -1034,6 +1035,7 @@ phutil_register_library_map(array( 'FundInitiativeReplyHandler' => 'applications/fund/mail/FundInitiativeReplyHandler.php', 'FundInitiativeSearchEngine' => 'applications/fund/query/FundInitiativeSearchEngine.php', 'FundInitiativeTransaction' => 'applications/fund/storage/FundInitiativeTransaction.php', + 'FundInitiativeTransactionComment' => 'applications/fund/storage/FundInitiativeTransactionComment.php', 'FundInitiativeTransactionQuery' => 'applications/fund/query/FundInitiativeTransactionQuery.php', 'FundInitiativeViewController' => 'applications/fund/controller/FundInitiativeViewController.php', 'FundSchemaSpec' => 'applications/fund/storage/FundSchemaSpec.php', @@ -5238,6 +5240,7 @@ phutil_register_library_map(array( ), 'FundInitiativeBackController' => 'FundController', 'FundInitiativeCloseController' => 'FundController', + 'FundInitiativeCommentController' => 'FundController', 'FundInitiativeEditController' => 'FundController', 'FundInitiativeEditor' => 'PhabricatorApplicationTransactionEditor', 'FundInitiativeFulltextEngine' => 'PhabricatorFulltextEngine', @@ -5248,6 +5251,7 @@ phutil_register_library_map(array( 'FundInitiativeReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'FundInitiativeSearchEngine' => 'PhabricatorApplicationSearchEngine', 'FundInitiativeTransaction' => 'PhabricatorApplicationTransaction', + 'FundInitiativeTransactionComment' => 'PhabricatorApplicationTransactionComment', 'FundInitiativeTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'FundInitiativeViewController' => 'FundController', 'FundSchemaSpec' => 'PhabricatorConfigSchemaSpec', diff --git a/src/applications/fund/application/PhabricatorFundApplication.php b/src/applications/fund/application/PhabricatorFundApplication.php index 889baca20e..3a26e501e6 100644 --- a/src/applications/fund/application/PhabricatorFundApplication.php +++ b/src/applications/fund/application/PhabricatorFundApplication.php @@ -42,6 +42,7 @@ final class PhabricatorFundApplication extends PhabricatorApplication { '/fund/' => array( '(?:query/(?P[^/]+)/)?' => 'FundInitiativeListController', 'create/' => 'FundInitiativeEditController', + 'comment/(?P[1-9]\d*)/' => 'FundInitiativeCommentController', 'edit/(?:(?P\d+)/)?' => 'FundInitiativeEditController', 'close/(?P\d+)/' => 'FundInitiativeCloseController', 'back/(?P\d+)/' => 'FundInitiativeBackController', diff --git a/src/applications/fund/controller/FundInitiativeCommentController.php b/src/applications/fund/controller/FundInitiativeCommentController.php new file mode 100644 index 0000000000..2c4998a94c --- /dev/null +++ b/src/applications/fund/controller/FundInitiativeCommentController.php @@ -0,0 +1,63 @@ +getViewer(); + $id = $request->getURIData('id'); + + if (!$request->isFormPost()) { + return new Aphront400Response(); + } + + $initiative = id(new FundInitiativeQuery()) + ->setViewer($viewer) + ->withIDs(array($id)) + ->executeOne(); + if (!$initiative) { + return new Aphront404Response(); + } + + $is_preview = $request->isPreviewRequest(); + $draft = PhabricatorDraft::buildFromRequest($request); + + $view_uri = '/'.$initiative->getMonogram(); + + $xactions = array(); + $xactions[] = id(new FundInitiativeTransaction()) + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) + ->attachComment( + id(new FundInitiativeTransactionComment()) + ->setContent($request->getStr('comment'))); + + $editor = id(new FundInitiativeEditor()) + ->setActor($viewer) + ->setContinueOnNoEffect($request->isContinueRequest()) + ->setContentSourceFromRequest($request) + ->setIsPreview($is_preview); + + try { + $xactions = $editor->applyTransactions($initiative, $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($viewer) + ->setTransactions($xactions) + ->setIsPreview($is_preview); + } else { + return id(new AphrontRedirectResponse()) + ->setURI($view_uri); + } + } + +} diff --git a/src/applications/fund/controller/FundInitiativeViewController.php b/src/applications/fund/controller/FundInitiativeViewController.php index a416054ae3..18b123bf3a 100644 --- a/src/applications/fund/controller/FundInitiativeViewController.php +++ b/src/applications/fund/controller/FundInitiativeViewController.php @@ -52,12 +52,16 @@ final class FundInitiativeViewController $timeline = $this->buildTransactionTimeline( $initiative, new FundInitiativeTransactionQuery()); - $timeline->setShouldTerminate(true); + + $add_comment = $this->buildCommentForm($initiative); $view = id(new PHUITwoColumnView()) ->setHeader($header) ->setCurtain($curtain) - ->setMainColumn($timeline) + ->setMainColumn(array( + $timeline, + $add_comment, + )) ->addPropertySection(pht('DETAILS'), $details); return $this->newPage() @@ -160,4 +164,27 @@ final class FundInitiativeViewController return $curtain; } + private function buildCommentForm(FundInitiative $initiative) { + $viewer = $this->getViewer(); + + $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); + + $add_comment_header = $is_serious + ? pht('Add Comment') + : pht('Add Liquidity'); + + $draft = PhabricatorDraft::newFromUserAndKey( + $viewer, $initiative->getPHID()); + + return id(new PhabricatorApplicationTransactionCommentView()) + ->setUser($viewer) + ->setObjectPHID($initiative->getPHID()) + ->setDraft($draft) + ->setHeaderText($add_comment_header) + ->setAction( + $this->getApplicationURI('/comment/'.$initiative->getID().'/')) + ->setSubmitButtonName(pht('Add Comment')); + } + + } diff --git a/src/applications/fund/editor/FundInitiativeEditor.php b/src/applications/fund/editor/FundInitiativeEditor.php index fc07c472ba..40fc6f0174 100644 --- a/src/applications/fund/editor/FundInitiativeEditor.php +++ b/src/applications/fund/editor/FundInitiativeEditor.php @@ -23,6 +23,7 @@ final class FundInitiativeEditor $types[] = FundInitiativeTransaction::TYPE_MERCHANT; $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; $types[] = PhabricatorTransactions::TYPE_EDIT_POLICY; + $types[] = PhabricatorTransactions::TYPE_COMMENT; return $types; } diff --git a/src/applications/fund/storage/FundInitiativeTransaction.php b/src/applications/fund/storage/FundInitiativeTransaction.php index c06d62e229..5c1f8c589d 100644 --- a/src/applications/fund/storage/FundInitiativeTransaction.php +++ b/src/applications/fund/storage/FundInitiativeTransaction.php @@ -27,7 +27,7 @@ final class FundInitiativeTransaction } public function getApplicationTransactionCommentObject() { - return null; + return new FundInitiativeTransactionComment(); } public function getRequiredHandlePHIDs() { diff --git a/src/applications/fund/storage/FundInitiativeTransactionComment.php b/src/applications/fund/storage/FundInitiativeTransactionComment.php new file mode 100644 index 0000000000..3e7330ab2c --- /dev/null +++ b/src/applications/fund/storage/FundInitiativeTransactionComment.php @@ -0,0 +1,10 @@ +