From 8b74cd481a47b1deeb074074a9caedd48201ad12 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 28 Dec 2016 14:34:46 -0800 Subject: [PATCH] Restore "Commandeer" action to Differential on EditEngine Summary: Ref T11114. This has two pieces of side-effect logic which I've noted locally: - Commandeer needs to apply Herald rules. - Commandeer needs to move the old author to become a reviewer and remove the actor as a reviewer. Test Plan: Commandeered some revisions. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11114 Differential Revision: https://secure.phabricator.com/D17111 --- src/__phutil_library_map__.php | 2 + ...ferentialRevisionCommandeerTransaction.php | 67 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/applications/differential/xaction/DifferentialRevisionCommandeerTransaction.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index d4106da800..84f1ae7364 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -512,6 +512,7 @@ phutil_register_library_map(array( 'DifferentialRevisionAuthorProjectsHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php', 'DifferentialRevisionCloseDetailsController' => 'applications/differential/controller/DifferentialRevisionCloseDetailsController.php', 'DifferentialRevisionCloseTransaction' => 'applications/differential/xaction/DifferentialRevisionCloseTransaction.php', + 'DifferentialRevisionCommandeerTransaction' => 'applications/differential/xaction/DifferentialRevisionCommandeerTransaction.php', 'DifferentialRevisionContentAddedHeraldField' => 'applications/differential/herald/DifferentialRevisionContentAddedHeraldField.php', 'DifferentialRevisionContentHeraldField' => 'applications/differential/herald/DifferentialRevisionContentHeraldField.php', 'DifferentialRevisionContentRemovedHeraldField' => 'applications/differential/herald/DifferentialRevisionContentRemovedHeraldField.php', @@ -5185,6 +5186,7 @@ phutil_register_library_map(array( 'DifferentialRevisionAuthorProjectsHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionCloseDetailsController' => 'DifferentialController', 'DifferentialRevisionCloseTransaction' => 'DifferentialRevisionActionTransaction', + 'DifferentialRevisionCommandeerTransaction' => 'DifferentialRevisionActionTransaction', 'DifferentialRevisionContentAddedHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionContentHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionContentRemovedHeraldField' => 'DifferentialRevisionHeraldField', diff --git a/src/applications/differential/xaction/DifferentialRevisionCommandeerTransaction.php b/src/applications/differential/xaction/DifferentialRevisionCommandeerTransaction.php new file mode 100644 index 0000000000..7690b79fff --- /dev/null +++ b/src/applications/differential/xaction/DifferentialRevisionCommandeerTransaction.php @@ -0,0 +1,67 @@ +getAuthorPHID(); + } + + public function generateNewValue($object, $value) { + $actor = $this->getActor(); + return $actor->getPHID(); + } + + public function applyInternalEffects($object, $value) { + $object->setAuthorPHID($value); + } + + protected function validateAction($object, PhabricatorUser $viewer) { + if ($object->isClosed()) { + throw new Exception( + pht( + 'You can not commandeer this revision because it has already '. + 'been closed. You can only commandeer open revisions.')); + } + + if ($this->isViewerRevisionAuthor($object, $viewer)) { + throw new Exception( + pht( + 'You can not commandeer this revision because you are already '. + 'the author.')); + } + } + + public function getTitle() { + return pht( + '%s commandeered this revision.', + $this->renderAuthor()); + } + + public function getTitleForFeed() { + return pht( + '%s commandeered %s.', + $this->renderAuthor(), + $this->renderObject()); + } + +}