Skip to content

Commit 7cb408f

Browse files
committed
refactor(policy): resolve collect_metadata via PolicyService in signature text
Signed-off-by: Vitor Mattos <[email protected]>
1 parent bf70048 commit 7cb408f

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

lib/Service/SignatureTextService.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use ImagickPixel;
1616
use OCA\Libresign\AppInfo\Application;
1717
use OCA\Libresign\Exception\LibresignException;
18+
use OCA\Libresign\Service\Policy\PolicyService;
19+
use OCA\Libresign\Service\Policy\Provider\CollectMetadata\CollectMetadataPolicy;
1820
use OCA\Libresign\Vendor\Twig\Environment;
1921
use OCA\Libresign\Vendor\Twig\Error\SyntaxError;
2022
use OCA\Libresign\Vendor\Twig\Loader\FilesystemLoader;
@@ -41,6 +43,7 @@ public function __construct(
4143
private IRequest $request,
4244
private IUserSession $userSession,
4345
protected LoggerInterface $logger,
46+
private ?PolicyService $policyService = null,
4447
) {
4548
}
4649

@@ -190,7 +193,7 @@ public function getAvailableVariables(): array {
190193
'{{SignerEmail}}' => $this->l10n->t('The signer\'s email is optional and can be left blank.'),
191194
'{{SignerIdentifier}}' => $this->l10n->t('Unique information used to identify the signer (such as email, phone number, or username).'),
192195
];
193-
$collectMetadata = $this->appConfig->getValueBool(Application::APP_ID, 'collect_metadata', false);
196+
$collectMetadata = $this->isCollectMetadataEnabled();
194197
if ($collectMetadata) {
195198
$list['{{SignerIP}}'] = $this->l10n->t('IP address of the person who signed the document.');
196199
$list['{{SignerUserAgent}}'] = $this->l10n->t('Browser and device information of the person who signed the document.');
@@ -400,7 +403,7 @@ private function mbWordwrap(string $text, int $width, string $break = "\n", bool
400403
}
401404

402405
public function getDefaultTemplate(): string {
403-
$collectMetadata = $this->appConfig->getValueBool(Application::APP_ID, 'collect_metadata', false);
406+
$collectMetadata = $this->isCollectMetadataEnabled();
404407
if ($collectMetadata) {
405408
// TRANSLATORS Variables enclosed in double curly braces {{variableName}} are template placeholders.
406409
//
@@ -480,21 +483,33 @@ private function getSanitizedDimension(string $key, float $default): float {
480483
}
481484

482485
public function getTemplateFontSize(): float {
483-
$collectMetadata = $this->appConfig->getValueBool(Application::APP_ID, 'collect_metadata', false);
486+
$collectMetadata = $this->isCollectMetadataEnabled();
484487
if ($collectMetadata) {
485488
return $this->appConfig->getValueFloat(Application::APP_ID, 'template_font_size', self::TEMPLATE_DEFAULT_FONT_SIZE - 1);
486489
}
487490
return $this->appConfig->getValueFloat(Application::APP_ID, 'template_font_size', self::TEMPLATE_DEFAULT_FONT_SIZE);
488491
}
489492

490493
public function getDefaultTemplateFontSize(): float {
491-
$collectMetadata = $this->appConfig->getValueBool(Application::APP_ID, 'collect_metadata', false);
494+
$collectMetadata = $this->isCollectMetadataEnabled();
492495
if ($collectMetadata) {
493496
return self::TEMPLATE_DEFAULT_FONT_SIZE - 0.2;
494497
}
495498
return self::TEMPLATE_DEFAULT_FONT_SIZE;
496499
}
497500

501+
private function isCollectMetadataEnabled(): bool {
502+
if ($this->policyService !== null) {
503+
try {
504+
return (bool)$this->policyService->resolve(CollectMetadataPolicy::KEY)->effectiveValue();
505+
} catch (\Throwable) {
506+
// Fallback keeps legacy behavior during migration rollout.
507+
}
508+
}
509+
510+
return $this->appConfig->getValueBool(Application::APP_ID, CollectMetadataPolicy::SYSTEM_APP_CONFIG_KEY, false);
511+
}
512+
498513
public function getSignatureFontSize(): float {
499514
return $this->appConfig->getValueFloat(Application::APP_ID, 'signature_font_size', self::SIGNATURE_DEFAULT_FONT_SIZE);
500515
}

0 commit comments

Comments
 (0)