Skip to content

Commit 4513d98

Browse files
fix: handle envelope child signers
Derive envelope ids from parent files when propagating identified dates and signing child documents, skip updating the active sign request, and avoid returning partially cached children lists. Signed-off-by: Vitor Mattos <[email protected]>
1 parent 4c1e98b commit 4513d98

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

lib/Db/FileMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public function neutralizeDeletedUser(string $userId, string $displayName): void
281281
*/
282282
public function getChildrenFiles(int $parentId): array {
283283
$cached = array_filter($this->file, fn ($f) => $f->getParentFileId() === $parentId);
284-
if (!empty($cached)) {
284+
if (!empty($cached) && count($cached) > 1) {
285285
return array_values($cached);
286286
}
287287

lib/Service/IdentifyMethod/IdentifyService.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,25 @@ private function propagateIdentifiedDateToEnvelopeChildren(IdentifyMethod $ident
6767
$signRequest = $this->signRequestMapper->getById($identifyMethod->getSignRequestId());
6868
$fileEntity = $this->fileMapper->getById($signRequest->getFileId());
6969

70-
if (method_exists($fileEntity, 'getNodeType') && $fileEntity->getNodeType() !== 'envelope') {
70+
if ($fileEntity->getNodeType() === 'envelope') {
71+
$envelopeId = $fileEntity->getId();
72+
} elseif ($fileEntity->hasParent()) {
73+
$envelopeId = $fileEntity->getParentFileId();
74+
} else {
7175
return;
7276
}
7377

7478
$children = $this->signRequestMapper->getByEnvelopeChildrenAndIdentifyMethod(
75-
$fileEntity->getId(),
79+
$envelopeId,
7680
$signRequest->getId(),
7781
);
7882

7983
foreach ($children as $childSignRequest) {
84+
// Skip the current sign request to avoid updating it twice
85+
if ($childSignRequest->getId() === $signRequest->getId()) {
86+
continue;
87+
}
88+
8089
$childMethods = $this->identifyMethodMapper->getIdentifyMethodsFromSignRequestId($childSignRequest->getId());
8190

8291
foreach ($childMethods as $childEntity) {

lib/Service/SignFileService.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,21 +388,26 @@ public function sign(): void {
388388
* @return array Array of ['file' => FileEntity, 'signRequest' => SignRequestEntity]
389389
*/
390390
private function getSignRequestsToSign(): array {
391-
if (!$this->libreSignFile->isEnvelope()) {
391+
if (!$this->libreSignFile->isEnvelope()
392+
&& !$this->libreSignFile->hasParent()
393+
) {
392394
return [[
393395
'file' => $this->libreSignFile,
394396
'signRequest' => $this->signRequest,
395397
]];
396398
}
397399

398-
$childFiles = $this->fileMapper->getChildrenFiles($this->libreSignFile->getId());
400+
$envelopeId = $this->libreSignFile->isEnvelope()
401+
? $this->libreSignFile->getId()
402+
: $this->libreSignFile->getParentFileId();
399403

404+
$childFiles = $this->fileMapper->getChildrenFiles($envelopeId);
400405
if (empty($childFiles)) {
401406
throw new LibresignException('No files found in envelope');
402407
}
403408

404409
$childSignRequests = $this->signRequestMapper->getByEnvelopeChildrenAndIdentifyMethod(
405-
$this->libreSignFile->getId(),
410+
$envelopeId,
406411
$this->signRequest->getId()
407412
);
408413

0 commit comments

Comments
 (0)