mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-26 15:30:58 +01:00
Add commenting to Badges
Summary: Fixes T8949. Adds the ability to render honors on those who have fought and received badges of distinction and honor. Test Plan: Write 'asdf'. See 'asdf'. Reviewers: btrahan, epriestley Reviewed By: epriestley Subscribers: epriestley, Korvin Maniphest Tasks: T8949 Differential Revision: https://secure.phabricator.com/D13704
This commit is contained in:
parent
7f2d27fed3
commit
10fb011a49
8 changed files with 123 additions and 3 deletions
18
resources/sql/autopatches/20150724.badges.comments.1.sql
Normal file
18
resources/sql/autopatches/20150724.badges.comments.1.sql
Normal file
|
@ -0,0 +1,18 @@
|
|||
CREATE TABLE {$NAMESPACE}_badges.badges_transaction_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};
|
|
@ -1620,6 +1620,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorBadgeHasRecipientEdgeType' => 'applications/badges/edge/PhabricatorBadgeHasRecipientEdgeType.php',
|
||||
'PhabricatorBadgesApplication' => 'applications/badges/application/PhabricatorBadgesApplication.php',
|
||||
'PhabricatorBadgesBadge' => 'applications/badges/storage/PhabricatorBadgesBadge.php',
|
||||
'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php',
|
||||
'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php',
|
||||
'PhabricatorBadgesCreateCapability' => 'applications/badges/capability/PhabricatorBadgesCreateCapability.php',
|
||||
'PhabricatorBadgesDAO' => 'applications/badges/storage/PhabricatorBadgesDAO.php',
|
||||
|
@ -1638,6 +1639,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorBadgesSchemaSpec' => 'applications/badges/storage/PhabricatorBadgesSchemaSpec.php',
|
||||
'PhabricatorBadgesSearchEngine' => 'applications/badges/query/PhabricatorBadgesSearchEngine.php',
|
||||
'PhabricatorBadgesTransaction' => 'applications/badges/storage/PhabricatorBadgesTransaction.php',
|
||||
'PhabricatorBadgesTransactionComment' => 'applications/badges/storage/PhabricatorBadgesTransactionComment.php',
|
||||
'PhabricatorBadgesTransactionQuery' => 'applications/badges/query/PhabricatorBadgesTransactionQuery.php',
|
||||
'PhabricatorBadgesViewController' => 'applications/badges/controller/PhabricatorBadgesViewController.php',
|
||||
'PhabricatorBarePageUIExample' => 'applications/uiexample/examples/PhabricatorBarePageUIExample.php',
|
||||
|
@ -5373,6 +5375,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFlaggableInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
),
|
||||
'PhabricatorBadgesCommentController' => 'PhabricatorBadgesController',
|
||||
'PhabricatorBadgesController' => 'PhabricatorController',
|
||||
'PhabricatorBadgesCreateCapability' => 'PhabricatorPolicyCapability',
|
||||
'PhabricatorBadgesDAO' => 'PhabricatorLiskDAO',
|
||||
|
@ -5391,6 +5394,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorBadgesSchemaSpec' => 'PhabricatorConfigSchemaSpec',
|
||||
'PhabricatorBadgesSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorBadgesTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'PhabricatorBadgesTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||
'PhabricatorBadgesTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'PhabricatorBadgesViewController' => 'PhabricatorBadgesController',
|
||||
'PhabricatorBarePageUIExample' => 'PhabricatorUIExample',
|
||||
|
|
|
@ -41,6 +41,8 @@ final class PhabricatorBadgesApplication extends PhabricatorApplication {
|
|||
=> 'PhabricatorBadgesListController',
|
||||
'create/'
|
||||
=> 'PhabricatorBadgesEditController',
|
||||
'comment/(?P<id>[1-9]\d*)/'
|
||||
=> 'PhabricatorBadgesCommentController',
|
||||
'edit/(?:(?P<id>\d+)/)?'
|
||||
=> 'PhabricatorBadgesEditController',
|
||||
'view/(?:(?P<id>\d+)/)?'
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorBadgesCommentController
|
||||
extends PhabricatorBadgesController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$viewer = $request->getViewer();
|
||||
$id = $request->getURIData('id');
|
||||
|
||||
if (!$request->isFormPost()) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
$badge = id(new PhabricatorBadgesQuery())
|
||||
->setViewer($viewer)
|
||||
->withIDs(array($id))
|
||||
->executeOne();
|
||||
if (!$badge) {
|
||||
return new Aphront404Response();
|
||||
}
|
||||
|
||||
$is_preview = $request->isPreviewRequest();
|
||||
$draft = PhabricatorDraft::buildFromRequest($request);
|
||||
|
||||
$view_uri = $this->getApplicationURI('view/'.$badge->getID());
|
||||
|
||||
$xactions = array();
|
||||
$xactions[] = id(new PhabricatorBadgesTransaction())
|
||||
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
||||
->attachComment(
|
||||
id(new PhabricatorBadgesTransactionComment())
|
||||
->setContent($request->getStr('comment')));
|
||||
|
||||
$editor = id(new PhabricatorBadgesEditor())
|
||||
->setActor($viewer)
|
||||
->setContinueOnNoEffect($request->isContinueRequest())
|
||||
->setContentSourceFromRequest($request)
|
||||
->setIsPreview($is_preview);
|
||||
|
||||
try {
|
||||
$xactions = $editor->applyTransactions($badge, $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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -52,8 +52,6 @@ final class PhabricatorBadgesViewController
|
|||
$timeline = $this->buildTransactionTimeline(
|
||||
$badge,
|
||||
new PhabricatorBadgesTransactionQuery());
|
||||
$timeline
|
||||
->setShouldTerminate(true);
|
||||
|
||||
$recipient_phids = $badge->getRecipientPHIDs();
|
||||
$recipient_phids = array_reverse($recipient_phids);
|
||||
|
@ -64,12 +62,15 @@ final class PhabricatorBadgesViewController
|
|||
->setHandles($handles)
|
||||
->setUser($viewer);
|
||||
|
||||
$add_comment = $this->buildCommentForm($badge);
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
array(
|
||||
$crumbs,
|
||||
$box,
|
||||
$recipient_list,
|
||||
$timeline,
|
||||
$add_comment,
|
||||
),
|
||||
array(
|
||||
'title' => $title,
|
||||
|
@ -154,4 +155,24 @@ final class PhabricatorBadgesViewController
|
|||
return $view;
|
||||
}
|
||||
|
||||
private function buildCommentForm(PhabricatorBadgesBadge $badge) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
||||
|
||||
$add_comment_header = $is_serious
|
||||
? pht('Add Comment')
|
||||
: pht('Render Honors');
|
||||
|
||||
$draft = PhabricatorDraft::newFromUserAndKey($viewer, $badge->getPHID());
|
||||
|
||||
return id(new PhabricatorApplicationTransactionCommentView())
|
||||
->setUser($viewer)
|
||||
->setObjectPHID($badge->getPHID())
|
||||
->setDraft($draft)
|
||||
->setHeaderText($add_comment_header)
|
||||
->setAction($this->getApplicationURI('/comment/'.$badge->getID().'/'))
|
||||
->setSubmitButtonName(pht('Add Comment'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ final class PhabricatorBadgesEditor
|
|||
$types[] = PhabricatorBadgesTransaction::TYPE_STATUS;
|
||||
$types[] = PhabricatorBadgesTransaction::TYPE_QUALITY;
|
||||
|
||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
||||
$types[] = PhabricatorTransactions::TYPE_EDGE;
|
||||
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
||||
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
||||
|
|
|
@ -19,9 +19,10 @@ final class PhabricatorBadgesTransaction
|
|||
}
|
||||
|
||||
public function getApplicationTransactionCommentObject() {
|
||||
return null;
|
||||
return new PhabricatorBadgesTransactionComment();
|
||||
}
|
||||
|
||||
|
||||
public function getTitle() {
|
||||
$author_phid = $this->getAuthorPHID();
|
||||
$object_phid = $this->getObjectPHID();
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorBadgesTransactionComment
|
||||
extends PhabricatorApplicationTransactionComment {
|
||||
|
||||
public function getApplicationTransactionObject() {
|
||||
return new PhabricatorBadgesTransaction();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue