Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/Service/File/EnvelopeAssembler.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ public function buildEnvelopeChildData(File $childFile, \OCA\Libresign\Service\F

foreach ($signRequests as $signRequest) {
$identifyMethods = $identifyMethodsBatch[$signRequest->getId()] ?? [];
$identifyMethodsArray = [];
$signerUid = null;
foreach ($identifyMethods as $methods) {
foreach ($methods as $identifyMethod) {
$entity = $identifyMethod->getEntity();
$identifyMethodsArray[] = [
'method' => $entity->getIdentifierKey(),
'value' => $entity->getIdentifierValue(),
'mandatory' => $entity->getMandatory(),
];
$signerUid ??= $entity->getUniqueIdentifier();
}
}

$email = '';
foreach ($identifyMethods[IdentifyMethodService::IDENTIFY_EMAIL] ?? [] as $identifyMethod) {
Expand All @@ -94,9 +107,12 @@ public function buildEnvelopeChildData(File $childFile, \OCA\Libresign\Service\F
$signer->signRequestId = $signRequest->getId();
$signer->displayName = $displayName;
$signer->email = $email;
$signer->uid = $signerUid;
$signer->signed = $signed;
$signer->status = $signRequest->getStatus();
$signer->statusText = $this->signRequestMapper->getTextOfSignerStatus($signRequest->getStatus());
$signer->identifyMethods = $identifyMethodsArray;
$signer->metadata = $signRequest->getMetadata();
$fileData->signers[] = $signer;
}

Expand Down
67 changes: 63 additions & 4 deletions tests/php/Unit/Service/File/EnvelopeAssemblerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@

use OCA\Libresign\Db\File as DbFile;
use OCA\Libresign\Db\FileMapper;
use OCA\Libresign\Db\IdentifyMethod;
use OCA\Libresign\Db\SignRequest as DbSignRequest;
use OCA\Libresign\Db\SignRequestMapper;
use OCA\Libresign\Handler\SignEngine\Pkcs12Handler;
use OCA\Libresign\Service\File\EnvelopeAssembler;
use OCA\Libresign\Service\File\FileResponseOptions;
use OCA\Libresign\Service\File\SignersLoader;
use OCA\Libresign\Service\FileElementService;
use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod;
use OCA\Libresign\Service\IdentifyMethodService;
use OCP\Files\File;
use OCP\Files\Folder;
Expand Down Expand Up @@ -77,7 +79,7 @@ public function testBuildsChildDataWithoutCertificateChain(): void {
$this->signRequestMapper->method('getByFileId')->willReturn([$signRequest]);

$this->identifyMethodService->method('setIsRequest')->willReturnSelf();
$this->identifyMethodService->method('getIdentifyMethodsFromSignRequestId')->willReturn([]);
$this->identifyMethodService->method('getIdentifyMethodsFromSignRequestIds')->willReturn([]);

$this->fileMapper->method('getTextOfStatus')->willReturn('status-text');

Expand Down Expand Up @@ -131,7 +133,7 @@ public function testBuildsChildDataWithVisibleElements(): void {
]);

$this->identifyMethodService->method('setIsRequest')->willReturnSelf();
$this->identifyMethodService->method('getIdentifyMethodsFromSignRequestId')->willReturn([]);
$this->identifyMethodService->method('getIdentifyMethodsFromSignRequestIds')->willReturn([]);

$this->fileMapper->method('getTextOfStatus')->willReturn('pending');

Expand Down Expand Up @@ -172,7 +174,7 @@ public function testBuildsChildDataWithoutVisibleElementsWhenNotRequested(): voi
$this->signRequestMapper->expects($this->never())->method('getVisibleElementsFromSigners');

$this->identifyMethodService->method('setIsRequest')->willReturnSelf();
$this->identifyMethodService->method('getIdentifyMethodsFromSignRequestId')->willReturn([]);
$this->identifyMethodService->method('getIdentifyMethodsFromSignRequestIds')->willReturn([]);

$this->fileMapper->method('getTextOfStatus')->willReturn('pending');

Expand Down Expand Up @@ -214,7 +216,7 @@ public function testBuildsChildDataWithMultipleSigners(): void {
$this->signRequestMapper->method('getByFileId')->willReturn([$signer1, $signer2]);

$this->identifyMethodService->method('setIsRequest')->willReturnSelf();
$this->identifyMethodService->method('getIdentifyMethodsFromSignRequestId')->willReturn([]);
$this->identifyMethodService->method('getIdentifyMethodsFromSignRequestIds')->willReturn([]);

$this->fileMapper->method('getTextOfStatus')->willReturn('partial');

Expand All @@ -237,6 +239,63 @@ public function testBuildsChildDataWithMultipleSigners(): void {
$this->assertEquals(2, $result->signers[1]->signRequestId);
}

public function testBuildsChildDataIncludesIdentifyMethodsAndMetadata(): void {
$this->mockFileNode();

$signRequest = new DbSignRequest();
$signRequest->setId(99);
$signRequest->setDisplayName('Signer');
$signRequest->setStatus(1);
$signRequest->setMetadata(['certificate_info' => ['serialNumber' => '1234']]);

$this->signRequestMapper->method('getByFileId')->willReturn([$signRequest]);

$identifyEntity = new IdentifyMethod();
$identifyEntity->setIdentifierKey(IdentifyMethodService::IDENTIFY_EMAIL);
$identifyEntity->setIdentifierValue('signer@example.com');
$identifyEntity->setMandatory(1);

$identifyMethod = $this->createMock(IIdentifyMethod::class);
$identifyMethod->method('getEntity')->willReturn($identifyEntity);

$this->identifyMethodService->method('setIsRequest')->willReturnSelf();
$this->identifyMethodService->method('getIdentifyMethodsFromSignRequestIds')->willReturn([
99 => [
IdentifyMethodService::IDENTIFY_EMAIL => [$identifyMethod],
],
]);

$this->fileMapper->method('getTextOfStatus')->willReturn('pending');

$assembler = $this->getService();

$childFile = new DbFile();
$childFile->setId(44);
$childFile->setUuid('uuid-44');
$childFile->setName('agreement.pdf');
$childFile->setStatus(1);
$childFile->setNodeId(500);
$childFile->setMetadata(['p' => 1]);
$childFile->setUserId('user1');

$options = new FileResponseOptions();
$result = $assembler->buildEnvelopeChildData($childFile, $options);

$this->assertCount(1, $result->signers);
$this->assertSame('email:signer@example.com', $result->signers[0]->uid);
$this->assertSame(
[
[
'method' => IdentifyMethodService::IDENTIFY_EMAIL,
'value' => 'signer@example.com',
'mandatory' => 1,
],
],
$result->signers[0]->identifyMethods
);
$this->assertSame(['certificate_info' => ['serialNumber' => '1234']], $result->signers[0]->metadata);
}

private function createMockFileElement(
int $id,
int $signRequestId,
Expand Down
Loading