Skip to content

Commit 3fbc56e

Browse files
committed
feat: add envelope capabilities and migrate from initialState
Add envelope availability to capabilities API: - Add envelope.is-available capability - Add EnvelopeService.isEnabled() method - Remove envelope_enabled from initialState - Update frontend to use capabilities instead of initialState This provides a consistent way to check envelope feature availability across the application using the Nextcloud capabilities API. Signed-off-by: Vitor Mattos <[email protected]>
1 parent 4b18370 commit 3fbc56e

6 files changed

Lines changed: 18 additions & 7 deletions

File tree

lib/Capabilities.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OCA\Libresign;
1010

11+
use OCA\Libresign\Service\EnvelopeService;
1112
use OCA\Libresign\Service\SignatureTextService;
1213
use OCA\Libresign\Service\SignerElementsService;
1314
use OCP\App\IAppManager;
@@ -25,6 +26,7 @@ public function __construct(
2526
protected SignerElementsService $signerElementsService,
2627
protected SignatureTextService $signatureTextService,
2728
protected IAppManager $appManager,
29+
protected EnvelopeService $envelopeService,
2830
) {
2931
}
3032

@@ -46,6 +48,9 @@ public function getCapabilities(): array {
4648
'signature-width' => $this->signatureTextService->getSignatureWidth(),
4749
'signature-height' => $this->signatureTextService->getSignatureHeight(),
4850
],
51+
'envelope' => [
52+
'is-available' => $this->envelopeService->isEnabled(),
53+
],
4954
],
5055
'version' => $this->appManager->getAppVersion('libresign'),
5156
];

lib/Controller/PageController.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ public function index(): TemplateResponse {
9393
$this->initialState->provideInitialState('can_request_sign', false);
9494
}
9595

96-
$this->initialState->provideInitialState('envelope_enabled', $this->appConfig->getValueBool(Application::APP_ID, 'envelope_enabled', true));
97-
9896
$this->provideSignerSignatues();
9997
$this->initialState->provideInitialState('identify_methods', $this->identifyMethodService->getIdentifyMethodsSettings());
10098
$this->initialState->provideInitialState('signature_flow', $this->appConfig->getValueString(Application::APP_ID, 'signature_flow', \OCA\Libresign\Enum\SignatureFlow::NONE->value));

lib/Files/TemplateLoader.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,5 @@ public function handle(Event $event): void {
6969
} catch (LibresignException) {
7070
$this->initialState->provideInitialState('can_request_sign', false);
7171
}
72-
73-
$this->initialState->provideInitialState('envelope_enabled', $this->appConfig->getValueBool(Application::APP_ID, 'envelope_enabled', true));
7472
}
7573
}

lib/ResponseDefinitions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@
274274
* signature-width: float,
275275
* signature-height: float,
276276
* },
277+
* envelope: array{
278+
* is-available: bool,
279+
* },
277280
* },
278281
* version: string,
279282
* }

lib/Service/EnvelopeService.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ public function __construct(
2828
) {
2929
}
3030

31+
public function isEnabled(): bool {
32+
return $this->appConfig->getValueBool(Application::APP_ID, 'envelope_enabled', true);
33+
}
34+
3135
/**
3236
* @throws LibresignException
3337
*/
3438
public function validateEnvelopeConstraints(int $fileCount): void {
35-
$isEnabled = $this->appConfig->getValueBool(Application::APP_ID, 'envelope_enabled', true);
36-
if (!$isEnabled) {
39+
if (!$this->isEnabled()) {
3740
throw new LibresignException($this->l10n->t('Envelope feature is disabled'));
3841
}
3942

src/Components/Request/RequestPicker.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import PlusIcon from 'vue-material-design-icons/Plus.vue'
7878
import UploadIcon from 'vue-material-design-icons/Upload.vue'
7979
8080
import axios from '@nextcloud/axios'
81+
import { getCapabilities } from '@nextcloud/capabilities'
8182
import { showError } from '@nextcloud/dialogs'
8283
import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
8384
import { loadState } from '@nextcloud/initial-state'
@@ -134,10 +135,13 @@ export default {
134135
loading: false,
135136
openedMenu: false,
136137
canRequestSign: loadState('libresign', 'can_request_sign', false),
137-
envelopeEnabled: loadState('libresign', 'envelope_enabled', true),
138138
}
139139
},
140140
computed: {
141+
envelopeEnabled() {
142+
const capabilities = getCapabilities()
143+
return capabilities?.libresign?.config?.envelope?.['is-available'] === true
144+
},
141145
filePickerButtons() {
142146
return [{
143147
label: t('libresign', 'Choose'),

0 commit comments

Comments
 (0)