Skip to content

Commit de3beb6

Browse files
committed
feat: delegate PDF URL generation to service layer
- Add getPdfUrls() method in PageController - Delegate to SignFileService::getPdfUrlsForSigning() - Provide pdfs array to initial state instead of single pdf - Adapt getPdfFile() to use array response Signed-off-by: Vitor Mattos <[email protected]>
1 parent 9626b83 commit de3beb6

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

lib/Controller/PageController.php

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,7 @@ public function sign(string $uuid): TemplateResponse {
329329
$this->provideSignerSignatues();
330330
$this->initialState->provideInitialState('token_length', TokenService::TOKEN_LENGTH);
331331
$this->initialState->provideInitialState('description', $this->getSignRequestEntity()->getDescription() ?? '');
332-
$this->initialState->provideInitialState('pdf',
333-
$this->signFileService->getFileUrl('url', $this->getFileEntity(), $this->getNextcloudFile(), $uuid)
334-
);
332+
$this->initialState->provideInitialState('pdfs', $this->getPdfUrls());
335333
$this->initialState->provideInitialState('nodeId', $this->getFileEntity()->getNodeId());
336334

337335
Util::addScript(Application::APP_ID, 'libresign-external');
@@ -354,6 +352,16 @@ private function provideSignerSignatues(): void {
354352
$this->initialState->provideInitialState('user_signatures', $signatures);
355353
}
356354

355+
/**
356+
* @return string[] Array of PDF URLs
357+
*/
358+
private function getPdfUrls(): array {
359+
return $this->signFileService->getPdfUrlsForSigning(
360+
$this->getFileEntity(),
361+
$this->getSignRequestEntity()
362+
);
363+
}
364+
357365
/**
358366
* Show signature page
359367
*
@@ -409,10 +417,9 @@ public function signIdDoc($uuid): TemplateResponse {
409417
$this->initialState->provideInitialState('signature_methods', $signatureMethods);
410418
$this->initialState->provideInitialState('token_length', TokenService::TOKEN_LENGTH);
411419
$this->initialState->provideInitialState('description', '');
412-
$nextcloudFile = $this->signFileService->getNextcloudFile($fileEntity);
413-
$this->initialState->provideInitialState('pdf',
414-
$this->signFileService->getFileUrl('url', $fileEntity, $nextcloudFile, $uuid)
415-
);
420+
$this->initialState->provideInitialState('pdf', [
421+
'url' => $this->signFileService->getFileUrl($fileEntity->getId(), $uuid)
422+
]);
416423

417424
Util::addScript(Application::APP_ID, 'libresign-external');
418425
$response = new TemplateResponse(Application::APP_ID, 'external', [], TemplateResponse::RENDER_AS_BASE);
@@ -469,7 +476,14 @@ public function getPdf($uuid) {
469476
#[AnonRateLimit(limit: 30, period: 60)]
470477
#[FrontpageRoute(verb: 'GET', url: '/pdf/{uuid}')]
471478
public function getPdfFile($uuid): FileDisplayResponse {
472-
$file = $this->getNextcloudFile();
479+
$files = $this->getNextcloudFiles();
480+
if (empty($files)) {
481+
throw new LibresignException(json_encode([
482+
'action' => JSActions::ACTION_DO_NOTHING,
483+
'errors' => [['message' => $this->l10n->t('File not found')]],
484+
]), Http::STATUS_NOT_FOUND);
485+
}
486+
$file = current($files);
473487
return new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
474488
}
475489

@@ -498,9 +512,7 @@ public function validation(): TemplateResponse {
498512
'description' => $this->getSignRequestEntity()?->getDescription(),
499513
]);
500514
$this->initialState->provideInitialState('filename', $this->getFileEntity()?->getName());
501-
$this->initialState->provideInitialState('pdf',
502-
$this->signFileService->getFileUrl('url', $this->getFileEntity(), $this->getNextcloudFile(), $this->request->getParam('uuid'))
503-
);
515+
$this->initialState->provideInitialState('pdfs', $this->getPdfUrls());
504516
$this->initialState->provideInitialState('signer',
505517
$this->signFileService->getSignerData(
506518
$this->userSession->getUser(),

0 commit comments

Comments
 (0)