Skip to content

Commit 5741066

Browse files
committed
feat(wfe): add runtime operations
Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com> # Conflicts: # apps/workflowengine/lib/Manager.php
1 parent b2ffaaf commit 5741066

11 files changed

Lines changed: 514 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
@@ -42,15 +42,25 @@ public function register(IRegistrationContext $context): void {
4242

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

49+
private function emitRuntimeEvent(IEventDispatcher $dispatcher, ContainerInterface $container): void {
50+
/** @var Manager $manager */
51+
$manager = $container->get(Manager::class);
52+
$manager->reloadRuntimeOperations();
53+
}
54+
4855
private function registerRuleListeners(IEventDispatcher $dispatcher,
4956
ContainerInterface $container,
5057
LoggerInterface $logger): void {
5158
/** @var Manager $manager */
5259
$manager = $container->get(Manager::class);
53-
$configuredEvents = $manager->getAllConfiguredEvents();
60+
$configuredEvents = array_merge_recursive(
61+
$manager->getAllConfiguredEvents(),
62+
$manager->getAllConfiguredRuntimeEvents(),
63+
);
5464

5565
foreach ($configuredEvents as $operationClass => $events) {
5666
foreach ($events as $entityClass => $eventNames) {
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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 Override;
18+
use Symfony\Component\Console\Command\Command;
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 Command {
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+
$this
36+
->setName('workflows:runtime:list')
37+
->setDescription('Lists configured runtime workflows')
38+
// need to add an optional filtering by app
39+
->addArgument(
40+
'appId',
41+
InputArgument::OPTIONAL,
42+
'Filter runtime workflows by appId',
43+
null
44+
)
45+
->addArgument(
46+
'scope',
47+
InputArgument::OPTIONAL,
48+
'Lists workflows for "admin", "user"',
49+
'admin'
50+
)
51+
->addArgument(
52+
'userId',
53+
InputArgument::OPTIONAL,
54+
'User ID used for user scope and session',
55+
null
56+
);
57+
}
58+
59+
protected function mappedScope(string $scope): int {
60+
return match($scope) {
61+
'admin' => IManager::SCOPE_ADMIN,
62+
'user' => IManager::SCOPE_USER,
63+
default => -1,
64+
};
65+
}
66+
67+
#[Override]
68+
protected function execute(InputInterface $input, OutputInterface $output): int {
69+
$appId = $input->getArgument('appId');
70+
$userId = $input->getArgument('userId');
71+
72+
if ($userId !== null) {
73+
$user = $this->userManager->get($userId);
74+
if (is_null($user)) {
75+
throw new NoUserException("user $userId not found");
76+
}
77+
$this->userSession->setUser($user);
78+
$this->manager->reloadRuntimeOperations();
79+
}
80+
81+
$opsByClass = $this->manager->getAllRuntimeOperations(
82+
new ScopeContext(
83+
$this->mappedScope($input->getArgument('scope')),
84+
$input->getArgument('userId')
85+
),
86+
$appId,
87+
);
88+
89+
foreach ($opsByClass as &$operations) {
90+
foreach ($operations as &$operation) {
91+
$checks = $operation['checks'];
92+
$appId = $operation['appId'];
93+
$decodedChecks = json_decode($checks, true);
94+
$operation['checks'] = $this->manager->getRuntimeChecks($decodedChecks, $appId);
95+
}
96+
unset($operation);
97+
}
98+
unset($operations);
99+
100+
$output->writeln(\json_encode($opsByClass, JSON_PRETTY_PRINT));
101+
return 0;
102+
}
103+
}

0 commit comments

Comments
 (0)