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
5 changes: 3 additions & 2 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ public function sign(string $uuid): TemplateResponse {
$this->initialState->provideInitialState('status', $file['status']);
$this->initialState->provideInitialState('statusText', $file['statusText']);
$this->initialState->provideInitialState('signers', $file['signers']);
$this->initialState->provideInitialState('visibleElements', $file['visibleElements'] ?? []);
$this->initialState->provideInitialState('sign_request_uuid', $uuid);
$this->provideSignerSignatues();
$this->initialState->provideInitialState('token_length', TokenService::TOKEN_LENGTH);
Expand Down Expand Up @@ -475,8 +476,8 @@ public function signIdDoc($uuid): TemplateResponse {
$this->initialState->provideInitialState('nodeId', $file['nodeId']);
$this->initialState->provideInitialState('status', $file['status']);
$this->initialState->provideInitialState('statusText', $file['statusText']);
$this->initialState->provideInitialState('visibleElements', []);
$this->initialState->provideInitialState('signers', []);
$this->initialState->provideInitialState('visibleElements', $file['visibleElements'] ?? []);
$this->initialState->provideInitialState('signers', $file['signers'] ?? []);
$this->provideSignerSignatues();
$signatureMethods = $this->identifyMethodService->getSignMethodsOfIdentifiedFactors($this->getSignRequestEntity()->getId());
$this->initialState->provideInitialState('signature_methods', $signatureMethods);
Expand Down
33 changes: 16 additions & 17 deletions lib/Service/FileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,25 +454,23 @@ private function loadLibreSignData(): void {
if (!isset($this->fileData->files) || !is_array($this->fileData->files)) {
$this->fileData->files = [];
}
}

if ($this->options->isShowVisibleElements()) {
$signers = $this->signRequestMapper->getByMultipleFileId([$this->file->getId()]);
$this->fileData->visibleElements = [];
foreach ($this->signRequestMapper->getVisibleElementsFromSigners($signers) as $visibleElements) {
if (empty($visibleElements)) {
continue;
}
$file = array_filter($this->fileData->files, fn (stdClass $file) => $file->id === $visibleElements[0]->getFileId());
if (empty($file)) {
continue;
}
$file = current($file);
$fileMetadata = $this->file->getMetadata();
$this->fileData->visibleElements = array_merge(
$this->fileElementService->formatVisibleElements($visibleElements, $fileMetadata),
$this->fileData->visibleElements
);
private function loadVisibleElements(): void {
if (!$this->options->isShowVisibleElements()) {
return;
}
$signers = $this->signRequestMapper->getByMultipleFileId([$this->file->getId()]);
$this->fileData->visibleElements = [];
$fileMetadata = $this->file->getMetadata();
foreach ($this->signRequestMapper->getVisibleElementsFromSigners($signers) as $visibleElements) {
if (empty($visibleElements)) {
continue;
}
$this->fileData->visibleElements = array_merge(
$this->fileElementService->formatVisibleElements($visibleElements, $fileMetadata),
$this->fileData->visibleElements
);
}
}

Expand Down Expand Up @@ -550,6 +548,7 @@ public function toArray(): array {
$this->loadFileMetadata();
$this->loadSettings();
$this->loadSigners();
$this->loadVisibleElements();
$this->loadMessages();
$this->computeEnvelopeSignersProgress();

Expand Down
2 changes: 2 additions & 0 deletions src/store/sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const defaultState = {
nodeType: 'file',
uuid: '',
signers: [],
visibleElements: [],
},
mounted: false,
}
Expand All @@ -46,6 +47,7 @@ export const useSignStore = defineStore('sign', {
nodeType: loadState('libresign', 'nodeType', ''),
uuid: loadState('libresign', 'uuid', null),
signers: loadState('libresign', 'signers', []),
visibleElements: loadState('libresign', 'visibleElements', []),
}
const filesStore = useFilesStore()
const sidebarStore = useSidebarStore()
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Unit/Service/AsyncSigningServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use OCA\Libresign\Db\SignRequest;
use OCA\Libresign\Enum\FileStatus;
use OCA\Libresign\Service\AsyncSigningService;
use OCA\Libresign\Service\WorkerHealthService;
use OCA\Libresign\Service\Worker\WorkerHealthService;
use OCP\BackgroundJob\IJobList;
use OCP\IUser;
use OCP\Security\ICredentialsManager;
Expand Down
50 changes: 50 additions & 0 deletions tests/php/Unit/Service/FileServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use OCA\Libresign\Exception\LibresignException;
use OCA\Libresign\Service\FileService;
use PHPUnit\Framework\Attributes\DataProvider;

final class FileServiceTest extends \OCA\Libresign\Tests\Unit\TestCase {
private $fileMapper;
Expand Down Expand Up @@ -296,4 +297,53 @@ public function testDeleteWithoutDeletingFile(): void {

$service->delete(1, false);
}

#[DataProvider('providerTestVisibleElements')]
public function testVisibleElements(bool $showVisibleElementsFlag, bool $expectedInResult): void {
$file = new \OCA\Libresign\Db\File();
$file->setId(1);
$file->setUuid('test-uuid');
$file->setName('test.pdf');
$file->setStatus(1);
$file->setCreatedAt(new \DateTime());
$file->setNodeId(100);
$file->setSignatureFlow('');
$file->setDocmdpLevel('');

$file->setUserId('testuser');

$user = $this->createMock(\OCP\IUser::class);
$user->method('getDisplayName')->willReturn('Test User');

$this->fileMapper->method('getById')->willReturn($file);
$this->fileMapper->method('getTextOfStatus')->willReturn('Status text');
$this->userManager->method('get')->willReturn($user);
$this->signRequestMapper->method('getByMultipleFileId')->willReturn([]);
if ($showVisibleElementsFlag) {
$this->signRequestMapper->method('getVisibleElementsFromSigners')->willReturn([]);
}

$service = $this->createFileService();
$chainedService = $service->setFile($file);

if ($showVisibleElementsFlag) {
$chainedService->showVisibleElements();
}

$result = $chainedService->toArray();

if ($expectedInResult) {
$this->assertArrayHasKey('visibleElements', $result);
$this->assertIsArray($result['visibleElements']);
} else {
$this->assertArrayNotHasKey('visibleElements', $result);
}
}

public static function providerTestVisibleElements(): array {
return [
'visible elements included when showVisibleElements() called' => [true, true],
'visible elements not included when showVisibleElements() not called' => [false, false],
];
}
}
Loading