From a1499ceb8f619124fdf6bcbe5c5042eadb941fb6 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 10 Aug 2015 14:14:52 -0700 Subject: [PATCH] Don't let autoplans be run manually Summary: Ref T8096. Like stop/start, autoplans are pushed into the system from outside (normally by `arc`) so it doesn't make any sense to run them manually. Test Plan: - Tried to run an autoplan from web UI, got an error. - Ran a normal plan from web UI. - Tried to run an autoplan from CLI, got an error. - Ran a noraml plan from CLI. Reviewers: chad Reviewed By: chad Maniphest Tasks: T8096 Differential Revision: https://secure.phabricator.com/D13844 --- .../controller/HarbormasterPlanRunController.php | 10 +++++++++- .../controller/HarbormasterPlanViewController.php | 4 +++- .../management/HarbormasterManagementBuildWorkflow.php | 5 +++++ .../storage/configuration/HarbormasterBuildPlan.php | 9 +++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/applications/harbormaster/controller/HarbormasterPlanRunController.php b/src/applications/harbormaster/controller/HarbormasterPlanRunController.php index 0f5673087d..980c7fad4b 100644 --- a/src/applications/harbormaster/controller/HarbormasterPlanRunController.php +++ b/src/applications/harbormaster/controller/HarbormasterPlanRunController.php @@ -22,6 +22,15 @@ final class HarbormasterPlanRunController extends HarbormasterController { return new Aphront404Response(); } + $cancel_uri = $this->getApplicationURI("plan/{$plan_id}/"); + + if (!$plan->canRunManually()) { + return $this->newDialog() + ->setTitle(pht('Can Not Run Plan')) + ->appendParagraph(pht('This plan can not be run manually.')) + ->addCancelButton($cancel_uri); + } + $e_name = true; $v_name = null; @@ -65,7 +74,6 @@ final class HarbormasterPlanRunController extends HarbormasterController { } $title = pht('Run Build Plan Manually'); - $cancel_uri = $this->getApplicationURI("plan/{$plan_id}/"); $save_button = pht('Run Plan Manually'); $form = id(new PHUIFormLayoutView()) diff --git a/src/applications/harbormaster/controller/HarbormasterPlanViewController.php b/src/applications/harbormaster/controller/HarbormasterPlanViewController.php index da35e389a0..95db4c52c0 100644 --- a/src/applications/harbormaster/controller/HarbormasterPlanViewController.php +++ b/src/applications/harbormaster/controller/HarbormasterPlanViewController.php @@ -289,12 +289,14 @@ final class HarbormasterPlanViewController extends HarbormasterPlanController { ->setIcon('fa-ban')); } + $can_run = ($has_manage && $plan->canRunManually()); + $list->addAction( id(new PhabricatorActionView()) ->setName(pht('Run Plan Manually')) ->setHref($this->getApplicationURI("plan/run/{$id}/")) ->setWorkflow(true) - ->setDisabled(!$has_manage) + ->setDisabled(!$can_run) ->setIcon('fa-play-circle')); return $list; diff --git a/src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php b/src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php index 86b8596fe3..fc0f670633 100644 --- a/src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php +++ b/src/applications/harbormaster/management/HarbormasterManagementBuildWorkflow.php @@ -64,6 +64,11 @@ final class HarbormasterManagementBuildWorkflow pht('Build plan "%s" does not exist.', $plan_id)); } + if (!$plan->canRunManually()) { + throw new PhutilArgumentUsageException( + pht('This build plan can not be run manually.')); + } + $console = PhutilConsole::getConsole(); $buildable = HarbormasterBuildable::initializeNewBuildable($viewer) diff --git a/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php b/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php index 7b15b0034c..cf3d9ee7d7 100644 --- a/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php +++ b/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php @@ -85,6 +85,15 @@ final class HarbormasterBuildPlan extends HarbormasterDAO } + public function canRunManually() { + if ($this->isAutoplan()) { + return false; + } + + return true; + } + + public function getName() { $autoplan = $this->getAutoplan(); if ($autoplan) { -- 2.51.2