Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.30% |
26 / 27 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Admin | |
96.30% |
26 / 27 |
|
80.00% |
4 / 5 |
6 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getForm | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
1 | |||
| getSection | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getPriority | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSignatureEngineInitialState | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Settings; |
| 10 | |
| 11 | use OCA\Libresign\AppInfo\Application; |
| 12 | use OCA\Libresign\Handler\CertificateEngine\CertificateEngineFactory; |
| 13 | use OCA\Libresign\Service\AccountService; |
| 14 | use OCA\Libresign\Service\CertificatePolicyService; |
| 15 | use OCA\Libresign\Service\Policy\PolicyService; |
| 16 | use OCP\AppFramework\Http\ContentSecurityPolicy; |
| 17 | use OCP\AppFramework\Http\TemplateResponse; |
| 18 | use OCP\AppFramework\Services\IInitialState; |
| 19 | use OCP\IAppConfig; |
| 20 | use OCP\IUserSession; |
| 21 | use OCP\Settings\ISettings; |
| 22 | use OCP\Util; |
| 23 | |
| 24 | class Admin implements ISettings { |
| 25 | public const PASSWORD_PLACEHOLDER = '••••••••'; |
| 26 | |
| 27 | public function __construct( |
| 28 | private IInitialState $initialState, |
| 29 | private AccountService $accountService, |
| 30 | private IUserSession $userSession, |
| 31 | private CertificateEngineFactory $certificateEngineFactory, |
| 32 | private CertificatePolicyService $certificatePolicyService, |
| 33 | private IAppConfig $appConfig, |
| 34 | private PolicyService $policyService, |
| 35 | ) { |
| 36 | } |
| 37 | #[\Override] |
| 38 | public function getForm(): TemplateResponse { |
| 39 | Util::addScript(Application::APP_ID, 'libresign-settings'); |
| 40 | Util::addStyle(Application::APP_ID, 'libresign-settings'); |
| 41 | $this->initialState->provideInitialState('config', $this->accountService->getConfig($this->userSession->getUser())); |
| 42 | $this->initialState->provideInitialState('certificate_engine', $this->certificateEngineFactory->getEngine()->getName()); |
| 43 | $this->initialState->provideInitialState('certificate_policies_oid', $this->certificatePolicyService->getOid()); |
| 44 | $this->initialState->provideInitialState('certificate_policies_cps', $this->certificatePolicyService->getCps()); |
| 45 | $this->initialState->provideInitialState('config_path', $this->appConfig->getValueString(Application::APP_ID, 'config_path')); |
| 46 | $this->initialState->provideInitialState('signature_engine', $this->getSignatureEngineInitialState()); |
| 47 | $this->initialState->provideInitialState('effective_policies', [ |
| 48 | 'policies' => $this->policyService->resolveKnownPolicyStatesWithRuleCounts( |
| 49 | $this->policyService->getAllRuleCounts(), |
| 50 | ), |
| 51 | ]); |
| 52 | $this->initialState->provideInitialState('ldap_extension_available', function_exists('ldap_connect')); |
| 53 | |
| 54 | $response = new TemplateResponse(Application::APP_ID, 'admin_settings'); |
| 55 | $policy = new ContentSecurityPolicy(); |
| 56 | $policy->addAllowedWorkerSrcDomain("'self'"); |
| 57 | $policy->addAllowedWorkerSrcDomain('blob:'); |
| 58 | $response->setContentSecurityPolicy($policy); |
| 59 | |
| 60 | return $response; |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @psalm-return 'libresign' |
| 65 | */ |
| 66 | #[\Override] |
| 67 | public function getSection(): string { |
| 68 | return Application::APP_ID; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @psalm-return 100 |
| 73 | */ |
| 74 | #[\Override] |
| 75 | public function getPriority(): int { |
| 76 | return 100; |
| 77 | } |
| 78 | |
| 79 | private function getSignatureEngineInitialState(): string { |
| 80 | $engine = $this->appConfig->getValueString(Application::APP_ID, 'signature_engine', 'JSignPdf'); |
| 81 | if ($engine === 'PhpNative') { |
| 82 | return $engine; |
| 83 | } |
| 84 | return 'JSignPdf'; |
| 85 | } |
| 86 | |
| 87 | } |