@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add Disabled mode to landing revision ui

Summary:
Fixes T4066.

add `isActionDisabled()` to DifferentialLandingStrategy, which also explains why it is so.
Make an appropriate pop-up in the controller.

Also make the whole UI "workflow", and convert `createMenuItems()` to `createMenuItem()` (Singular).

Test Plan: Click "Land to..." button in all kinds of revisions.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Maniphest Tasks: T4066

Differential Revision: https://secure.phabricator.com/D8105

authored by

Aviv Eyal and committed by
epriestley
d0e30882 6b4998bf

+71 -33
+20
src/applications/differential/controller/DifferentialRevisionLandController.php
··· 68 68 return id(new AphrontDialogResponse())->setDialog($dialog); 69 69 } 70 70 71 + $is_disabled = $this->pushStrategy->isActionDisabled( 72 + $viewer, 73 + $revision, 74 + $revision->getRepository()); 75 + if ($is_disabled) { 76 + if (is_string($is_disabled)) { 77 + $explain = $is_disabled; 78 + } else { 79 + $explain = pht("This action is not currently enabled."); 80 + } 81 + $dialog = id(new AphrontDialogView()) 82 + ->setUser($viewer) 83 + ->setTitle(pht("Can't land revision")) 84 + ->appendChild($explain) 85 + ->addCancelButton('/D'.$revision_id); 86 + 87 + return id(new AphrontDialogResponse())->setDialog($dialog); 88 + } 89 + 90 + 71 91 $prompt = hsprintf('%s<br><br>%s', 72 92 pht( 73 93 'This will squash and rebase revision %s, and push it to '.
+12 -11
src/applications/differential/landing/DifferentialLandingActionMenuEventListener.php
··· 1 1 <?php 2 2 3 + /** 4 + * This class adds a "Land this" button to revision view. 5 + */ 3 6 final class DifferentialLandingActionMenuEventListener 4 7 extends PhabricatorEventListener { 5 8 ··· 17 20 18 21 private function handleActionsEvent(PhutilEvent $event) { 19 22 $object = $event->getValue('object'); 20 - 21 - $actions = null; 22 23 if ($object instanceof DifferentialRevision) { 23 - $actions = $this->renderRevisionAction($event); 24 + $this->renderRevisionAction($event); 24 25 } 25 - 26 - $this->addActionMenuItems($event, $actions); 27 26 } 28 27 29 28 private function renderRevisionAction(PhutilEvent $event) { ··· 42 41 ->setAncestorClass('DifferentialLandingStrategy') 43 42 ->loadObjects(); 44 43 foreach ($strategies as $strategy) { 45 - $actions = $strategy->createMenuItems( 46 - $event->getUser(), 47 - $revision, 48 - $repository); 49 - $this->addActionMenuItems($event, $actions); 44 + $viewer = $event->getUser(); 45 + $action = $strategy->createMenuItem($viewer, $revision, $repository); 46 + if ($action == null) 47 + continue; 48 + if ($strategy->isActionDisabled($viewer, $revision, $repository)) { 49 + $action->setDisabled(true); 50 + } 51 + $this->addActionMenuItems($event, $action); 50 52 } 51 53 } 52 54 53 55 } 54 -
+34 -5
src/applications/differential/landing/DifferentialLandingStrategy.php
··· 8 8 PhabricatorRepository $repository); 9 9 10 10 /** 11 - * returns PhabricatorActionView or an array of PhabricatorActionView or null. 11 + * returns PhabricatorActionView or null. 12 12 */ 13 - abstract function createMenuItems( 13 + abstract function createMenuItem( 14 14 PhabricatorUser $viewer, 15 15 DifferentialRevision $revision, 16 16 PhabricatorRepository $repository); ··· 18 18 /** 19 19 * returns PhabricatorActionView which can be attached to the revision view. 20 20 */ 21 - protected function createActionView($revision, $name, $disabled = false) { 21 + protected function createActionView($revision, $name) { 22 22 $strategy = get_class($this); 23 23 $revision_id = $revision->getId(); 24 24 return id(new PhabricatorActionView()) 25 25 ->setRenderAsForm(true) 26 + ->setWorkflow(true) 26 27 ->setName($name) 27 - ->setHref("/differential/revision/land/{$revision_id}/{$strategy}/") 28 - ->setDisabled($disabled); 28 + ->setHref("/differential/revision/land/{$revision_id}/{$strategy}/"); 29 + } 30 + 31 + /** 32 + * Check if this action should be disabled, and explain why. 33 + * 34 + * By default, this method checks for push permissions, and for the 35 + * revision being Accepted. 36 + * 37 + * @return FALSE for "not disabled"; 38 + * Human-readable text explaining why, if it is disabled; 39 + */ 40 + public function isActionDisabled( 41 + PhabricatorUser $viewer, 42 + DifferentialRevision $revision, 43 + PhabricatorRepository $repository) { 44 + 45 + $status = $revision->getStatus(); 46 + if ($status != ArcanistDifferentialRevisionStatus::ACCEPTED) { 47 + return pht("Only Accepted revisions can be landed."); 48 + } 49 + 50 + if (!PhabricatorPolicyFilter::hasCapability( 51 + $viewer, 52 + $repository, 53 + DiffusionCapabilityPush::CAPABILITY)) { 54 + return pht("You do not have permissions to push to this repository."); 55 + } 56 + 57 + return false; 29 58 } 30 59 31 60 /**
+1 -1
src/applications/differential/landing/DifferentialLandingToGitHub.php
··· 47 47 /** 48 48 * returns PhabricatorActionView or an array of PhabricatorActionView or null. 49 49 */ 50 - public function createMenuItems( 50 + public function createMenuItem( 51 51 PhabricatorUser $viewer, 52 52 DifferentialRevision $revision, 53 53 PhabricatorRepository $repository) {
+2 -8
src/applications/differential/landing/DifferentialLandingToHostedGit.php
··· 105 105 $workspace->execxLocal("push origin HEAD:master"); 106 106 } 107 107 108 - public function createMenuItems( 108 + public function createMenuItem( 109 109 PhabricatorUser $viewer, 110 110 DifferentialRevision $revision, 111 111 PhabricatorRepository $repository) { ··· 123 123 return; 124 124 } 125 125 126 - $can_push = PhabricatorPolicyFilter::hasCapability( 127 - $viewer, 128 - $repository, 129 - DiffusionCapabilityPush::CAPABILITY); 130 - 131 126 return $this->createActionView( 132 127 $revision, 133 - pht('Land to Hosted Repository'), 134 - !$can_push); 128 + pht('Land to Hosted Repository')); 135 129 } 136 130 }
+2 -8
src/applications/differential/landing/DifferentialLandingToHostedMercurial.php
··· 93 93 $workspace->execxLocal("push -b default"); 94 94 } 95 95 96 - public function createMenuItems( 96 + public function createMenuItem( 97 97 PhabricatorUser $viewer, 98 98 DifferentialRevision $revision, 99 99 PhabricatorRepository $repository) { ··· 107 107 return; 108 108 } 109 109 110 - $can_push = PhabricatorPolicyFilter::hasCapability( 111 - $viewer, 112 - $repository, 113 - DiffusionCapabilityPush::CAPABILITY); 114 - 115 110 return $this->createActionView( 116 111 $revision, 117 - pht('Land to Hosted Repository'), 118 - !$can_push); 112 + pht('Land to Hosted Repository')); 119 113 } 120 114 }