Page MenuHomePhabricator

D8105.id18338.diff
No OneTemporary

D8105.id18338.diff

Index: src/applications/differential/controller/DifferentialRevisionLandController.php
===================================================================
--- src/applications/differential/controller/DifferentialRevisionLandController.php
+++ src/applications/differential/controller/DifferentialRevisionLandController.php
@@ -68,6 +68,26 @@
return id(new AphrontDialogResponse())->setDialog($dialog);
}
+ $is_disabled = $this->pushStrategy->isActionDisabled(
+ $viewer,
+ $revision,
+ $revision->getRepository());
+ if ($is_disabled) {
+ if (is_string($is_disabled)) {
+ $explain = $is_disabled;
+ } else {
+ $explain = pht("This action is not currently enabled.");
+ }
+ $dialog = id(new AphrontDialogView())
+ ->setUser($viewer)
+ ->setTitle(pht("Can't land revision"))
+ ->appendChild($explain)
+ ->addCancelButton('/D'.$revision_id);
+
+ return id(new AphrontDialogResponse())->setDialog($dialog);
+ }
+
+
$prompt = hsprintf('%s<br><br>%s',
pht(
'This will squash and rebase revision %s, and push it to '.
Index: src/applications/differential/landing/DifferentialLandingActionMenuEventListener.php
===================================================================
--- src/applications/differential/landing/DifferentialLandingActionMenuEventListener.php
+++ src/applications/differential/landing/DifferentialLandingActionMenuEventListener.php
@@ -1,5 +1,8 @@
<?php
+/**
+ * This class adds a "Land this" button to revision view.
+ */
final class DifferentialLandingActionMenuEventListener
extends PhabricatorEventListener {
@@ -17,13 +20,9 @@
private function handleActionsEvent(PhutilEvent $event) {
$object = $event->getValue('object');
-
- $actions = null;
if ($object instanceof DifferentialRevision) {
- $actions = $this->renderRevisionAction($event);
+ $this->renderRevisionAction($event);
}
-
- $this->addActionMenuItems($event, $actions);
}
private function renderRevisionAction(PhutilEvent $event) {
@@ -42,13 +41,15 @@
->setAncestorClass('DifferentialLandingStrategy')
->loadObjects();
foreach ($strategies as $strategy) {
- $actions = $strategy->createMenuItems(
- $event->getUser(),
- $revision,
- $repository);
- $this->addActionMenuItems($event, $actions);
+ $viewer = $event->getUser();
+ $action = $strategy->createMenuItem($viewer, $revision, $repository);
+ if ($action == null)
+ continue;
+ if ($strategy->isActionDisabled($viewer, $revision, $repository)) {
+ $action->setDisabled(true);
+ }
+ $this->addActionMenuItems($event, $action);
}
}
}
-
Index: src/applications/differential/landing/DifferentialLandingStrategy.php
===================================================================
--- src/applications/differential/landing/DifferentialLandingStrategy.php
+++ src/applications/differential/landing/DifferentialLandingStrategy.php
@@ -8,9 +8,9 @@
PhabricatorRepository $repository);
/**
- * returns PhabricatorActionView or an array of PhabricatorActionView or null.
+ * returns PhabricatorActionView or null.
*/
- abstract function createMenuItems(
+ abstract function createMenuItem(
PhabricatorUser $viewer,
DifferentialRevision $revision,
PhabricatorRepository $repository);
@@ -18,14 +18,43 @@
/**
* returns PhabricatorActionView which can be attached to the revision view.
*/
- protected function createActionView($revision, $name, $disabled = false) {
+ protected function createActionView($revision, $name) {
$strategy = get_class($this);
$revision_id = $revision->getId();
return id(new PhabricatorActionView())
->setRenderAsForm(true)
+ ->setWorkflow(true)
->setName($name)
- ->setHref("/differential/revision/land/{$revision_id}/{$strategy}/")
- ->setDisabled($disabled);
+ ->setHref("/differential/revision/land/{$revision_id}/{$strategy}/");
+ }
+
+ /**
+ * Check if this action should be disabled, and explain why.
+ *
+ * By default, this method checks for push permissions, and for the
+ * revision being Accepted.
+ *
+ * @return FALSE for "not disabled";
+ * Human-readable text explaining why, if it is disabled;
+ */
+ public function isActionDisabled(
+ PhabricatorUser $viewer,
+ DifferentialRevision $revision,
+ PhabricatorRepository $repository) {
+
+ $status = $revision->getStatus();
+ if ($status != ArcanistDifferentialRevisionStatus::ACCEPTED) {
+ return pht("Only Accepted revisions can be landed.");
+ }
+
+ if (!PhabricatorPolicyFilter::hasCapability(
+ $viewer,
+ $repository,
+ DiffusionCapabilityPush::CAPABILITY)) {
+ return pht("You do not have permissions to push to this repository.");
+ }
+
+ return false;
}
/**
Index: src/applications/differential/landing/DifferentialLandingToGitHub.php
===================================================================
--- src/applications/differential/landing/DifferentialLandingToGitHub.php
+++ src/applications/differential/landing/DifferentialLandingToGitHub.php
@@ -47,7 +47,7 @@
/**
* returns PhabricatorActionView or an array of PhabricatorActionView or null.
*/
- public function createMenuItems(
+ public function createMenuItem(
PhabricatorUser $viewer,
DifferentialRevision $revision,
PhabricatorRepository $repository) {
Index: src/applications/differential/landing/DifferentialLandingToHostedGit.php
===================================================================
--- src/applications/differential/landing/DifferentialLandingToHostedGit.php
+++ src/applications/differential/landing/DifferentialLandingToHostedGit.php
@@ -105,7 +105,7 @@
$workspace->execxLocal("push origin HEAD:master");
}
- public function createMenuItems(
+ public function createMenuItem(
PhabricatorUser $viewer,
DifferentialRevision $revision,
PhabricatorRepository $repository) {
@@ -123,14 +123,8 @@
return;
}
- $can_push = PhabricatorPolicyFilter::hasCapability(
- $viewer,
- $repository,
- DiffusionCapabilityPush::CAPABILITY);
-
return $this->createActionView(
$revision,
- pht('Land to Hosted Repository'),
- !$can_push);
+ pht('Land to Hosted Repository'));
}
}
Index: src/applications/differential/landing/DifferentialLandingToHostedMercurial.php
===================================================================
--- src/applications/differential/landing/DifferentialLandingToHostedMercurial.php
+++ src/applications/differential/landing/DifferentialLandingToHostedMercurial.php
@@ -93,7 +93,7 @@
$workspace->execxLocal("push -b default");
}
- public function createMenuItems(
+ public function createMenuItem(
PhabricatorUser $viewer,
DifferentialRevision $revision,
PhabricatorRepository $repository) {
@@ -107,14 +107,8 @@
return;
}
- $can_push = PhabricatorPolicyFilter::hasCapability(
- $viewer,
- $repository,
- DiffusionCapabilityPush::CAPABILITY);
-
return $this->createActionView(
$revision,
- pht('Land to Hosted Repository'),
- !$can_push);
+ pht('Land to Hosted Repository'));
}
}

File Metadata

Mime Type
text/plain
Expires
Sun, Oct 20, 5:01 AM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6735202
Default Alt Text
D8105.id18338.diff (7 KB)

Event Timeline