-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathAdmin.php
More file actions
101 lines (94 loc) · 6.17 KB
/
Admin.php
File metadata and controls
101 lines (94 loc) · 6.17 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
92
93
94
95
96
97
98
99
100
101
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Settings;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory;
use OCA\Libresign\Service\CertificatePolicyService;
use OCA\Libresign\Service\DocMdpConfigService;
use OCA\Libresign\Service\FooterService;
use OCA\Libresign\Service\IdentifyMethodService;
use OCA\Libresign\Service\SignatureBackgroundService;
use OCA\Libresign\Service\SignatureTextService;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\IAppConfig;
use OCP\Settings\ISettings;
use OCP\Util;
class Admin implements ISettings {
public const PASSWORD_PLACEHOLDER = '••••••••';
public function __construct(
private IInitialState $initialState,
private IdentifyMethodService $identifyMethodService,
private CertificateEngineFactory $certificateEngineFactory,
private CertificatePolicyService $certificatePolicyService,
private IAppConfig $appConfig,
private SignatureTextService $signatureTextService,
private SignatureBackgroundService $signatureBackgroundService,
private FooterService $footerService,
private DocMdpConfigService $docMdpConfigService,
) {
}
#[\Override]
public function getForm(): TemplateResponse {
Util::addScript(Application::APP_ID, 'libresign-settings');
try {
$signatureParsed = $this->signatureTextService->parse();
$this->initialState->provideInitialState('signature_text_parsed', $signatureParsed['parsed']);
} catch (LibresignException $e) {
$this->initialState->provideInitialState('signature_text_parsed', '');
$this->initialState->provideInitialState('signature_text_template_error', $e->getMessage());
}
$this->initialState->provideInitialState('certificate_engine', $this->certificateEngineFactory->getEngine()->getName());
$this->initialState->provideInitialState('certificate_policies_oid', $this->certificatePolicyService->getOid());
$this->initialState->provideInitialState('certificate_policies_cps', $this->certificatePolicyService->getCps());
$this->initialState->provideInitialState('config_path', $this->appConfig->getValueString(Application::APP_ID, 'config_path'));
$this->initialState->provideInitialState('default_signature_font_size', SignatureTextService::SIGNATURE_DEFAULT_FONT_SIZE);
$this->initialState->provideInitialState('default_signature_height', SignatureTextService::DEFAULT_SIGNATURE_HEIGHT);
$this->initialState->provideInitialState('default_signature_text_template', $this->signatureTextService->getDefaultTemplate());
$this->initialState->provideInitialState('default_signature_width', SignatureTextService::DEFAULT_SIGNATURE_WIDTH);
$this->initialState->provideInitialState('default_template_font_size', $this->signatureTextService->getDefaultTemplateFontSize());
$this->initialState->provideInitialState('identify_methods', $this->identifyMethodService->getIdentifyMethodsSettings());
$this->initialState->provideInitialState('signature_available_variables', $this->signatureTextService->getAvailableVariables());
$this->initialState->provideInitialState('signature_background_type', $this->signatureBackgroundService->getSignatureBackgroundType());
$this->initialState->provideInitialState('signature_font_size', $this->signatureTextService->getSignatureFontSize());
$this->initialState->provideInitialState('signature_height', $this->signatureTextService->getFullSignatureHeight());
$this->initialState->provideInitialState('signature_preview_zoom_level', $this->appConfig->getValueFloat(Application::APP_ID, 'signature_preview_zoom_level', 100));
$this->initialState->provideInitialState('footer_preview_zoom_level', $this->appConfig->getValueFloat(Application::APP_ID, 'footer_preview_zoom_level', 100));
$this->initialState->provideInitialState('footer_preview_width', $this->appConfig->getValueInt(Application::APP_ID, 'footer_preview_width', 595));
$this->initialState->provideInitialState('footer_preview_height', $this->appConfig->getValueInt(Application::APP_ID, 'footer_preview_height', 100));
$this->initialState->provideInitialState('footer_template_variables', $this->footerService->getTemplateVariablesMetadata());
$this->initialState->provideInitialState('footer_template', $this->footerService->getTemplate());
$this->initialState->provideInitialState('footer_template_is_default', $this->footerService->isDefaultTemplate());
$this->initialState->provideInitialState('signature_render_mode', $this->signatureTextService->getRenderMode());
$this->initialState->provideInitialState('signature_text_template', $this->signatureTextService->getTemplate());
$this->initialState->provideInitialState('signature_width', $this->signatureTextService->getFullSignatureWidth());
$this->initialState->provideInitialState('template_font_size', $this->signatureTextService->getTemplateFontSize());
$this->initialState->provideInitialState('tsa_url', $this->appConfig->getValueString(Application::APP_ID, 'tsa_url', ''));
$this->initialState->provideInitialState('tsa_policy_oid', $this->appConfig->getValueString(Application::APP_ID, 'tsa_policy_oid', ''));
$this->initialState->provideInitialState('tsa_auth_type', $this->appConfig->getValueString(Application::APP_ID, 'tsa_auth_type', 'none'));
$this->initialState->provideInitialState('tsa_username', $this->appConfig->getValueString(Application::APP_ID, 'tsa_username', ''));
$this->initialState->provideInitialState('tsa_password', $this->appConfig->getValueString(Application::APP_ID, 'tsa_password', self::PASSWORD_PLACEHOLDER));
$this->initialState->provideInitialState('docmdp_config', $this->docMdpConfigService->getConfig());
$this->initialState->provideInitialState('signature_flow', $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', ''));
return new TemplateResponse(Application::APP_ID, 'admin_settings');
}
/**
* @psalm-return 'libresign'
*/
#[\Override]
public function getSection(): string {
return Application::APP_ID;
}
/**
* @psalm-return 100
*/
#[\Override]
public function getPriority(): int {
return 100;
}
}