Skip to content

Commit d19fe62

Browse files
committed
feat(wfe): add runtime operations
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
1 parent 0f762a0 commit d19fe62

9 files changed

Lines changed: 528 additions & 6 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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,25 @@ public function register(IRegistrationContext $context): void {
4040
}
4141

4242
public function boot(IBootContext $context): void {
43+
$context->injectFn(Closure::fromCallable([$this, 'emitRuntimeEvent']));
4344
$context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners']));
4445
}
4546

47+
private function emitRuntimeEvent(IEventDispatcher $dispatcher, ContainerInterface $container): void {
48+
/** @var Manager $manager */
49+
$manager = $container->get(Manager::class);
50+
$manager->reloadRuntimeOperations();
51+
}
52+
4653
private function registerRuleListeners(IEventDispatcher $dispatcher,
4754
ContainerInterface $container,
4855
LoggerInterface $logger): void {
4956
/** @var Manager $manager */
5057
$manager = $container->get(Manager::class);
51-
$configuredEvents = $manager->getAllConfiguredEvents();
58+
$configuredEvents = array_merge_recursive(
59+
$manager->getAllConfiguredEvents(),
60+
$manager->getAllConfiguredRuntimeEvents(),
61+
);
5262

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

0 commit comments

Comments
 (0)