• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LibreSign / libresign / 21257929909

22 Jan 2026 05:17PM UTC coverage: 44.867%. First build
21257929909

Pull #6520

github

web-flow
Merge 3974c717f into cf0454786
Pull Request #6520: fix: prevent cache race condition workers

108 of 162 new or added lines in 8 files covered. (66.67%)

7264 of 16190 relevant lines covered (44.87%)

4.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

56.0
/lib/Service/NotifyService.php
1
<?php
2

3
declare(strict_types=1);
4
/**
5
 * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
6
 * SPDX-License-Identifier: AGPL-3.0-or-later
7
 */
8

9
namespace OCA\Libresign\Service;
10

11
use OCA\Libresign\AppInfo\Application;
12
use OCA\Libresign\Db\SignRequest;
13
use OCA\Libresign\Db\SignRequestMapper;
14
use OCA\Libresign\Helper\ValidateHelper;
15
use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod;
16
use OCP\AppFramework\Utility\ITimeFactory;
17
use OCP\IL10N;
18
use OCP\IUser;
19
use OCP\IUserSession;
20
use OCP\Notification\IManager;
21

22
class NotifyService {
23
        public function __construct(
24
                private ValidateHelper $validateHelper,
25
                private IUserSession $userSession,
26
                private SignRequestMapper $signRequestMapper,
27
                private IdentifyMethodService $identifyMethodService,
28
                private SignerIndexProvider $signerIndexProvider,
29
                private SignerNotificationPolicy $signerNotificationPolicy,
30
                private ITimeFactory $timeFactory,
31
                private IManager $notificationManager,
32
                private IL10N $l10n,
33
        ) {
34
        }
2✔
35

36
        public function signer(int $fileId, int $signRequestId): void {
37
                $this->validateHelper->canRequestSign($this->userSession->getUser());
×
38
                $this->validateHelper->validateLibreSignFileId($fileId);
×
39
                $signRequest = $this->signRequestMapper->getByFileIdAndSignRequestId($fileId, $signRequestId);
×
40
                $this->validateHelper->iRequestedSignThisFile($this->userSession->getUser(), $fileId);
×
41
                $this->notify($signRequest);
×
42
        }
43

44
        public function signers(int $fileId, array $signers): void {
45
                $this->validateHelper->canRequestSign($this->userSession->getUser());
2✔
46
                $this->validateHelper->validateLibreSignFileId($fileId);
1✔
47
                $signRequests = $this->signRequestMapper->getByFileId($fileId);
1✔
48
                if (!empty($signRequests)) {
1✔
49
                        $this->validateHelper->iRequestedSignThisFile($this->userSession->getUser(), $fileId);
1✔
50
                }
51
                $signRequestIndex = $this->signerIndexProvider->build($signRequests);
1✔
52
                foreach ($signers as $signer) {
1✔
53
                        $this->validateHelper->haveValidMail($signer);
1✔
54
                        $this->validateSignerForNotification($signer, $signRequestIndex);
1✔
55
                }
56
                // @todo refactor this code
57
                foreach ($signRequests as $signRequest) {
1✔
58
                        $this->notify($signRequest, $signers);
1✔
59
                }
60
        }
61

62
        public function notificationDismiss(
63
                string $objectType,
64
                int $objectId,
65
                string $subject,
66
                IUser $user,
67
                int $timestamp,
68
        ): void {
69
                $notification = $this->notificationManager->createNotification();
×
70
                $notification->setApp(Application::APP_ID)
×
71
                        ->setObject($objectType, (string)$objectId)
×
72
                        ->setDateTime($this->timeFactory->getDateTime('@' . $timestamp))
×
73
                        ->setUser($user->getUID())
×
74
                        ->setSubject($subject);
×
75
                $this->notificationManager->markProcessed($notification);
×
76
        }
77

78
        private function notify(SignRequest $signRequest, array $signers = []): void {
79
                $identifyMethods = $this->identifyMethodService->getIdentifyMethodsFromSignRequestId($signRequest->getId());
1✔
80
                foreach ($identifyMethods as $methodName => $instances) {
1✔
81
                        $identifyMethod = array_reduce($instances, function (?IIdentifyMethod $carry, IIdentifyMethod $identifyMethod) use ($signers): ?IIdentifyMethod {
1✔
82
                                foreach ($signers as $signer) {
1✔
83
                                        $key = key($signer);
1✔
84
                                        $value = current($signer);
1✔
85
                                        $entity = $identifyMethod->getEntity();
1✔
86
                                        if ($entity->getIdentifierKey() === $key
1✔
87
                                                && $entity->getIdentifierValue() === $value
1✔
88
                                        ) {
89
                                                return $identifyMethod;
1✔
90
                                        }
91
                                }
92
                                return $carry;
×
93
                        });
1✔
94
                        if ($identifyMethod instanceof IIdentifyMethod) {
1✔
95
                                $identifyMethod->willNotifyUser(true);
1✔
96
                                $identifyMethod->notify();
1✔
97
                        } else {
98
                                foreach ($instances as $instance) {
×
99
                                        $instance->willNotifyUser(true);
×
100
                                        $instance->notify();
×
101
                                }
102
                        }
103
                }
104
        }
105

106
        /**
107
         * @param array<string, SignRequest[]> $signRequestIndex Indexed by identifierKey:identifierValue
108
         * @throws \OCA\Libresign\Exception\LibresignException
109
         */
110
        private function validateSignerForNotification(array $signer, array $signRequestIndex): void {
111
                $error = $this->signerNotificationPolicy->getValidationError($signer, $signRequestIndex);
1✔
112
                if ($error !== null) {
1✔
NEW
113
                        $message = match ($error['code']) {
×
NEW
114
                                'not_requested' => $this->l10n->t('No signature was requested to %s', $error['params']),
×
NEW
115
                                'already_signed' => $this->l10n->t('%s already signed this file', $error['params']),
×
NEW
116
                                default => $this->l10n->t('Invalid signer data'),
×
NEW
117
                        };
×
NEW
118
                        throw new \OCA\Libresign\Exception\LibresignException($message);
×
119
                }
120
        }
121
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc