Skip to content

Commit 4e618db

Browse files
committed
refactor(policy): remove footer legacy appconfig fallback
Consolidate add_footer runtime and persistence on PolicyService: - remove footer_template fallback in FooterHandler - persist template customization via PolicyService in FooterService - stop using footer_template as FooterPolicy baseline - remove initial-state dependency for footer_template_is_default in Validation view - update FooterServiceTest for policy-first flow Signed-off-by: Vitor Mattos <[email protected]>
1 parent c134cff commit 4e618db

5 files changed

Lines changed: 116 additions & 99 deletions

File tree

lib/Handler/FooterHandler.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,6 @@ public function getTemplate(): string {
209209
return $policyTemplate;
210210
}
211211
}
212-
213-
$footerTemplate = $this->appConfig->getValueString(Application::APP_ID, 'footer_template', '');
214-
if ($footerTemplate) {
215-
return $footerTemplate;
216-
}
217212
return $this->getDefaultTemplate();
218213
}
219214

lib/Service/FooterService.php

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,19 @@
88

99
namespace OCA\Libresign\Service;
1010

11-
use OCA\Libresign\AppInfo\Application;
1211
use OCA\Libresign\Handler\FooterHandler;
12+
use OCA\Libresign\Service\Policy\PolicyService;
1313
use OCA\Libresign\Service\Policy\Provider\Footer\FooterPolicy;
1414
use OCA\Libresign\Service\Policy\Provider\Footer\FooterPolicyValue;
15-
use OCP\IAppConfig;
1615

1716
class FooterService {
1817
public function __construct(
19-
private IAppConfig $appConfig,
18+
private PolicyService $policyService,
2019
private FooterHandler $footerHandler,
2120
) {
2221
}
2322

2423
public function isDefaultTemplate(): bool {
25-
$legacyCustomTemplate = $this->appConfig->getValueString(Application::APP_ID, 'footer_template', '');
26-
if ($legacyCustomTemplate !== '') {
27-
return false;
28-
}
29-
3024
$footerPolicy = $this->getEffectiveFooterPolicy();
3125
return !$footerPolicy['customizeFooterTemplate'];
3226
}
@@ -40,38 +34,31 @@ public function saveTemplate(string $template = ''): void {
4034
$defaultTemplateFromPolicy = $currentPolicy['footerTemplate'];
4135

4236
if (empty($template)) {
43-
$this->appConfig->deleteKey(Application::APP_ID, 'footer_template');
4437
$this->syncFooterPolicyTemplate('', false);
4538
return;
4639
}
4740

4841
$isProvidedTemplateEqualsDefault = $template === $defaultTemplateFromPolicy;
4942

5043
if ($isProvidedTemplateEqualsDefault) {
51-
$this->appConfig->deleteKey(Application::APP_ID, 'footer_template');
5244
$this->syncFooterPolicyTemplate('', false);
5345
} else {
54-
$this->appConfig->setValueString(Application::APP_ID, 'footer_template', $template);
5546
$this->syncFooterPolicyTemplate($template, true);
5647
}
5748
}
5849

5950
private function syncFooterPolicyTemplate(string $template, bool $customizeFooterTemplate): void {
6051
$currentPolicy = $this->getEffectiveFooterPolicy();
61-
$defaultTemplate = $currentPolicy['footerTemplate'];
62-
63-
$normalizedPolicy = FooterPolicyValue::normalize(
64-
$this->appConfig->getValueString(Application::APP_ID, FooterPolicy::KEY, ''),
65-
$defaultTemplate
66-
);
52+
$normalizedPolicy = FooterPolicyValue::normalize($currentPolicy);
6753

6854
$normalizedPolicy['customizeFooterTemplate'] = $customizeFooterTemplate;
6955
$normalizedPolicy['footerTemplate'] = $customizeFooterTemplate ? $template : '';
7056

71-
$this->appConfig->setValueString(
72-
Application::APP_ID,
57+
$allowChildOverride = $this->policyService->getSystemPolicy(FooterPolicy::KEY)?->isAllowChildOverride() ?? false;
58+
$this->policyService->saveSystem(
7359
FooterPolicy::KEY,
74-
FooterPolicyValue::encode($normalizedPolicy)
60+
FooterPolicyValue::encode($normalizedPolicy),
61+
$allowChildOverride,
7562
);
7663
}
7764

lib/Service/Policy/Provider/Footer/FooterPolicy.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,15 @@
88

99
namespace OCA\Libresign\Service\Policy\Provider\Footer;
1010

11-
use OCA\Libresign\AppInfo\Application;
1211
use OCA\Libresign\Service\Policy\Contract\IPolicyDefinition;
1312
use OCA\Libresign\Service\Policy\Contract\IPolicyDefinitionProvider;
1413
use OCA\Libresign\Service\Policy\Model\PolicyContext;
1514
use OCA\Libresign\Service\Policy\Model\PolicySpec;
16-
use OCP\IAppConfig;
1715

1816
final class FooterPolicy implements IPolicyDefinitionProvider {
1917
public const KEY = 'add_footer';
2018
public const SYSTEM_APP_CONFIG_KEY = 'add_footer';
2119

22-
public function __construct(
23-
private ?IAppConfig $appConfig = null,
24-
) {
25-
}
26-
2720
#[\Override]
2821
public function keys(): array {
2922
return [
@@ -81,15 +74,6 @@ private static function canManageTechnicalFooterSettings(PolicyContext $context)
8174
}
8275

8376
private function resolveInstanceBaseTemplate(): string {
84-
if ($this->appConfig === null) {
85-
return '';
86-
}
87-
88-
$templateFromConfig = $this->appConfig->getValueString(Application::APP_ID, 'footer_template', '');
89-
if ($templateFromConfig !== '') {
90-
return $templateFromConfig;
91-
}
92-
9377
$defaultTemplatePath = __DIR__ . '/../../../../Handler/Templates/footer.twig';
9478
$defaultTemplate = @file_get_contents($defaultTemplatePath);
9579

src/views/Settings/Validation.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
</template>
5454
<script setup lang="ts">
5555
import axios from '@nextcloud/axios'
56-
import { loadState } from '@nextcloud/initial-state'
5756
import { generateOcsUrl } from '@nextcloud/router'
5857
import { t } from '@nextcloud/l10n'
5958
import { onMounted, ref } from 'vue'
@@ -92,15 +91,13 @@ defineOptions({
9291
name: 'Validation',
9392
})
9493
95-
const isDefaultFooterTemplateState = loadState('libresign', 'footer_template_is_default', true)
96-
9794
const paternValidadeUrl = ref('https://validador.librecode.coop/')
9895
const makeValidationUrlPrivate = ref(false)
9996
const url = ref<string | null>(null)
10097
const addFooter = ref(true)
10198
const writeQrcodeOnFooter = ref(true)
102-
const isDefaultFooterTemplate = ref(isDefaultFooterTemplateState)
103-
const customizeFooter = ref(!isDefaultFooterTemplateState)
99+
const isDefaultFooterTemplate = ref(true)
100+
const customizeFooter = ref(false)
104101
const policiesStore = usePoliciesStore()
105102
106103
const urlInput = ref<HTMLInputElement | null>(null)

0 commit comments

Comments
 (0)