Skip to content

Commit f55b3fb

Browse files
authored
Merge pull request #59966 from nextcloud/feature/workflow-app-rules
Add runtime operations in WFE
2 parents 4082691 + 2a9036a commit f55b3fb

14 files changed

Lines changed: 619 additions & 9 deletions

File tree

apps/workflowengine/appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
<commands>
4343
<command>OCA\WorkflowEngine\Command\Index</command>
44+
<command>OCA\WorkflowEngine\Command\Runtime</command>
4445
</commands>
4546

4647
<settings>

apps/workflowengine/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'OCA\\WorkflowEngine\\Check\\TFileCheck' => $baseDir . '/../lib/Check/TFileCheck.php',
2222
'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => $baseDir . '/../lib/Check/UserGroupMembership.php',
2323
'OCA\\WorkflowEngine\\Command\\Index' => $baseDir . '/../lib/Command/Index.php',
24+
'OCA\\WorkflowEngine\\Command\\Runtime' => $baseDir . '/../lib/Command/Runtime.php',
2425
'OCA\\WorkflowEngine\\Controller\\AWorkflowOCSController' => $baseDir . '/../lib/Controller/AWorkflowOCSController.php',
2526
'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => $baseDir . '/../lib/Controller/GlobalWorkflowsController.php',
2627
'OCA\\WorkflowEngine\\Controller\\RequestTimeController' => $baseDir . '/../lib/Controller/RequestTimeController.php',

apps/workflowengine/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ComposerStaticInitWorkflowEngine
3636
'OCA\\WorkflowEngine\\Check\\TFileCheck' => __DIR__ . '/..' . '/../lib/Check/TFileCheck.php',
3737
'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => __DIR__ . '/..' . '/../lib/Check/UserGroupMembership.php',
3838
'OCA\\WorkflowEngine\\Command\\Index' => __DIR__ . '/..' . '/../lib/Command/Index.php',
39+
'OCA\\WorkflowEngine\\Command\\Runtime' => __DIR__ . '/..' . '/../lib/Command/Runtime.php',
3940
'OCA\\WorkflowEngine\\Controller\\AWorkflowOCSController' => __DIR__ . '/..' . '/../lib/Controller/AWorkflowOCSController.php',
4041
'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => __DIR__ . '/..' . '/../lib/Controller/GlobalWorkflowsController.php',
4142
'OCA\\WorkflowEngine\\Controller\\RequestTimeController' => __DIR__ . '/..' . '/../lib/Controller/RequestTimeController.php',

apps/workflowengine/lib/AppInfo/Application.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,23 @@ public function register(IRegistrationContext $context): void {
4242

4343
#[\Override]
4444
public function boot(IBootContext $context): void {
45+
$context->injectFn(Closure::fromCallable([$this, 'registerRuntimeOperations']));
4546
$context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners']));
4647
}
4748

49+
private function registerRuntimeOperations(Manager $manager): void {
50+
$manager->reloadRuntimeOperations();
51+
}
52+
4853
private function registerRuleListeners(IEventDispatcher $dispatcher,
4954
ContainerInterface $container,
5055
LoggerInterface $logger): void {
5156
/** @var Manager $manager */
5257
$manager = $container->get(Manager::class);
53-
$configuredEvents = $manager->getAllConfiguredEvents();
58+
$configuredEvents = array_merge_recursive(
59+
$manager->getAllConfiguredEvents(),
60+
$manager->getAllConfiguredRuntimeEvents(),
61+
);
5462

5563
foreach ($configuredEvents as $operationClass => $events) {
5664
foreach ($events as $entityClass => $eventNames) {
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
namespace OCA\WorkflowEngine\Command;
10+
11+
use OC\Core\Command\Base;
12+
use OC\User\NoUserException;
13+
use OCA\WorkflowEngine\Helper\ScopeContext;
14+
use OCA\WorkflowEngine\Manager;
15+
use OCP\IUserManager;
16+
use OCP\IUserSession;
17+
use OCP\WorkflowEngine\IManager;
18+
use Override;
19+
use Symfony\Component\Console\Input\InputArgument;
20+
use Symfony\Component\Console\Input\InputInterface;
21+
use Symfony\Component\Console\Output\OutputInterface;
22+
23+
class Runtime extends Base {
24+
25+
public function __construct(
26+
private Manager $manager,
27+
private IUserManager $userManager,
28+
private IUserSession $userSession,
29+
) {
30+
parent::__construct();
31+
}
32+
33+
#[Override]
34+
protected function configure() {
35+
parent::configure();
36+
$this
37+
->setName('workflows:runtime:list')
38+
->setDescription('Lists configured runtime workflows')
39+
// need to add an optional filtering by app
40+
->addArgument(
41+
'appId',
42+
InputArgument::OPTIONAL,
43+
'Filter runtime workflows by appId',
44+
null
45+
)
46+
->addArgument(
47+
'scope',
48+
InputArgument::OPTIONAL,
49+
'Lists workflows for "admin", "user"',
50+
'admin'
51+
)
52+
->addArgument(
53+
'userId',
54+
InputArgument::OPTIONAL,
55+
'User ID used for user scope and session',
56+
null
57+
);
58+
}
59+
60+
protected function mappedScope(string $scope): int {
61+
return match($scope) {
62+
'admin' => IManager::SCOPE_ADMIN,
63+
'user' => IManager::SCOPE_USER,
64+
default => -1,
65+
};
66+
}
67+
68+
#[Override]
69+
protected function execute(InputInterface $input, OutputInterface $output): int {
70+
$appId = $input->getArgument('appId');
71+
$userId = $input->getArgument('userId');
72+
73+
if ($userId !== null) {
74+
$user = $this->userManager->get($userId);
75+
if ($user === null) {
76+
throw new NoUserException("user $userId not found");
77+
}
78+
$this->userSession->setUser($user);
79+
$this->manager->reloadRuntimeOperations();
80+
}
81+
82+
$opsByClass = $this->manager->getAllRuntimeOperations(
83+
new ScopeContext(
84+
$this->mappedScope($input->getArgument('scope')),
85+
$input->getArgument('userId')
86+
),
87+
$appId,
88+
);
89+
90+
foreach ($opsByClass as &$operations) {
91+
foreach ($operations as &$operation) {
92+
$checks = $operation->checks;
93+
$appId = $operation->appId;
94+
$operation = $operation->toArray();
95+
$operation['checks'] = $this->manager->getRuntimeChecks($checks, $appId);
96+
}
97+
unset($operation);
98+
}
99+
unset($operations);
100+
101+
$this->writeArrayInOutputFormat($input, $output, $opsByClass);
102+
103+
return 0;
104+
}
105+
}

0 commit comments

Comments
 (0)