2019-08-23 10:56:24 -04:00
|
|
|
<?php
|
2020-04-09 05:50:14 -04:00
|
|
|
|
2019-08-23 10:56:24 -04:00
|
|
|
declare(strict_types=1);
|
2021-06-04 15:52:51 -04:00
|
|
|
|
2019-08-23 10:56:24 -04:00
|
|
|
/**
|
2024-05-30 14:13:41 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-08-23 10:56:24 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\WorkflowEngine\Settings;
|
|
|
|
|
|
|
|
|
|
use OCA\WorkflowEngine\AppInfo\Application;
|
|
|
|
|
use OCA\WorkflowEngine\Manager;
|
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2021-03-02 13:52:39 -05:00
|
|
|
use OCP\AppFramework\Services\IInitialState;
|
2020-06-18 19:16:53 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2020-03-15 12:32:50 -04:00
|
|
|
use OCP\IConfig;
|
2022-05-19 12:35:32 -04:00
|
|
|
use OCP\IURLGenerator;
|
2019-08-23 10:56:24 -04:00
|
|
|
use OCP\Settings\ISettings;
|
2020-06-18 19:16:53 -04:00
|
|
|
use OCP\WorkflowEngine\Events\LoadSettingsScriptsEvent;
|
2019-09-05 09:52:11 -04:00
|
|
|
use OCP\WorkflowEngine\ICheck;
|
2019-08-27 10:52:00 -04:00
|
|
|
use OCP\WorkflowEngine\IComplexOperation;
|
2019-08-23 10:56:24 -04:00
|
|
|
use OCP\WorkflowEngine\IEntity;
|
|
|
|
|
use OCP\WorkflowEngine\IEntityEvent;
|
2019-08-27 10:52:00 -04:00
|
|
|
use OCP\WorkflowEngine\IOperation;
|
|
|
|
|
use OCP\WorkflowEngine\ISpecificOperation;
|
2019-08-23 10:56:24 -04:00
|
|
|
|
|
|
|
|
abstract class ASettings implements ISettings {
|
|
|
|
|
public function __construct(
|
2025-09-16 08:31:21 -04:00
|
|
|
private readonly IEventDispatcher $eventDispatcher,
|
|
|
|
|
protected readonly Manager $manager,
|
|
|
|
|
private readonly IInitialState $initialStateService,
|
|
|
|
|
private readonly IConfig $config,
|
|
|
|
|
private readonly IURLGenerator $urlGenerator,
|
2019-08-23 10:56:24 -04:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-10 10:51:06 -04:00
|
|
|
abstract public function getScope(): int;
|
2019-08-23 10:56:24 -04:00
|
|
|
|
2021-03-02 13:52:39 -05:00
|
|
|
public function getForm(): TemplateResponse {
|
2020-08-10 08:29:21 -04:00
|
|
|
// @deprecated in 20.0.0: retire this one in favor of the typed event
|
2020-06-18 19:16:53 -04:00
|
|
|
$this->eventDispatcher->dispatch(
|
|
|
|
|
'OCP\WorkflowEngine::loadAdditionalSettingScripts',
|
|
|
|
|
new LoadSettingsScriptsEvent()
|
|
|
|
|
);
|
2020-08-10 08:29:21 -04:00
|
|
|
$this->eventDispatcher->dispatchTyped(new LoadSettingsScriptsEvent());
|
2019-08-23 10:56:24 -04:00
|
|
|
|
|
|
|
|
$entities = $this->manager->getEntitiesList();
|
|
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
|
'entities',
|
|
|
|
|
$this->entitiesToArray($entities)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$operators = $this->manager->getOperatorList();
|
|
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
|
'operators',
|
|
|
|
|
$this->operatorsToArray($operators)
|
|
|
|
|
);
|
|
|
|
|
|
2019-09-05 09:52:11 -04:00
|
|
|
$checks = $this->manager->getCheckList();
|
|
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
|
'checks',
|
|
|
|
|
$this->checksToArray($checks)
|
|
|
|
|
);
|
|
|
|
|
|
2019-08-23 10:56:24 -04:00
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
|
'scope',
|
|
|
|
|
$this->getScope()
|
|
|
|
|
);
|
|
|
|
|
|
2020-03-15 12:32:50 -04:00
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
|
'appstoreenabled',
|
|
|
|
|
$this->config->getSystemValueBool('appstoreenabled', true)
|
|
|
|
|
);
|
|
|
|
|
|
2022-05-19 12:35:32 -04:00
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
|
'doc-url',
|
|
|
|
|
$this->urlGenerator->linkToDocs('admin-workflowengine')
|
|
|
|
|
);
|
|
|
|
|
|
2026-01-27 16:57:24 -05:00
|
|
|
return new TemplateResponse(Application::APP_ID, 'settings', [], TemplateResponse::RENDER_AS_BLANK);
|
2019-08-23 10:56:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-09-16 08:31:21 -04:00
|
|
|
* @return string|null the section ID, e.g. 'sharing'
|
2019-08-23 10:56:24 -04:00
|
|
|
*/
|
2021-03-02 13:52:39 -05:00
|
|
|
public function getSection(): ?string {
|
2019-08-23 10:56:24 -04:00
|
|
|
return 'workflow';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return int whether the form should be rather on the top or bottom of
|
|
|
|
|
* the admin section. The forms are arranged in ascending order of the
|
|
|
|
|
* priority values. It is required to return a value between 0 and 100.
|
|
|
|
|
*
|
|
|
|
|
* E.g.: 70
|
|
|
|
|
*/
|
2021-03-02 13:52:39 -05:00
|
|
|
public function getPriority(): int {
|
2019-08-23 10:56:24 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-16 08:31:21 -04:00
|
|
|
/**
|
|
|
|
|
* @param IEntity[] $entities
|
|
|
|
|
* @return array<array-key, array{id: class-string<IEntity>, icon: string, name: string, events: array<array-key, array{eventName: string, displayName: string}>}>
|
|
|
|
|
*/
|
|
|
|
|
private function entitiesToArray(array $entities): array {
|
|
|
|
|
return array_map(function (IEntity $entity): array {
|
|
|
|
|
$events = array_map(function (IEntityEvent $entityEvent): array {
|
2019-08-23 10:56:24 -04:00
|
|
|
return [
|
|
|
|
|
'eventName' => $entityEvent->getEventName(),
|
|
|
|
|
'displayName' => $entityEvent->getDisplayName()
|
|
|
|
|
];
|
|
|
|
|
}, $entity->getEvents());
|
|
|
|
|
|
|
|
|
|
return [
|
2019-08-27 11:40:00 -04:00
|
|
|
'id' => get_class($entity),
|
2019-08-23 10:56:24 -04:00
|
|
|
'icon' => $entity->getIcon(),
|
|
|
|
|
'name' => $entity->getName(),
|
|
|
|
|
'events' => $events,
|
|
|
|
|
];
|
|
|
|
|
}, $entities);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-16 08:31:21 -04:00
|
|
|
private function operatorsToArray(array $operators): array {
|
|
|
|
|
$operators = array_filter($operators, fn (IOperation $operator): bool => $operator->isAvailableForScope($this->getScope()));
|
2019-08-23 10:56:24 -04:00
|
|
|
|
2019-08-27 10:52:00 -04:00
|
|
|
return array_map(function (IOperation $operator) {
|
2019-08-23 10:56:24 -04:00
|
|
|
return [
|
2019-08-27 10:52:00 -04:00
|
|
|
'id' => get_class($operator),
|
2019-08-23 10:56:24 -04:00
|
|
|
'icon' => $operator->getIcon(),
|
|
|
|
|
'name' => $operator->getDisplayName(),
|
|
|
|
|
'description' => $operator->getDescription(),
|
2019-08-27 10:52:00 -04:00
|
|
|
'fixedEntity' => $operator instanceof ISpecificOperation ? $operator->getEntityId() : '',
|
|
|
|
|
'isComplex' => $operator instanceof IComplexOperation,
|
2019-08-29 06:36:35 -04:00
|
|
|
'triggerHint' => $operator instanceof IComplexOperation ? $operator->getTriggerHint() : '',
|
2019-08-23 10:56:24 -04:00
|
|
|
];
|
|
|
|
|
}, $operators);
|
|
|
|
|
}
|
2019-09-05 09:52:11 -04:00
|
|
|
|
2025-09-16 08:31:21 -04:00
|
|
|
private function checksToArray(array $checks): array {
|
|
|
|
|
$checks = array_filter($checks, fn (ICheck $check): bool => $check->isAvailableForScope($this->getScope()));
|
2019-09-05 09:52:11 -04:00
|
|
|
|
|
|
|
|
return array_map(function (ICheck $check) {
|
|
|
|
|
return [
|
|
|
|
|
'id' => get_class($check),
|
|
|
|
|
'supportedEntities' => $check->supportedEntities(),
|
|
|
|
|
];
|
|
|
|
|
}, $checks);
|
|
|
|
|
}
|
2019-08-23 10:56:24 -04:00
|
|
|
}
|