From 10fb011a494d1d71ca62f15b461bbdab89ad7ee1 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Fri, 24 Jul 2015 10:56:08 -0700 Subject: [PATCH] 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 --- .../20150724.badges.comments.1.sql | 18 ++++++ src/__phutil_library_map__.php | 4 ++ .../PhabricatorBadgesApplication.php | 2 + .../PhabricatorBadgesCommentController.php | 63 +++++++++++++++++++ .../PhabricatorBadgesViewController.php | 25 +++++++- .../badges/editor/PhabricatorBadgesEditor.php | 1 + .../storage/PhabricatorBadgesTransaction.php | 3 +- .../PhabricatorBadgesTransactionComment.php | 10 +++ 8 files changed, 123 insertions(+), 3 deletions(-) create mode 100644 resources/sql/autopatches/20150724.badges.comments.1.sql create mode 100644 src/applications/badges/controller/PhabricatorBadgesCommentController.php create mode 100644 src/applications/badges/storage/PhabricatorBadgesTransactionComment.php diff --git a/resources/sql/autopatches/20150724.badges.comments.1.sql b/resources/sql/autopatches/20150724.badges.comments.1.sql new file mode 100644 index 0000000000..1f1579c201 --- /dev/null +++ b/resources/sql/autopatches/20150724.badges.comments.1.sql @@ -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}; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 161914d921..25e303fa8d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/badges/application/PhabricatorBadgesApplication.php b/src/applications/badges/application/PhabricatorBadgesApplication.php index f2f4df0e3f..206c11abef 100644 --- a/src/applications/badges/application/PhabricatorBadgesApplication.php +++ b/src/applications/badges/application/PhabricatorBadgesApplication.php @@ -41,6 +41,8 @@ final class PhabricatorBadgesApplication extends PhabricatorApplication { => 'PhabricatorBadgesListController', 'create/' => 'PhabricatorBadgesEditController', + 'comment/(?P[1-9]\d*)/' + => 'PhabricatorBadgesCommentController', 'edit/(?:(?P\d+)/)?' => 'PhabricatorBadgesEditController', 'view/(?:(?P\d+)/)?' diff --git a/src/applications/badges/controller/PhabricatorBadgesCommentController.php b/src/applications/badges/controller/PhabricatorBadgesCommentController.php new file mode 100644 index 0000000000..a9108fd8dd --- /dev/null +++ b/src/applications/badges/controller/PhabricatorBadgesCommentController.php @@ -0,0 +1,63 @@ +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); + } + } + +} diff --git a/src/applications/badges/controller/PhabricatorBadgesViewController.php b/src/applications/badges/controller/PhabricatorBadgesViewController.php index 2c53e845f7..387b5d1f98 100644 --- a/src/applications/badges/controller/PhabricatorBadgesViewController.php +++ b/src/applications/badges/controller/PhabricatorBadgesViewController.php @@ -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')); + } + } diff --git a/src/applications/badges/editor/PhabricatorBadgesEditor.php b/src/applications/badges/editor/PhabricatorBadgesEditor.php index b69d4991a3..1cc6934b34 100644 --- a/src/applications/badges/editor/PhabricatorBadgesEditor.php +++ b/src/applications/badges/editor/PhabricatorBadgesEditor.php @@ -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; diff --git a/src/applications/badges/storage/PhabricatorBadgesTransaction.php b/src/applications/badges/storage/PhabricatorBadgesTransaction.php index ee25a65eca..e7ab4eab6a 100644 --- a/src/applications/badges/storage/PhabricatorBadgesTransaction.php +++ b/src/applications/badges/storage/PhabricatorBadgesTransaction.php @@ -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(); diff --git a/src/applications/badges/storage/PhabricatorBadgesTransactionComment.php b/src/applications/badges/storage/PhabricatorBadgesTransactionComment.php new file mode 100644 index 0000000000..249a7bcf7b --- /dev/null +++ b/src/applications/badges/storage/PhabricatorBadgesTransactionComment.php @@ -0,0 +1,10 @@ +