Skip to content

Commit acd6593

Browse files
committed
fix(compat): restore legacy admin state and tsa config fallback
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 67fef15 commit acd6593

6 files changed

Lines changed: 84 additions & 4 deletions

File tree

lib/Controller/AdminController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,11 @@ public function setTsaConfig(
822822
false,
823823
);
824824

825+
$this->appConfig->setValueString(Application::APP_ID, 'tsa_url', $trimmedUrl);
826+
$this->appConfig->setValueString(Application::APP_ID, 'tsa_policy_oid', $trimmedOid);
827+
$this->appConfig->setValueString(Application::APP_ID, 'tsa_auth_type', $authType);
828+
$this->appConfig->setValueString(Application::APP_ID, 'tsa_username', $username);
829+
825830
return new DataResponse(['status' => 'success']);
826831
}
827832

@@ -838,6 +843,10 @@ public function setTsaConfig(
838843
#[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/admin/tsa', requirements: ['apiVersion' => '(v1)'])]
839844
public function deleteTsaConfig(): DataResponse {
840845
$this->policyService->saveSystem(TsaPolicy::KEY, TsaPolicyValue::defaults(), false);
846+
$this->appConfig->deleteKey(Application::APP_ID, 'tsa_url');
847+
$this->appConfig->deleteKey(Application::APP_ID, 'tsa_policy_oid');
848+
$this->appConfig->deleteKey(Application::APP_ID, 'tsa_auth_type');
849+
$this->appConfig->deleteKey(Application::APP_ID, 'tsa_username');
841850
$this->appConfig->deleteKey(Application::APP_ID, 'tsa_password');
842851

843852
return new DataResponse(['status' => 'success']);

lib/Handler/SignEngine/JSignPdfHandler.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,17 @@ private function getTsaParameters(): array {
656656
*/
657657
private function getTsaSettings(): array {
658658
$resolved = $this->policyService->resolve(TsaPolicy::KEY)->getEffectiveValue();
659-
return TsaPolicyValue::decode($resolved);
659+
$settings = TsaPolicyValue::decode($resolved);
660+
if (!empty($settings['url'])) {
661+
return $settings;
662+
}
663+
664+
return [
665+
'url' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_url', ''),
666+
'policy_oid' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_policy_oid', ''),
667+
'auth_type' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_auth_type', 'none'),
668+
'username' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_username', ''),
669+
];
660670
}
661671

662672
private function signWrapper(JSignPDF $jSignPDF): string {

lib/Handler/SignEngine/PhpNativeHandler.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,17 @@ private function buildTimestampOptions(): ?TimestampOptionsDto {
241241
*/
242242
private function getTsaSettings(): array {
243243
$resolved = $this->policyService->resolve(TsaPolicy::KEY)->getEffectiveValue();
244-
return TsaPolicyValue::decode($resolved);
244+
$settings = TsaPolicyValue::decode($resolved);
245+
if (!empty($settings['url'])) {
246+
return $settings;
247+
}
248+
249+
return [
250+
'url' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_url', ''),
251+
'policy_oid' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_policy_oid', ''),
252+
'auth_type' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_auth_type', 'none'),
253+
'username' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_username', ''),
254+
];
245255
}
246256

247257
private function resolveCertificationLevel(bool $noVisibleElements): ?CertificationLevel {

lib/Service/IdentifyMethod/IdentifyService.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OCA\Libresign\Service\IdentifyMethod;
1010

11+
use OCA\Libresign\AppInfo\Application;
1112
use OCA\Libresign\Db\FileMapper;
1213
use OCA\Libresign\Db\IdentifyMethod;
1314
use OCA\Libresign\Db\IdentifyMethodMapper;
@@ -134,7 +135,14 @@ public function getSavedSettings(): array {
134135
}
135136

136137
$resolved = $this->policyService->resolve(IdentifyMethodsPolicy::KEY)->getEffectiveValue();
137-
$this->savedSettings = IdentifyMethodsPolicyValue::normalize($resolved);
138+
$normalized = IdentifyMethodsPolicyValue::normalize($resolved);
139+
if ($normalized !== []) {
140+
$this->savedSettings = $normalized;
141+
return $this->savedSettings;
142+
}
143+
144+
$legacyRaw = $this->appConfig->getValueString(Application::APP_ID, IdentifyMethodsPolicy::KEY, '');
145+
$this->savedSettings = IdentifyMethodsPolicyValue::normalize($legacyRaw);
138146

139147
return $this->savedSettings;
140148
}

lib/Settings/Admin.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
use OCA\Libresign\Service\AccountService;
1515
use OCA\Libresign\Service\CertificatePolicyService;
1616
use OCA\Libresign\Service\FooterService;
17+
use OCA\Libresign\Service\IdentifyMethodService;
1718
use OCA\Libresign\Service\Policy\PolicyService;
19+
use OCA\Libresign\Service\Policy\Provider\LegalInformation\LegalInformationPolicy;
20+
use OCA\Libresign\Service\Policy\Provider\SignatureBackground\SignatureBackgroundPolicy;
21+
use OCA\Libresign\Service\Policy\Provider\Tsa\TsaPolicy;
22+
use OCA\Libresign\Service\Policy\Provider\Tsa\TsaPolicyValue;
1823
use OCA\Libresign\Service\SignatureTextService;
1924
use OCP\AppFramework\Http\ContentSecurityPolicy;
2025
use OCP\AppFramework\Http\TemplateResponse;
@@ -42,6 +47,7 @@ public function __construct(
4247
private SignatureTextService $signatureTextService,
4348
private FooterService $footerService,
4449
private PolicyService $policyService,
50+
private IdentifyMethodService $identifyMethodService,
4551
) {
4652
}
4753
#[\Override]
@@ -60,7 +66,9 @@ public function getForm(): TemplateResponse {
6066
$this->initialState->provideInitialState('certificate_policies_oid', $this->certificatePolicyService->getOid());
6167
$this->initialState->provideInitialState('certificate_policies_cps', $this->certificatePolicyService->getCps());
6268
$this->initialState->provideInitialState('config_path', $this->appConfig->getValueString(Application::APP_ID, 'config_path'));
69+
$this->initialState->provideInitialState('legal_information', (string)$this->policyService->resolve(LegalInformationPolicy::KEY)->getEffectiveValue());
6370
$this->initialState->provideInitialState('signature_available_variables', $this->signatureTextService->getAvailableVariables());
71+
$this->initialState->provideInitialState('signature_background_type', (string)$this->policyService->resolve(SignatureBackgroundPolicy::KEY)->getEffectiveValue());
6472
$this->initialState->provideInitialState('signature_preview_zoom_level', $this->appConfig->getValueFloat(Application::APP_ID, 'signature_preview_zoom_level', 100));
6573
$this->initialState->provideInitialState('footer_preview_zoom_level', $this->appConfig->getValueFloat(Application::APP_ID, 'footer_preview_zoom_level', 100));
6674
$this->initialState->provideInitialState('footer_preview_width', $this->appConfig->getValueInt(Application::APP_ID, 'footer_preview_width', 595));
@@ -70,6 +78,13 @@ public function getForm(): TemplateResponse {
7078
$this->initialState->provideInitialState('footer_template', $this->footerService->getTemplate());
7179
$this->initialState->provideInitialState('footer_template_is_default', $this->footerService->isDefaultTemplate());
7280
$this->initialState->provideInitialState('signature_engine', $this->getSignatureEngineInitialState());
81+
$tsaSettings = $this->getTsaInitialState();
82+
$this->initialState->provideInitialState('tsa_url', $tsaSettings['url']);
83+
$this->initialState->provideInitialState('tsa_policy_oid', $tsaSettings['policy_oid']);
84+
$this->initialState->provideInitialState('tsa_auth_type', $tsaSettings['auth_type']);
85+
$this->initialState->provideInitialState('tsa_username', $tsaSettings['username']);
86+
$this->initialState->provideInitialState('tsa_password', $this->appConfig->getValueString(Application::APP_ID, 'tsa_password', self::PASSWORD_PLACEHOLDER));
87+
$this->initialState->provideInitialState('identify_methods', $this->identifyMethodService->getIdentifyMethodsSettings());
7388
$resolvedPolicies = [];
7489
foreach ($this->policyService->resolveKnownPolicies() as $policyKey => $resolvedPolicy) {
7590
$resolvedPolicies[$policyKey] = $resolvedPolicy->toArray();
@@ -79,7 +94,12 @@ public function getForm(): TemplateResponse {
7994
]);
8095
$this->initialState->provideInitialState('signing_mode', $this->getSigningModeInitialState());
8196
$this->initialState->provideInitialState('worker_type', $this->getWorkerTypeInitialState());
97+
$this->initialState->provideInitialState('identification_documents', $this->appConfig->getValueBool(Application::APP_ID, 'identification_documents', false));
98+
$this->initialState->provideInitialState('approval_group', $this->appConfig->getValueString(Application::APP_ID, 'approval_group', '["admin"]'));
99+
$this->initialState->provideInitialState('envelope_enabled', $this->appConfig->getValueBool(Application::APP_ID, 'envelope_enabled', true));
82100
$this->initialState->provideInitialState('parallel_workers', $this->appConfig->getValueString(Application::APP_ID, 'parallel_workers', '4'));
101+
$this->initialState->provideInitialState('show_confetti_after_signing', $this->appConfig->getValueBool(Application::APP_ID, 'show_confetti_after_signing', true));
102+
$this->initialState->provideInitialState('crl_external_validation_enabled', $this->appConfig->getValueBool(Application::APP_ID, 'crl_external_validation_enabled', true));
83103
$this->initialState->provideInitialState('ldap_extension_available', function_exists('ldap_connect'));
84104

85105
$response = new TemplateResponse(Application::APP_ID, 'admin_settings');
@@ -133,4 +153,22 @@ private function getWorkerTypeInitialState(): string {
133153
}
134154
return 'local';
135155
}
156+
157+
/**
158+
* @return array{url: string, policy_oid: string, auth_type: string, username: string}
159+
*/
160+
private function getTsaInitialState(): array {
161+
$resolved = $this->policyService->resolve(TsaPolicy::KEY)->getEffectiveValue();
162+
$settings = TsaPolicyValue::decode($resolved);
163+
if (!empty($settings['url'])) {
164+
return $settings;
165+
}
166+
167+
return [
168+
'url' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_url', ''),
169+
'policy_oid' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_policy_oid', ''),
170+
'auth_type' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_auth_type', 'none'),
171+
'username' => $this->appConfig->getValueString(Application::APP_ID, 'tsa_username', ''),
172+
];
173+
}
136174
}

tests/php/Unit/Settings/AdminTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCA\Libresign\Service\AccountService;
1515
use OCA\Libresign\Service\CertificatePolicyService;
1616
use OCA\Libresign\Service\FooterService;
17+
use OCA\Libresign\Service\IdentifyMethodService;
1718
use OCA\Libresign\Service\Policy\Model\ResolvedPolicy;
1819
use OCA\Libresign\Service\Policy\PolicyService;
1920
use OCA\Libresign\Service\SignatureTextService;
@@ -39,6 +40,7 @@ final class AdminTest extends \OCA\Libresign\Tests\Unit\TestCase {
3940
private SignatureTextService&MockObject $signatureTextService;
4041
private FooterService&MockObject $footerService;
4142
private PolicyService&MockObject $policyService;
43+
private IdentifyMethodService&MockObject $identifyMethodService;
4244
public function setUp(): void {
4345
$this->initialState = $this->createMock(IInitialState::class);
4446
$this->accountService = $this->createMock(AccountService::class);
@@ -49,6 +51,7 @@ public function setUp(): void {
4951
$this->signatureTextService = $this->createMock(SignatureTextService::class);
5052
$this->footerService = $this->createMock(FooterService::class);
5153
$this->policyService = $this->createMock(PolicyService::class);
54+
$this->identifyMethodService = $this->createMock(IdentifyMethodService::class);
5255
$this->admin = new Admin(
5356
$this->initialState,
5457
$this->accountService,
@@ -59,6 +62,7 @@ public function setUp(): void {
5962
$this->signatureTextService,
6063
$this->footerService,
6164
$this->policyService,
65+
$this->identifyMethodService,
6266
);
6367
$this->stubGetFormDependencies();
6468
}
@@ -72,8 +76,9 @@ private function stubGetFormDependencies(): void {
7276
$this->userSession->method('getUser')->willReturn($this->createMock(IUser::class));
7377
$this->policyService->method('resolveKnownPolicies')->willReturn([]);
7478
$this->policyService->method('resolve')->willReturn(
75-
(new ResolvedPolicy())->setEffectiveValue(['admin']),
79+
(new ResolvedPolicy())->setEffectiveValue(''),
7680
);
81+
$this->identifyMethodService->method('getIdentifyMethodsSettings')->willReturn([]);
7782

7883
$engine = $this->createMock(OpenSslHandler::class);
7984
$engine->method('getName')->willReturn('openssl');

0 commit comments

Comments
 (0)