diff --git a/src/app/document/controllers/DocumentController.php b/src/app/document/controllers/DocumentController.php index 14f9c01ad3a69f9eddf58a2e5880f41e44d04bdd..9749fb12af2b68f198c2f78dffc62eab82a54f1a 100755 --- a/src/app/document/controllers/DocumentController.php +++ b/src/app/document/controllers/DocumentController.php @@ -301,6 +301,7 @@ class DocumentController } } + $hasEidas = false; foreach ($body['workflow'] as $key => $workflow) { if (!empty($workflow['processingUser'])) { $processingUser = UserModel::getByLogin(['select' => ['id'], 'login' => strtolower($workflow['processingUser'])]); @@ -322,9 +323,18 @@ class DocumentController } } } + if ($workflow['signatureMode'] == 'eidas') { + $hasEidas = true; + } $body['workflow'][$key]['userId'] = $processingUser['id']; } + $libDir = CoreConfigModel::getLibrariesDirectory(); + $loadedXml = CoreConfigModel::getConfig(); + if ($loadedXml->docaposteSignature->enable == 'true' && $hasEidas && (empty($libDir) || !is_file($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php'))) { + return $response->withStatus(500)->withJson(['errors' => 'SetaPDF-Signer library is not installed', 'lang' => 'setAPdfSignerError']); + } + $isZipped = (!isset($body['isZipped']) || $body['isZipped']) ? true : false; if ($isZipped) { @@ -343,7 +353,6 @@ class DocumentController return $response->withStatus(400)->withJson(['errors' => 'Document is not a pdf']); } - $libDir = CoreConfigModel::getLibrariesDirectory(); if (!empty($libDir) && is_file($libDir . 'SetaPDF-FormFiller-Full/library/SetaPDF/Autoload.php')) { require_once($libDir . 'SetaPDF-FormFiller-Full/library/SetaPDF/Autoload.php'); @@ -450,7 +459,6 @@ class DocumentController return $response->withStatus(500)->withJson(['errors' => $e->getMessage()]); } - $loadedXml = CoreConfigModel::getConfig(); $workflow = WorkflowModel::get([ 'select' => ['id', 'user_id', 'signature_mode'], 'where' => ['mode = ?', 'main_document_id = ?'], @@ -458,22 +466,10 @@ class DocumentController 'orderBy' => ['"order" asc'] ]); - $hasEidas = false; - foreach ($workflow as $step) { - if ($step['signature_mode'] == 'eidas') { - $hasEidas = true; - break; - } - } if ($loadedXml->docaposteSignature->enable == 'true' && $hasEidas) { - $libDir = CoreConfigModel::getLibrariesDirectory(); - if (!empty($libDir) && is_file($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php')) { - $result = DigitalSignatureController::createTransaction(['documentId' => $id, 'workflow' => $workflow, 'encodedDocument' => $encodedDocument['encodedDocument']]); - if (!empty($result['errors'])) { - return $response->withStatus(500)->withJson(['errors' => $result['errors']]); - } - } else { - return $response->withStatus(500)->withJson(['errors' => 'SetaPDF-Signer library is not installed', 'lang' => 'setAPdfSignerError']); + $result = DigitalSignatureController::createTransaction(['documentId' => $id, 'workflow' => $workflow, 'encodedDocument' => $encodedDocument['encodedDocument']]); + if (!empty($result['errors'])) { + return $response->withStatus(500)->withJson(['errors' => $result['errors']]); } } EmailController::sendNotificationToNextUserInWorkflow(['documentId' => $id, 'userId' => $GLOBALS['id']]); @@ -495,9 +491,13 @@ class DocumentController } $workflow = WorkflowModel::getCurrentStep(['select' => ['id', 'mode', 'user_id', 'signature_mode', 'digital_signature_id'], 'documentId' => $args['id']]); + $libDir = CoreConfigModel::getLibrariesDirectory(); + $loadedXml = CoreConfigModel::getConfig(); + if ($loadedXml->docaposteSignature->enable == 'true' && $workflow['signature_mode'] == 'eidas' && (empty($libDir) || !is_file($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php'))) { + return $response->withStatus(500)->withJson(['errors' => 'SetaPDF-Signer library is not installed', 'lang' => 'setAPdfSignerError']); + } $body = $request->getParsedBody(); - $loadedXml = CoreConfigModel::getConfig(); if (!empty($body['signatures'])) { foreach ($body['signatures'] as $signature) { foreach (['encodedImage', 'width', 'positionX', 'positionY', 'page', 'type'] as $value) { @@ -677,19 +677,17 @@ class DocumentController ]); } elseif (DocumentController::ACTIONS[$args['actionId']] == 'VAL' && $workflow['mode'] == 'sign') { $imageSignature = false; - - $adr = AdrModel::getDocumentsAdr([ - 'select' => ['path', 'filename'], - 'where' => ['main_document_id = ?', 'type = ?'], - 'data' => [$args['id'], 'ESIGN'] - ]); - $docserver = DocserverModel::getByType(['type' => 'ESIGN', 'select' => ['path']]); - $pathToDocument = $docserver['path'] . $adr[0]['path'] . $adr[0]['filename']; - $libDir = CoreConfigModel::getLibrariesDirectory(); - $tmpPath = CoreConfigModel::getTmpPath(); if (!empty($libDir) && is_file($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php')) { require_once($libDir . 'SetaPDF-Signer/library/SetaPDF/Autoload.php'); - + + $adr = AdrModel::getDocumentsAdr([ + 'select' => ['path', 'filename'], + 'where' => ['main_document_id = ?', 'type = ?'], + 'data' => [$args['id'], 'ESIGN'] + ]); + $docserver = DocserverModel::getByType(['type' => 'ESIGN', 'select' => ['path']]); + $pathToDocument = $docserver['path'] . $adr[0]['path'] . $adr[0]['filename']; + $tmpPath = CoreConfigModel::getTmpPath(); $signedDocumentPath = $tmpPath . $GLOBALS['id'] . '_' . rand() . '_signedDocument.pdf'; $writer = new \SetaPDF_Core_Writer_File($signedDocumentPath); $document = \SetaPDF_Core_Document::loadByFilename($pathToDocument, $writer); diff --git a/src/app/history/controllers/HistoryController.php b/src/app/history/controllers/HistoryController.php index d082b6a6212a28bc5fa30b73e7c6cae58efc5850..a3c25a52d0b691b14726bf2dca40a51bb973784e 100755 --- a/src/app/history/controllers/HistoryController.php +++ b/src/app/history/controllers/HistoryController.php @@ -181,8 +181,9 @@ class HistoryController } $workflow = WorkflowModel::getByDocumentId(['select' => ['user_id', 'process_date', 'note', 'status', 'signature_mode'], 'documentId' => $args['id'], 'orderBy' => ['"order"']]); - $hasEidas = false; - $workflowTerminated = true; + $hasEidas = false; + $workflowTerminated = true; + $canGetdocaposteProof = true; foreach ($workflow as $step) { if (!$hasEidas && $step['signature_mode'] == 'eidas') { $hasEidas = true; @@ -190,14 +191,19 @@ class HistoryController if (empty($step['status'])) { $workflowTerminated = false; } + if (in_array($step['status'], ['REF', 'STOP'])) { + $canGetdocaposteProof = false; + } } if (empty($workflow) || !$workflowTerminated) { return $response->withStatus(403)->withJson(['errors' => 'The document is still being processed']); } - $proofDocument = DigitalSignatureController::proof(['documentId' => $args['id']]); - if (!empty($proofDocument['errors'])) { - return $response->withStatus(403)->withJson(['errors' => $proofDocument['errors']]); + if ($canGetdocaposteProof) { + $proofDocument = DigitalSignatureController::proof(['documentId' => $args['id']]); + if (!empty($proofDocument['errors'])) { + return $response->withStatus(403)->withJson(['errors' => $proofDocument['errors']]); + } } $documentPathToZip = []; diff --git a/src/app/workflow/controllers/WorkflowController.php b/src/app/workflow/controllers/WorkflowController.php index 942cf7727abf5e1478a0116b3d1b38054bed5d84..c8aeb9d35f508d2bceeb4b866fc068a406c0c038 100755 --- a/src/app/workflow/controllers/WorkflowController.php +++ b/src/app/workflow/controllers/WorkflowController.php @@ -14,6 +14,7 @@ namespace Workflow\controllers; +use Document\controllers\DigitalSignatureController; use Document\controllers\DocumentController; use Document\models\DocumentModel; use Group\controllers\PrivilegeController; @@ -69,9 +70,9 @@ class WorkflowController } $workflows = WorkflowModel::get([ - 'select' => ['id'], - 'where' => ['main_document_id = ?', 'status is null'], - 'data' => [$args['id']] + 'select' => ['id', 'digital_signature_id'], + 'where' => ['main_document_id = ?', 'status is null'], + 'data' => [$args['id']] ]); if (empty($workflows)) { return $response->withStatus(400)->withJson(['errors' => 'Workflow is over or already suspended']); @@ -84,6 +85,13 @@ class WorkflowController 'data' => [$workflowsId] ]); + foreach ($workflows as $step) { + if (!empty($step['digital_signature_id'])) { + DigitalSignatureController::abort(['signatureId' => $step['digital_signature_id'], 'documentId' => $args['id']]); + break; + } + } + HistoryController::add([ 'code' => 'OK', 'objectType' => 'main_documents', diff --git a/src/frontend/app/search/search.component.ts b/src/frontend/app/search/search.component.ts index 9331047be54a71ae4f55e2ce0e3561d8e3c49fe7..2f6a067ca0d2cffb7da3dadc81c25e9661149629 100644 --- a/src/frontend/app/search/search.component.ts +++ b/src/frontend/app/search/search.component.ts @@ -356,19 +356,14 @@ export class SearchComponent implements OnInit { } downloadProof(item: any, mode: string) { - let format: any = null; const onlyProof = mode === 'onlyProof' ? '&onlyProof=true' : ''; return new Promise((resolve) => { - this.http.get(`../rest/documents/${item.id}/proof?mode=base64${onlyProof}`) + this.http.get(`../rest/documents/${item.id}/proof?mode=stream${onlyProof}`, {responseType: 'blob' as 'json' }) .pipe( - tap((data: any) => { - format = data.format; - }), - exhaustMap(() => this.http.get(`../rest/documents/${item.id}/proof?mode=stream${onlyProof}`, { responseType: 'blob' })), tap((data: any) => { const today = new Date(); - const filename = 'proof_' + item.id + '_' + this.datePipe.transform(today, 'dd-MM-y') + '.' + format; + const filename = 'proof_' + item.id + '_' + this.datePipe.transform(today, 'dd-MM-y') + '.' + data.type.replace('application/', ''); const downloadLink = document.createElement('a'); downloadLink.href = window.URL.createObjectURL(data); downloadLink.setAttribute('download', filename);