Path: blob/master/src/applications/differential/xaction/DifferentialRevisionRequestReviewTransaction.php
12256 views
<?php12final class DifferentialRevisionRequestReviewTransaction3extends DifferentialRevisionActionTransaction {45const TRANSACTIONTYPE = 'differential.revision.request';6const ACTIONKEY = 'request-review';78const SOURCE_HARBORMASTER = 'harbormaster';9const SOURCE_AUTHOR = 'author';10const SOURCE_VIEWER = 'viewer';1112protected function getRevisionActionLabel(13DifferentialRevision $revision,14PhabricatorUser $viewer) {1516// See PHI1810. Allow non-authors to "Request Review" on draft revisions17// to promote them out of the draft state. This smoothes over the workflow18// where an author asks for review of an urgent change but has not used19// "Request Review" to skip builds.2021if ($revision->isDraft()) {22if (!$this->isViewerRevisionAuthor($revision, $viewer)) {23return pht('Begin Review Now');24}25}2627return pht('Request Review');28}2930protected function getRevisionActionDescription(31DifferentialRevision $revision,32PhabricatorUser $viewer) {33if ($revision->isDraft()) {34if (!$this->isViewerRevisionAuthor($revision, $viewer)) {35return pht(36'This revision will be moved out of the draft state so you can '.37'review it immediately.');38} else {39return pht(40'This revision will be submitted to reviewers for feedback.');41}42} else {43return pht('This revision will be returned to reviewers for feedback.');44}45}4647protected function getRevisionActionMetadata(48DifferentialRevision $revision,49PhabricatorUser $viewer) {50$map = array();5152if ($revision->isDraft()) {53$action_source = $this->getActorSourceType(54$revision,55$viewer);56$map['promotion.source'] = $action_source;57}5859return $map;60}6162protected function getRevisionActionSubmitButtonText(63DifferentialRevision $revision,64PhabricatorUser $viewer) {6566// See PHI975. When the action stack will promote the revision out of67// draft, change the button text from "Submit Quietly".68if ($revision->isDraft()) {69return pht('Publish Revision');70}7172return null;73}747576public function getColor() {77return 'sky';78}7980protected function getRevisionActionOrder() {81return 200;82}8384public function getActionName() {85return pht('Requested Review');86}8788public function generateOldValue($object) {89return $object->isNeedsReview();90}9192public function applyInternalEffects($object, $value) {93$status_review = DifferentialRevisionStatus::NEEDS_REVIEW;94$object95->setModernRevisionStatus($status_review)96->setShouldBroadcast(true);97}9899protected function validateAction($object, PhabricatorUser $viewer) {100if ($object->isNeedsReview()) {101throw new Exception(102pht(103'You can not request review of this revision because this '.104'revision is already under review and the action would have '.105'no effect.'));106}107108if ($object->isClosed()) {109throw new Exception(110pht(111'You can not request review of this revision because it has '.112'already been closed. You can only request review of open '.113'revisions.'));114}115116$this->getActorSourceType($object, $viewer);117}118119public function getTitle() {120$source = $this->getDraftPromotionSource();121122switch ($source) {123case self::SOURCE_HARBORMASTER:124case self::SOURCE_VIEWER:125case self::SOURCE_AUTHOR:126return pht(127'%s published this revision for review.',128$this->renderAuthor());129default:130return pht(131'%s requested review of this revision.',132$this->renderAuthor());133}134}135136public function getTitleForFeed() {137$source = $this->getDraftPromotionSource();138139switch ($source) {140case self::SOURCE_HARBORMASTER:141case self::SOURCE_VIEWER:142case self::SOURCE_AUTHOR:143return pht(144'%s published %s for review.',145$this->renderAuthor(),146$this->renderObject());147default:148return pht(149'%s requested review of %s.',150$this->renderAuthor(),151$this->renderObject());152}153}154155public function getTransactionTypeForConduit($xaction) {156return 'request-review';157}158159public function getFieldValuesForConduit($object, $data) {160return array();161}162163private function getDraftPromotionSource() {164return $this->getMetadataValue('promotion.source');165}166167private function getActorSourceType(168DifferentialRevision $revision,169PhabricatorUser $viewer) {170171$is_harbormaster = $viewer->isOmnipotent();172$is_author = $this->isViewerRevisionAuthor($revision, $viewer);173$is_draft = $revision->isDraft();174175if ($is_harbormaster) {176// When revisions automatically promote out of "Draft" after builds177// finish, the viewer may be acting as the Harbormaster application.178$source = self::SOURCE_HARBORMASTER;179} else if ($is_author) {180$source = self::SOURCE_AUTHOR;181} else if ($is_draft) {182// Non-authors are allowed to "Request Review" on draft revisions, to183// force them into review immediately.184$source = self::SOURCE_VIEWER;185} else {186throw new Exception(187pht(188'You can not request review of this revision because you are not '.189'the author of the revision and it is not currently a draft.'));190}191192return $source;193}194195}196197198