Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
70.59% |
12 / 17 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| SignedEventFactory | |
70.59% |
12 / 17 |
|
50.00% |
2 / 4 |
5.64 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| make | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| getIdentifyMethod | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUser | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 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\Events; |
| 10 | |
| 11 | use OCA\Libresign\Db\File as FileEntity; |
| 12 | use OCA\Libresign\Db\SignRequest; |
| 13 | use OCA\Libresign\Exception\LibresignException; |
| 14 | use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod; |
| 15 | use OCA\Libresign\Service\IdentifyMethodService; |
| 16 | use OCP\Files\File; |
| 17 | use OCP\IL10N; |
| 18 | use OCP\IUser; |
| 19 | use OCP\IUserManager; |
| 20 | |
| 21 | class SignedEventFactory { |
| 22 | public function __construct( |
| 23 | private IUserManager $userManager, |
| 24 | private IdentifyMethodService $identifyMethodService, |
| 25 | private IL10N $l10n, |
| 26 | ) { |
| 27 | } |
| 28 | |
| 29 | public function make( |
| 30 | SignRequest $signRequest, |
| 31 | FileEntity $libreSignFile, |
| 32 | File $signedFile, |
| 33 | bool $signedWithoutPassword = false, |
| 34 | ?string $certificateSerialNumber = null, |
| 35 | ): SignedEvent { |
| 36 | $identifyMethod = $this->getIdentifyMethod($signRequest); |
| 37 | $user = $this->getUser($libreSignFile); |
| 38 | return new SignedEvent( |
| 39 | $signRequest, |
| 40 | $libreSignFile, |
| 41 | $identifyMethod, |
| 42 | $user, |
| 43 | $signedFile, |
| 44 | $signedWithoutPassword, |
| 45 | $certificateSerialNumber, |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | protected function getIdentifyMethod(SignRequest $signRequest): IIdentifyMethod { |
| 50 | return $this->identifyMethodService->getIdentifiedMethod($signRequest->getId()); |
| 51 | } |
| 52 | |
| 53 | protected function getUser(FileEntity $libreSignFile): IUser { |
| 54 | $user = $this->userManager->get($libreSignFile->getUserId()); |
| 55 | if (!$user instanceof IUser) { |
| 56 | // TRANSLATORS Error when building the post-signature event and the Nextcloud user linked to the signer cannot be found. |
| 57 | throw new LibresignException($this->l10n->t('User not found.')); |
| 58 | } |
| 59 | return $user; |
| 60 | } |
| 61 | } |