Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MessagesLoader | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
10 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| loadMessages | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
9 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors |
| 7 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | */ |
| 9 | |
| 10 | namespace OCA\Libresign\Service\File; |
| 11 | |
| 12 | use OCA\Libresign\Db\File; |
| 13 | use OCP\IL10N; |
| 14 | use stdClass; |
| 15 | |
| 16 | class MessagesLoader { |
| 17 | public function __construct( |
| 18 | private SignersLoader $signersLoader, |
| 19 | private IL10N $l10n, |
| 20 | ) { |
| 21 | } |
| 22 | |
| 23 | public function loadMessages( |
| 24 | ?File $file, |
| 25 | stdClass $fileData, |
| 26 | FileResponseOptions $options, |
| 27 | array $certData = [], |
| 28 | ): void { |
| 29 | if (!$options->isShowMessages()) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | $messages = []; |
| 34 | |
| 35 | if (isset($fileData->settings['canSign']) && $fileData->settings['canSign']) { |
| 36 | $messages[] = [ |
| 37 | 'type' => 'info', |
| 38 | // TRANSLATORS: Informational message shown in the file details UI when the current user is one of the required signers and still needs to sign the document. |
| 39 | 'message' => $this->l10n->t('You need to sign this document') |
| 40 | ]; |
| 41 | } |
| 42 | |
| 43 | if ( |
| 44 | $file instanceof File |
| 45 | && isset($fileData->settings['canRequestSign']) |
| 46 | && $fileData->settings['canRequestSign'] |
| 47 | ) { |
| 48 | $this->signersLoader->loadLibreSignSigners($file, $fileData, $options, $certData); |
| 49 | |
| 50 | if (empty($fileData->signers)) { |
| 51 | $messages[] = [ |
| 52 | 'type' => 'info', |
| 53 | // TRANSLATORS: Informational message shown when the current user can request signatures in general, but no eligible signer can be added for this specific document. |
| 54 | 'message' => $this->l10n->t('You cannot create a signature request for this document. Please contact your administrator.') |
| 55 | ]; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | if (!empty($messages)) { |
| 60 | $fileData->messages = $messages; |
| 61 | } |
| 62 | } |
| 63 | } |