Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
86.67% |
13 / 15 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| NotificationDeliveryRegistrar | |
86.67% |
13 / 15 |
|
50.00% |
1 / 2 |
3.02 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| register | |
85.71% |
12 / 14 |
|
0.00% |
0 / 1 |
2.01 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Service\Notification; |
| 10 | |
| 11 | use OCA\Libresign\Db\NotificationDelivery; |
| 12 | use OCA\Libresign\Db\NotificationDeliveryMapper; |
| 13 | use OCP\IDBConnection; |
| 14 | use OCP\Security\ICrypto; |
| 15 | |
| 16 | /** |
| 17 | * Prepare a durable delivery identity before invoking any external transport. |
| 18 | * |
| 19 | * Keep database, identity and encryption concerns outside the transport |
| 20 | * orchestration. Registration is intentionally separate from attempt claiming. |
| 21 | */ |
| 22 | final class NotificationDeliveryRegistrar { |
| 23 | public function __construct( |
| 24 | private NotificationDeliveryMapper $deliveries, |
| 25 | private NotificationDeliveryKeyFactory $keys, |
| 26 | private ICrypto $crypto, |
| 27 | private IDBConnection $db, |
| 28 | ) { |
| 29 | } |
| 30 | |
| 31 | public function register(NotificationMessage $message, NotificationChannel $channel, ?string $encodedMessage = null): NotificationDelivery { |
| 32 | $keys = $this->keys->keys($message, $channel); |
| 33 | try { |
| 34 | return $this->deliveries->register( |
| 35 | $keys['eventKey'], |
| 36 | $keys['correlationId'], |
| 37 | $message->eventType, |
| 38 | $message->channel, |
| 39 | $message->file->getId(), |
| 40 | $message->signRequest->getId(), |
| 41 | $message->file->getUserId(), |
| 42 | $this->crypto->encrypt($message->recipient), |
| 43 | $encodedMessage, |
| 44 | ); |
| 45 | } catch (\OCP\DB\Exception $e) { |
| 46 | // The domain transaction must roll back when an intent cannot be stored. |
| 47 | throw new \LogicException('Notification intent could not be persisted', 0, $e); |
| 48 | } |
| 49 | } |
| 50 | } |