1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

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
This commit is contained in:
Chad Little 2016-03-31 15:29:42 -07:00
parent 59ef3a31d3
commit dc2dab94bb
8 changed files with 127 additions and 3 deletions

View file

@ -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};

View file

@ -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',

View file

@ -42,6 +42,7 @@ final class PhabricatorFundApplication extends PhabricatorApplication {
'/fund/' => array(
'(?:query/(?P<queryKey>[^/]+)/)?' => 'FundInitiativeListController',
'create/' => 'FundInitiativeEditController',
'comment/(?P<id>[1-9]\d*)/' => 'FundInitiativeCommentController',
'edit/(?:(?P<id>\d+)/)?' => 'FundInitiativeEditController',
'close/(?P<id>\d+)/' => 'FundInitiativeCloseController',
'back/(?P<id>\d+)/' => 'FundInitiativeBackController',

View file

@ -0,0 +1,63 @@
<?php
final class FundInitiativeCommentController
extends FundController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->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);
}
}
}

View file

@ -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'));
}
}

View file

@ -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;
}

View file

@ -27,7 +27,7 @@ final class FundInitiativeTransaction
}
public function getApplicationTransactionCommentObject() {
return null;
return new FundInitiativeTransactionComment();
}
public function getRequiredHandlePHIDs() {

View file

@ -0,0 +1,10 @@
<?php
final class FundInitiativeTransactionComment
extends PhabricatorApplicationTransactionComment {
public function getApplicationTransactionObject() {
return new FundInitiativeTransaction();
}
}