-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathTemplateLoader.php
More file actions
91 lines (80 loc) · 2.56 KB
/
TemplateLoader.php
File metadata and controls
91 lines (80 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Files;
use OCA\Files\Event\LoadSidebar;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
use OCA\Libresign\Helper\ValidateHelper;
use OCA\Libresign\Service\AccountService;
use OCA\Libresign\Service\DocMdp\ConfigService;
use OCA\Libresign\Service\IdentifyMethodService;
use OCP\App\IAppManager;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCP\IAppConfig;
use OCP\IRequest;
use OCP\IUserSession;
use OCP\Util;
/**
* @template-implements IEventListener<Event>
*/
class TemplateLoader implements IEventListener {
public function __construct(
private IRequest $request,
private IUserSession $userSession,
private AccountService $accountService,
private IInitialState $initialState,
private ValidateHelper $validateHelper,
private IdentifyMethodService $identifyMethodService,
private CertificateEngineFactory $certificateEngineFactory,
private IAppConfig $appConfig,
private IAppManager $appManager,
private ConfigService $docMdpConfigService,
) {
}
#[\Override]
public function handle(Event $event): void {
if (!($event instanceof LoadSidebar)) {
return;
}
if (!$this->appManager->isEnabledForUser('libresign')) {
return;
}
foreach ($this->getInitialStatePayload() as $key => $value) {
$this->initialState->provideInitialState($key, $value);
}
Util::addScript(Application::APP_ID, 'libresign-tab');
Util::addStyle(Application::APP_ID, 'libresign-tab');
Util::addStyle(Application::APP_ID, 'icons');
}
protected function getInitialStatePayload(): array {
return [
'certificate_ok' => $this->certificateEngineFactory->getEngine()->isSetupOk(),
'identify_methods' => $this->identifyMethodService->getIdentifyMethodsSettings(),
'signature_flow' => $this->getSignatureFlow(),
'docmdp_config' => $this->docMdpConfigService->getConfig(),
'can_request_sign' => $this->canRequestSign(),
];
}
private function getSignatureFlow(): string {
return $this->appConfig->getValueString(
Application::APP_ID,
'signature_flow',
\OCA\Libresign\Enum\SignatureFlow::NONE->value
);
}
private function canRequestSign(): bool {
try {
$this->validateHelper->canRequestSign($this->userSession->getUser());
return true;
} catch (LibresignException) {
return false;
}
}
}