Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.55% |
28 / 29 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Capabilities | |
96.55% |
28 / 29 |
|
66.67% |
2 / 3 |
5 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCapabilities | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
1 | |||
| getMaxFileUploads | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
3.14 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign; |
| 10 | |
| 11 | use OCA\Libresign\Service\Envelope\EnvelopeService; |
| 12 | use OCA\Libresign\Service\Policy\PolicyService; |
| 13 | use OCA\Libresign\Service\Policy\Provider\Confetti\ConfettiPolicy; |
| 14 | use OCA\Libresign\Service\SignatureTextService; |
| 15 | use OCA\Libresign\Service\SignerElementsService; |
| 16 | use OCP\App\IAppManager; |
| 17 | use OCP\Capabilities\IPublicCapability; |
| 18 | |
| 19 | /** |
| 20 | * @psalm-import-type LibresignCapabilities from ResponseDefinitions |
| 21 | */ |
| 22 | class Capabilities implements IPublicCapability { |
| 23 | public const FEATURES = [ |
| 24 | 'customize-signature' |
| 25 | ]; |
| 26 | |
| 27 | public function __construct( |
| 28 | protected SignerElementsService $signerElementsService, |
| 29 | protected SignatureTextService $signatureTextService, |
| 30 | protected IAppManager $appManager, |
| 31 | protected EnvelopeService $envelopeService, |
| 32 | protected PolicyService $policyService, |
| 33 | ) { |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @return array{ |
| 38 | * libresign?: LibresignCapabilities, |
| 39 | * } |
| 40 | */ |
| 41 | #[\Override] |
| 42 | public function getCapabilities(): array { |
| 43 | $capabilities = [ |
| 44 | 'features' => self::FEATURES, |
| 45 | 'config' => [ |
| 46 | 'show-confetti' => $this->policyService->resolve(ConfettiPolicy::KEY)->getEffectiveValueAsBool(true), |
| 47 | 'sign-elements' => [ |
| 48 | 'is-available' => $this->signerElementsService->isSignElementsAvailable(), |
| 49 | 'can-create-signature' => $this->signerElementsService->canCreateSignature(), |
| 50 | 'full-signature-width' => $this->signatureTextService->getFullSignatureWidth(), |
| 51 | 'full-signature-height' => $this->signatureTextService->getFullSignatureHeight(), |
| 52 | 'signature-width' => $this->signatureTextService->getSignatureWidth(), |
| 53 | 'signature-height' => $this->signatureTextService->getSignatureHeight(), |
| 54 | ], |
| 55 | 'envelope' => [ |
| 56 | 'is-available' => $this->envelopeService->isEnabled(), |
| 57 | ], |
| 58 | 'upload' => [ |
| 59 | 'max-file-uploads' => $this->getMaxFileUploads(), |
| 60 | ], |
| 61 | ], |
| 62 | 'version' => $this->appManager->getAppVersion('libresign'), |
| 63 | ]; |
| 64 | |
| 65 | return [ |
| 66 | 'libresign' => $capabilities, |
| 67 | ]; |
| 68 | } |
| 69 | |
| 70 | private function getMaxFileUploads(): int { |
| 71 | $maxFileUploads = ini_get('max_file_uploads'); |
| 72 | if (!is_numeric($maxFileUploads) || (int)$maxFileUploads <= 0) { |
| 73 | return 20; |
| 74 | } |
| 75 | return (int)$maxFileUploads; |
| 76 | } |
| 77 | } |