diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -512,6 +512,7 @@ '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 @@ '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 --- /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()); + } + +}