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

LibreSign / libresign / 20472217448

23 Dec 2025 09:41PM UTC coverage: 42.655%. First build
20472217448

Pull #6242

github

web-flow
Merge 5e8e97740 into 4f1a71d46
Pull Request #6242: feat: envelope support

301 of 1003 new or added lines in 21 files covered. (30.01%)

6159 of 14439 relevant lines covered (42.66%)

4.97 hits per line

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

70.91
/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
        }
47✔
45

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

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

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

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

70
                if (method_exists($fileEntity, 'getNodeType') && $fileEntity->getNodeType() !== 'envelope') {
2✔
NEW
71
                        return;
×
72
                }
73

74
                $children = $this->signRequestMapper->getByEnvelopeChildrenAndIdentifyMethod(
2✔
75
                        $fileEntity->getId(),
2✔
76
                        $signRequest->getId(),
2✔
77
                );
2✔
78

79
                foreach ($children as $childSignRequest) {
2✔
NEW
80
                        $childMethods = $this->identifyMethodMapper->getIdentifyMethodsFromSignRequestId($childSignRequest->getId());
×
81

NEW
82
                        foreach ($childMethods as $childEntity) {
×
83
                                if (
NEW
84
                                        $childEntity->getIdentifierKey() === $identifyMethod->getIdentifierKey()
×
NEW
85
                                        && $childEntity->getIdentifierValue() === $identifyMethod->getIdentifierValue()
×
86
                                ) {
NEW
87
                                        $childEntity->setIdentifiedAtDate($identifyMethod->getIdentifiedAtDate());
×
NEW
88
                                        $this->identifyMethodMapper->update($childEntity);
×
89
                                }
90
                        }
91
                }
92
        }
93

94
        public function delete(IdentifyMethod $identifyMethod): void {
95
                if ($identifyMethod->getId()) {
×
96
                        $this->identifyMethodMapper->delete($identifyMethod);
×
97
                }
98
        }
99

100
        private function refreshIdFromDatabaseIfNecessary(IdentifyMethod $identifyMethod): void {
101
                if ($identifyMethod->getId()) {
13✔
102
                        return;
2✔
103
                }
104
                if (!$identifyMethod->getSignRequestId() || !$identifyMethod->getIdentifierKey()) {
13✔
105
                        return;
×
106
                }
107

108
                $identifyMethods = $this->identifyMethodMapper->getIdentifyMethodsFromSignRequestId($identifyMethod->getSignRequestId());
13✔
109
                $exists = array_filter($identifyMethods, fn (IdentifyMethod $current): bool => $current->getIdentifierKey() === $identifyMethod->getIdentifierKey());
13✔
110
                if (!$exists) {
13✔
111
                        return;
13✔
112
                }
113
                $exists = current($exists);
×
114
                $identifyMethod->setId($exists->getId());
×
115
        }
116

117
        public function getSavedSettings(): array {
118
                if (!empty($this->savedSettings)) {
13✔
119
                        return $this->savedSettings;
×
120
                }
121
                return $this->getAppConfig()->getValueArray(Application::APP_ID, 'identify_methods', []);
13✔
122
        }
123

124
        public function getEventDispatcher(): IEventDispatcher {
125
                return $this->eventDispatcher;
13✔
126
        }
127

128
        public function getSessionService(): SessionService {
129
                return $this->sessionService;
2✔
130
        }
131

132
        public function getTimeFactory(): ITimeFactory {
133
                return $this->timeFactory;
2✔
134
        }
135

136
        public function getRootFolder(): IRootFolder {
137
                return $this->root;
3✔
138
        }
139

140
        public function getAppConfig(): IAppConfig {
141
                return $this->appConfig;
13✔
142
        }
143

144
        public function getSignRequestMapper(): SignRequestMapper {
145
                return $this->signRequestMapper;
13✔
146
        }
147

148
        public function getL10n(): IL10N {
149
                return $this->l10n;
48✔
150
        }
151

152
        public function getFileMapper(): FileMapper {
153
                return $this->fileMapper;
13✔
154
        }
155

156
        public function getHasher(): IHasher {
157
                return $this->hasher;
×
158
        }
159

160
        public function getUserManager(): IUserManager {
161
                return $this->userManager;
3✔
162
        }
163

164
        public function getUrlGenerator(): IURLGenerator {
165
                return $this->urlGenerator;
13✔
166
        }
167

168
        public function getLogger(): LoggerInterface {
169
                return $this->logger;
×
170
        }
171
}
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

© 2025 Coveralls, Inc