From c77a77d584bff98d9bc335d61ab3f46372954a90 Mon Sep 17 00:00:00 2001 From: Andrew Paxley Date: Thu, 9 Nov 2023 20:22:59 +1300 Subject: [PATCH] Flip canView logic and combine into taskEnabled check --- src/Dev/TaskRunner.php | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/Dev/TaskRunner.php b/src/Dev/TaskRunner.php index 465db9fcc4b..4b514cb601f 100644 --- a/src/Dev/TaskRunner.php +++ b/src/Dev/TaskRunner.php @@ -118,8 +118,8 @@ public function runTask($request) $inst = Injector::inst()->create($task['class']); $title(sprintf('Running Task %s', $inst->getTitle())); - if (!$inst->isEnabled()) { - $message('The task is disabled'); + if (!$this->taskEnabled($task['class'])) { + $message('The task is disabled or you do not have sufficient permission to run it'); return; } @@ -162,7 +162,7 @@ protected function getTaskList(): array { $taskClasses = ClassInfo::subclassesFor(BuildTask::class, false); foreach ($taskClasses as $index => $task) { - if (!$this->taskEnabled($task) || !$this->canViewTask($task)) { + if (!$this->taskEnabled($task)) { unset($taskClasses[$index]); } } @@ -179,30 +179,18 @@ protected function taskEnabled($class) $reflectionClass = new ReflectionClass($class); if ($reflectionClass->isAbstract()) { return false; - } elseif (!singleton($class)->isEnabled()) { - return false; - } - - return true; - } - - protected function canViewTask(string $class): bool - { - if ($this->canViewAllTasks()) { - return true; } - $reflectionClass = new ReflectionClass($class); - if ($reflectionClass->isAbstract()) { + $task = Injector::inst()->get($class); + if (!$task->isEnabled()) { return false; } - $task = Injector::inst()->get($class); - if (!$task->hasMethod('canView') || !$task->canView()) { + if ($task->hasMethod('canView') && !$task->canView()) { return false; } - return true; + return $this->canViewAllTasks(); } protected function canViewAllTasks(): bool @@ -254,7 +242,7 @@ public function providePermissions(): array return [ 'BUILDTASK_CAN_RUN' => [ 'name' => _t(__CLASS__ . '.BUILDTASK_CAN_RUN_DESCRIPTION', 'Can view and execute all /dev/tasks'), - 'help' => _t(__CLASS__ . '.BUILDTASK_CAN_RUN_HELP', 'Can view and execute all Build Tasks (/dev/tasks). This supersedes individual task permissions'), + 'help' => _t(__CLASS__ . '.BUILDTASK_CAN_RUN_HELP', 'Can view and execute all Build Tasks (/dev/tasks). This may still be overriden by individual task view permissions'), 'category' => DevelopmentAdmin::permissionsCategory(), 'sort' => 70 ],