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

LibreSign / libresign / 20621495436

31 Dec 2025 02:59PM UTC coverage: 44.647%. First build
20621495436

Pull #6256

github

web-flow
Merge 4343635f1 into 27812ed76
Pull Request #6256: feat: add dashboard pending signatures widget

57 of 239 new or added lines in 16 files covered. (23.85%)

6618 of 14823 relevant lines covered (44.65%)

5.05 hits per line

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

83.33
/lib/Service/IdentifyMethod/IdentifyService.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\IdentifyMethod;
10

11
use OCA\Libresign\AppInfo\Application;
12
use OCA\Libresign\Db\FileMapper;
13
use OCA\Libresign\Db\IdentifyMethod;
14
use OCA\Libresign\Db\IdentifyMethodMapper;
15
use OCA\Libresign\Db\SignRequestMapper;
16
use OCA\Libresign\Service\SessionService;
17
use OCP\AppFramework\Utility\ITimeFactory;
18
use OCP\EventDispatcher\IEventDispatcher;
19
use OCP\Files\IRootFolder;
20
use OCP\IAppConfig;
21
use OCP\IL10N;
22
use OCP\IURLGenerator;
23
use OCP\IUserManager;
24
use OCP\Security\IHasher;
25
use Psr\Log\LoggerInterface;
26

27
class IdentifyService {
28
        private array $savedSettings = [];
29
        public function __construct(
30
                private IdentifyMethodMapper $identifyMethodMapper,
31
                private SessionService $sessionService,
32
                private ITimeFactory $timeFactory,
33
                private IEventDispatcher $eventDispatcher,
34
                private IRootFolder $root,
35
                private IAppConfig $appConfig,
36
                private SignRequestMapper $signRequestMapper,
37
                private IL10N $l10n,
38
                private FileMapper $fileMapper,
39
                private IHasher $hasher,
40
                private IUserManager $userManager,
41
                private IURLGenerator $urlGenerator,
42
                private LoggerInterface $logger,
43
        ) {
44
        }
48✔
45

46
        public function save(IdentifyMethod $identifyMethod): void {
47
                $this->refreshIdFromDatabaseIfNecessary($identifyMethod);
14✔
48
                if ($identifyMethod->getId()) {
14✔
49
                        $this->identifyMethodMapper->update($identifyMethod);
2✔
50
                        $this->propagateIdentifiedDateToEnvelopeChildren($identifyMethod);
2✔
51
                        return;
2✔
52
                }
53
                $this->identifyMethodMapper->insertOrUpdate($identifyMethod);
14✔
54
                $this->propagateIdentifiedDateToEnvelopeChildren($identifyMethod);
14✔
55
                return;
14✔
56
        }
57

58
        private function propagateIdentifiedDateToEnvelopeChildren(IdentifyMethod $identifyMethod): void {
59
                if (!$identifyMethod->getIdentifiedAtDate()) {
14✔
60
                        return;
13✔
61
                }
62

63
                if (!$identifyMethod->getSignRequestId()) {
3✔
64
                        return;
×
65
                }
66

67
                $signRequest = $this->signRequestMapper->getById($identifyMethod->getSignRequestId());
3✔
68
                $fileEntity = $this->fileMapper->getById($signRequest->getFileId());
3✔
69

70
                if ($fileEntity->getNodeType() === 'envelope') {
3✔
NEW
71
                        $envelopeId = $fileEntity->getId();
×
72
                } elseif ($fileEntity->hasParent()) {
3✔
73
                        $envelopeId = $fileEntity->getParentFileId();
1✔
74
                } else {
75
                        return;
2✔
76
                }
77

78
                $children = $this->signRequestMapper->getByEnvelopeChildrenAndIdentifyMethod(
1✔
79
                        $envelopeId,
1✔
80
                        $signRequest->getId(),
1✔
81
                );
1✔
82

83
                foreach ($children as $childSignRequest) {
1✔
84
                        // Skip the current sign request to avoid updating it twice
85
                        if ($childSignRequest->getId() === $signRequest->getId()) {
1✔
86
                                continue;
1✔
87
                        }
88

89
                        $childMethods = $this->identifyMethodMapper->getIdentifyMethodsFromSignRequestId($childSignRequest->getId());
1✔
90

91
                        foreach ($childMethods as $childEntity) {
1✔
92
                                if (
93
                                        $childEntity->getIdentifierKey() === $identifyMethod->getIdentifierKey()
1✔
94
                                        && $childEntity->getIdentifierValue() === $identifyMethod->getIdentifierValue()
1✔
95
                                ) {
96
                                        $childEntity->setIdentifiedAtDate($identifyMethod->getIdentifiedAtDate());
1✔
97
                                        $this->identifyMethodMapper->update($childEntity);
1✔
98
                                }
99
                        }
100
                }
101
        }
102

103
        public function delete(IdentifyMethod $identifyMethod): void {
104
                if ($identifyMethod->getId()) {
×
105
                        $this->identifyMethodMapper->delete($identifyMethod);
×
106
                }
107
        }
108

109
        private function refreshIdFromDatabaseIfNecessary(IdentifyMethod $identifyMethod): void {
110
                if ($identifyMethod->getId()) {
14✔
111
                        return;
2✔
112
                }
113
                if (!$identifyMethod->getSignRequestId() || !$identifyMethod->getIdentifierKey()) {
14✔
114
                        return;
×
115
                }
116

117
                $identifyMethods = $this->identifyMethodMapper->getIdentifyMethodsFromSignRequestId($identifyMethod->getSignRequestId());
14✔
118
                $exists = array_filter($identifyMethods, fn (IdentifyMethod $current): bool => $current->getIdentifierKey() === $identifyMethod->getIdentifierKey());
14✔
119
                if (!$exists) {
14✔
120
                        return;
14✔
121
                }
122
                $exists = current($exists);
×
123
                $identifyMethod->setId($exists->getId());
×
124
        }
125

126
        public function getSavedSettings(): array {
127
                if (!empty($this->savedSettings)) {
13✔
128
                        return $this->savedSettings;
×
129
                }
130
                return $this->getAppConfig()->getValueArray(Application::APP_ID, 'identify_methods', []);
13✔
131
        }
132

133
        public function getEventDispatcher(): IEventDispatcher {
134
                return $this->eventDispatcher;
13✔
135
        }
136

137
        public function getSessionService(): SessionService {
138
                return $this->sessionService;
2✔
139
        }
140

141
        public function getTimeFactory(): ITimeFactory {
142
                return $this->timeFactory;
2✔
143
        }
144

145
        public function getRootFolder(): IRootFolder {
146
                return $this->root;
3✔
147
        }
148

149
        public function getAppConfig(): IAppConfig {
150
                return $this->appConfig;
13✔
151
        }
152

153
        public function getSignRequestMapper(): SignRequestMapper {
154
                return $this->signRequestMapper;
13✔
155
        }
156

157
        public function getL10n(): IL10N {
158
                return $this->l10n;
48✔
159
        }
160

161
        public function getFileMapper(): FileMapper {
162
                return $this->fileMapper;
13✔
163
        }
164

165
        public function getHasher(): IHasher {
166
                return $this->hasher;
×
167
        }
168

169
        public function getUserManager(): IUserManager {
170
                return $this->userManager;
3✔
171
        }
172

173
        public function getUrlGenerator(): IURLGenerator {
174
                return $this->urlGenerator;
13✔
175
        }
176

177
        public function getLogger(): LoggerInterface {
178
                return $this->logger;
×
179
        }
180
}
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