Skip to content

Commit d644e92

Browse files
committed
fix: align footer policy reset behavior
Signed-off-by: Vitor Mattos <[email protected]>
1 parent da34720 commit d644e92

10 files changed

Lines changed: 1071 additions & 15 deletions

File tree

lib/Handler/FooterHandler.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ public function setWriteQrcodeOnFooterOverride(?bool $value): self {
129129
return $this;
130130
}
131131

132+
public function getEffectiveFooterPolicyAsJson(): string {
133+
return (string)$this->policyService->resolve(FooterPolicy::KEY, $this->requestPolicyOverrides)->getEffectiveValue();
134+
}
135+
132136
/** @return array{enabled: bool, writeQrcodeOnFooter: bool, validationSite: string, customizeFooterTemplate: bool, footerTemplate: string, previewWidth: int, previewHeight: int, previewZoom: int} */
133137
private function resolveFooterPolicy(): array {
134138
return FooterPolicyValue::normalize(

lib/Service/FooterService.php

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use OCA\Libresign\AppInfo\Application;
1212
use OCA\Libresign\Handler\FooterHandler;
13+
use OCA\Libresign\Service\Policy\Provider\Footer\FooterPolicy;
14+
use OCA\Libresign\Service\Policy\Provider\Footer\FooterPolicyValue;
1315
use OCP\IAppConfig;
1416

1517
class FooterService {
@@ -20,34 +22,64 @@ public function __construct(
2022
}
2123

2224
public function isDefaultTemplate(): bool {
23-
$customTemplate = $this->appConfig->getValueString(Application::APP_ID, 'footer_template', '');
24-
return empty($customTemplate);
25+
$footerPolicy = $this->getEffectiveFooterPolicy();
26+
return !$footerPolicy['customizeFooterTemplate'];
2527
}
2628

2729
public function getTemplate(): string {
2830
return $this->footerHandler->getTemplate();
2931
}
3032

3133
public function saveTemplate(string $template = ''): void {
34+
$currentPolicy = $this->getEffectiveFooterPolicy();
35+
$defaultTemplateFromPolicy = $currentPolicy['footerTemplate'];
36+
3237
if (empty($template)) {
3338
$this->appConfig->deleteKey(Application::APP_ID, 'footer_template');
39+
$this->syncFooterPolicyTemplate('', false);
3440
return;
3541
}
3642

37-
if ($template === $this->footerHandler->getDefaultTemplate()) {
43+
$isProvidedTemplateEqualsDefault = $template === $defaultTemplateFromPolicy;
44+
45+
if ($isProvidedTemplateEqualsDefault) {
3846
$this->appConfig->deleteKey(Application::APP_ID, 'footer_template');
47+
$this->syncFooterPolicyTemplate('', false);
3948
} else {
4049
$this->appConfig->setValueString(Application::APP_ID, 'footer_template', $template);
50+
$this->syncFooterPolicyTemplate($template, true);
4151
}
4252
}
4353

54+
private function syncFooterPolicyTemplate(string $template, bool $customizeFooterTemplate): void {
55+
$currentPolicy = $this->getEffectiveFooterPolicy();
56+
$defaultTemplate = $currentPolicy['footerTemplate'];
57+
58+
$normalizedPolicy = FooterPolicyValue::normalize(
59+
$this->appConfig->getValueString(Application::APP_ID, FooterPolicy::KEY, ''),
60+
$defaultTemplate
61+
);
62+
63+
$normalizedPolicy['customizeFooterTemplate'] = $customizeFooterTemplate;
64+
$normalizedPolicy['footerTemplate'] = $customizeFooterTemplate ? $template : '';
65+
66+
$this->appConfig->setValueString(
67+
Application::APP_ID,
68+
FooterPolicy::KEY,
69+
FooterPolicyValue::encode($normalizedPolicy)
70+
);
71+
}
72+
73+
private function getEffectiveFooterPolicy(): array {
74+
$policyJson = $this->footerHandler->getEffectiveFooterPolicyAsJson();
75+
return FooterPolicyValue::normalize($policyJson, '');
76+
}
77+
4478
public function renderPreviewPdf(string $template = '', int $width = 595, int $height = 50, ?bool $writeQrcodeOnFooter = null): string {
4579
if (!empty($template)) {
4680
$this->saveTemplate($template);
4781
}
4882

49-
// Generate a realistic UUID format for preview (36 chars with hyphens, same as real UUIDs)
50-
// This ensures QR code size matches the final document
5183
$previewUuid = sprintf(
5284
'preview-%04x-%04x-%04x-%012x',
5385
random_int(0, 0xffff),

lib/Service/IdentifyMethod/TwofactorGateway.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\IUserSession;
1919
use OCP\Server;
2020
use Psr\Log\LoggerInterface;
21+
use Throwable;
2122

2223
class TwofactorGateway extends AbstractIdentifyMethod {
2324
public function __construct(
@@ -67,8 +68,17 @@ public function isTwofactorGatewayEnabled(): bool {
6768

6869
$gatewayName = $this->getGatewayName();
6970

70-
$gateway = $gatewayFactory->get($gatewayName);
71-
return $gateway->isComplete();
71+
try {
72+
$gateway = $gatewayFactory->get($gatewayName);
73+
return $gateway->isComplete();
74+
} catch (Throwable $exception) {
75+
$this->logger->warning('Unable to load twofactor gateway provider.', [
76+
'gateway' => $gatewayName,
77+
'identifyMethod' => $this->getId(),
78+
'exception' => $exception,
79+
]);
80+
return false;
81+
}
7282
}
7383

7484
private function getGatewayName(): string {

0 commit comments

Comments
 (0)