diff --git a/appinfo/routes/routesAccountController.php b/appinfo/routes/routesAccountController.php index 641f80566b..00d2849a4f 100644 --- a/appinfo/routes/routesAccountController.php +++ b/appinfo/routes/routesAccountController.php @@ -20,9 +20,9 @@ ['name' => 'account#accountFileListToApproval', 'url' => '/api/{apiVersion}/account/files/approval/list', 'verb' => 'GET', 'requirements' => $requirements], ['name' => 'account#createSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements', 'verb' => 'POST', 'requirements' => $requirements], ['name' => 'account#getSignatureElements', 'url' => '/api/{apiVersion}/account/signature/elements', 'verb' => 'GET', 'requirements' => $requirements], - ['name' => 'account#getSignatureElementPreview','url' => '/api/{apiVersion}/account/signature/elements/preview/{fileId}', 'verb' => 'GET', 'requirements' => $requirements], - ['name' => 'account#getSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements/{elementId}', 'verb' => 'GET', 'requirements' => $requirements], - ['name' => 'account#patchSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements/{elementId}', 'verb' => 'PATCH', 'requirements' => $requirements], - ['name' => 'account#deleteSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements/{elementId}', 'verb' => 'DELETE', 'requirements' => $requirements], + ['name' => 'account#getSignatureElementPreview','url' => '/api/{apiVersion}/account/signature/elements/preview/{nodeId}', 'verb' => 'GET', 'requirements' => $requirements], + ['name' => 'account#getSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements/{nodeId}', 'verb' => 'GET', 'requirements' => $requirements], + ['name' => 'account#patchSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements/{nodeId}', 'verb' => 'PATCH', 'requirements' => $requirements], + ['name' => 'account#deleteSignatureElement', 'url' => '/api/{apiVersion}/account/signature/elements/{nodeId}', 'verb' => 'DELETE', 'requirements' => $requirements], ], ]; diff --git a/img/application-pdf.png b/img/application-pdf.png deleted file mode 100644 index 2ee4aab352..0000000000 Binary files a/img/application-pdf.png and /dev/null differ diff --git a/img/frame4.png b/img/frame4.png deleted file mode 100644 index e495cbb94a..0000000000 Binary files a/img/frame4.png and /dev/null differ diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index 19fb87a5a8..98f9257517 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -324,10 +324,10 @@ public function getSignatureElements(): JSONResponse { #[NoAdminRequired] #[PublicPage] #[NoCSRFRequired] - public function getSignatureElementPreview(int $fileId) { + public function getSignatureElementPreview(int $nodeId) { try { $node = $this->accountService->getFileByNodeIdAndSessionId( - $fileId, + $nodeId, $this->sessionService->getSessionId() ); } catch (DoesNotExistException $th) { @@ -346,11 +346,11 @@ public function getSignatureElementPreview(int $fileId) { #[NoAdminRequired] #[NoCSRFRequired] - public function getSignatureElement(int $elementId): JSONResponse { + public function getSignatureElement(int $nodeId): JSONResponse { $userId = $this->userSession->getUser()->getUID(); try { return new JSONResponse( - $this->signerElementsService->getUserElementByElementId($userId, $elementId), + $this->signerElementsService->getUserElementByNodeId($userId, $nodeId), Http::STATUS_OK ); } catch (\Throwable $th) { @@ -365,9 +365,9 @@ public function getSignatureElement(int $elementId): JSONResponse { #[NoAdminRequired] #[NoCSRFRequired] - public function patchSignatureElement($elementId, string $type = '', array $file = []): JSONResponse { + public function patchSignatureElement($nodeId, string $type = '', array $file = []): JSONResponse { try { - $element['elementId'] = $elementId; + $element['nodeId'] = $nodeId; if ($type) { $element['type'] = $type; } @@ -394,10 +394,14 @@ public function patchSignatureElement($elementId, string $type = '', array $file #[NoAdminRequired] #[NoCSRFRequired] - public function deleteSignatureElement(int $elementId): JSONResponse { - $userId = $this->userSession->getUser()->getUID(); + #[PublicPage] + public function deleteSignatureElement(int $nodeId): JSONResponse { try { - $this->accountService->deleteSignatureElement($userId, $elementId); + $this->accountService->deleteSignatureElement( + user: $this->userSession->getUser(), + nodeId: $nodeId, + sessionId: $this->sessionService->getSessionId(), + ); } catch (\Throwable $th) { return new JSONResponse( [ diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index a8d4dbc1b4..e8b3af9ebc 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -100,6 +100,7 @@ public function index(): TemplateResponse { $this->initialState->provideInitialState('can_request_sign', false); } + $this->provideSignerSignatues(); $this->initialState->provideInitialState('file_info', $this->fileService->formatFile()); $this->initialState->provideInitialState('identify_methods', $this->identifyMethodService->getIdentifyMethodsSettings()); $this->initialState->provideInitialState('legal_information', $this->appConfig->getAppValue('legal_information')); @@ -173,8 +174,6 @@ public function sign(string $uuid): TemplateResponse { $this->initialState->provideInitialState('statusText', $file['statusText']); $this->initialState->provideInitialState('signers', $file['signers']); $this->provideSignerSignatues(); - $signatureMethods = $this->identifyMethodService->getSignMethodsOfIdentifiedFactors($this->getSignRequestEntity()->getId()); - $this->initialState->provideInitialState('signature_methods', $signatureMethods); $this->initialState->provideInitialState('token_length', TokenService::TOKEN_LENGTH); $this->initialState->provideInitialState('description', $this->getSignRequestEntity()->getDescription() ?? ''); $this->initialState->provideInitialState('pdf', diff --git a/lib/Db/FileMapper.php b/lib/Db/FileMapper.php index 20a740a01c..183b751827 100644 --- a/lib/Db/FileMapper.php +++ b/lib/Db/FileMapper.php @@ -118,15 +118,15 @@ public function getBySignerUuid(?string $uuid = null): File { } /** - * Return LibreSign file by fileId + * Return LibreSign file by nodeId */ - public function getByFileId(?int $fileId = null): File { - $exists = array_filter($this->file, fn ($f) => $f->getNodeId() === $fileId || $f->getSignedNodeId() === $fileId); + public function getByFileId(?int $nodeId = null): File { + $exists = array_filter($this->file, fn ($f) => $f->getNodeId() === $nodeId || $f->getSignedNodeId() === $nodeId); if (!empty($exists)) { return current($exists); } foreach ($this->file as $file) { - if ($file->getNodeId() === $fileId) { + if ($file->getNodeId() === $nodeId) { return $file; } } @@ -136,8 +136,8 @@ public function getByFileId(?int $fileId = null): File { ->from($this->getTableName()) ->where( $qb->expr()->orX( - $qb->expr()->eq('node_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)), - $qb->expr()->eq('signed_node_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)) + $qb->expr()->eq('node_id', $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT)), + $qb->expr()->eq('signed_node_id', $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT)) ) ); diff --git a/lib/Db/SignRequestMapper.php b/lib/Db/SignRequestMapper.php index 0f8fa5492a..6654426188 100644 --- a/lib/Db/SignRequestMapper.php +++ b/lib/Db/SignRequestMapper.php @@ -361,16 +361,10 @@ public function getFilesAssociatedFilesWithMeFormatted( $currentPageResults = $pagination->getCurrentPageResults(); $data = []; - $fileIds = []; - foreach ($currentPageResults as $row) { - $fileIds[] = $row['id']; $data[] = $this->formatListRow($row); } - $signers = $this->getByMultipleFileId($fileIds); - $identifyMethods = $this->getIdentifyMethodsFromSigners($signers); - $visibleElements = $this->getVisibleElementsFromSigners($signers); - $return['data'] = $this->associateAllAndFormat($user, $data, $signers, $identifyMethods, $visibleElements); + $return['data'] = $data; $return['pagination'] = $pagination; return $return; } @@ -379,7 +373,7 @@ public function getFilesAssociatedFilesWithMeFormatted( * @param array $signRequests * @return FileElement[][] */ - private function getVisibleElementsFromSigners(array $signRequests): array { + public function getVisibleElementsFromSigners(array $signRequests): array { $signRequestIds = array_map(function (SignRequest $signRequest): int { return $signRequest->getId(); }, $signRequests); @@ -408,7 +402,7 @@ private function getVisibleElementsFromSigners(array $signRequests): array { * @param array $signRequests * @return array> */ - private function getIdentifyMethodsFromSigners(array $signRequests): array { + public function getIdentifyMethodsFromSigners(array $signRequests): array { $signRequestIds = array_map(function (SignRequest $signRequest): int { return $signRequest->getId(); }, $signRequests); @@ -531,113 +525,6 @@ private function getFilesAssociatedFilesWithMeStmt(string $userId, ?string $emai return $pagination; } - /** - * @param IUser $userId - * @param array $files - * @param array $signers - * @param array> $identifyMethods - * @param SignRequest[][] - */ - private function associateAllAndFormat(IUser $user, array $files, array $signers, array $identifyMethods, array $visibleElements): array { - foreach ($files as $key => $file) { - $totalSigned = 0; - foreach ($signers as $signerKey => $signer) { - if ($signer->getFileId() === $file['id']) { - /** @var array */ - $identifyMethodsOfSigner = $identifyMethods[$signer->getId()] ?? []; - $data = [ - 'email' => array_reduce($identifyMethodsOfSigner, function (string $carry, IdentifyMethod $identifyMethod): string { - if ($identifyMethod->getIdentifierKey() === IdentifyMethodService::IDENTIFY_EMAIL) { - return $identifyMethod->getIdentifierValue(); - } - return $carry; - }, ''), - 'description' => $signer->getDescription(), - 'displayName' => - array_reduce($identifyMethodsOfSigner, function (string $carry, IdentifyMethod $identifyMethod): string { - if (!$carry && $identifyMethod->getMandatory()) { - return $identifyMethod->getIdentifierValue(); - } - return $carry; - }, $signer->getDisplayName()), - 'request_sign_date' => (new \DateTime()) - ->setTimestamp($signer->getCreatedAt()) - ->format('Y-m-d H:i:s'), - 'signed' => null, - 'signRequestId' => $signer->getId(), - 'me' => array_reduce($identifyMethodsOfSigner, function (bool $carry, IdentifyMethod $identifyMethod) use ($user): bool { - if ($identifyMethod->getIdentifierKey() === IdentifyMethodService::IDENTIFY_ACCOUNT) { - if ($user->getUID() === $identifyMethod->getIdentifierValue()) { - return true; - } - } elseif ($identifyMethod->getIdentifierKey() === IdentifyMethodService::IDENTIFY_EMAIL) { - if (!$user->getEMailAddress()) { - return false; - } - if ($user->getEMailAddress() === $identifyMethod->getIdentifierValue()) { - return true; - } - } - return $carry; - }, false), - 'visibleElements' => array_map(function (FileElement $visibleElement) use ($file) { - $element = [ - 'elementId' => $visibleElement->getId(), - 'signRequestId' => $visibleElement->getSignRequestId(), - 'type' => $visibleElement->getType(), - 'coordinates' => [ - 'page' => $visibleElement->getPage(), - 'urx' => $visibleElement->getUrx(), - 'ury' => $visibleElement->getUry(), - 'llx' => $visibleElement->getLlx(), - 'lly' => $visibleElement->getLly() - ] - ]; - $metadata = json_decode($file['metadata'], true); - $dimension = $metadata['d'][$element['coordinates']['page'] - 1]; - - $element['coordinates']['left'] = $element['coordinates']['llx']; - $element['coordinates']['height'] = abs($element['coordinates']['ury'] - $element['coordinates']['lly']); - $element['coordinates']['top'] = $dimension['h'] - $element['coordinates']['ury']; - $element['coordinates']['width'] = $element['coordinates']['urx'] - $element['coordinates']['llx']; - - return $element; - }, $visibleElements[$signer->getId()] ?? []), - 'identifyMethods' => array_map(function (IdentifyMethod $identifyMethod) use ($signer): array { - return [ - 'method' => $identifyMethod->getIdentifierKey(), - 'value' => $identifyMethod->getIdentifierValue(), - 'mandatory' => $identifyMethod->getMandatory(), - ]; - }, array_values($identifyMethodsOfSigner)), - ]; - - if ($data['me']) { - $data['sign_uuid'] = $signer->getUuid(); - $files[$key]['url'] = $this->urlGenerator->linkToRoute('libresign.page.getPdfFile', ['uuid' => $signer->getuuid()]); - } - - if ($signer->getSigned()) { - $data['signed'] = $this->dateTimeFormatter->formatDateTime($signer->getSigned()); - $totalSigned++; - } - ksort($data); - $files[$key]['signers'][] = $data; - unset($signers[$signerKey]); - } - } - if (empty($files[$key]['signers'])) { - $files[$key]['signers'] = []; - $files[$key]['statusText'] = $this->l10n->t('no signers'); - } else { - $files[$key]['statusText'] = $this->fileMapper->getTextOfStatus((int) $files[$key]['status']); - } - unset($files[$key]['id']); - ksort($files[$key]); - } - return $files; - } - private function formatListRow(array $row): array { $row['id'] = (int) $row['id']; $row['status'] = (int) $row['status']; diff --git a/lib/Helper/ValidateHelper.php b/lib/Helper/ValidateHelper.php index 200ef16303..95ddd1fa0a 100644 --- a/lib/Helper/ValidateHelper.php +++ b/lib/Helper/ValidateHelper.php @@ -295,15 +295,15 @@ public function validateVisibleElementsRelation(array $list, SignRequest $signRe if (!array_key_exists('documentElementId', $elements)) { throw new LibresignException($this->l10n->t('Field %s not found', ['documentElementId'])); } - if (!array_key_exists('profileFileId', $elements)) { - throw new LibresignException($this->l10n->t('Field %s not found', ['profileFileId'])); + if (!array_key_exists('profileNodeId', $elements)) { + throw new LibresignException($this->l10n->t('Field %s not found', ['profileNodeId'])); } $this->validateSignerIsOwnerOfPdfVisibleElement($elements['documentElementId'], $signRequest); if ($user instanceof IUser) { try { - $this->userElementMapper->findOne(['file_id' => $elements['profileFileId'], 'user_id' => $user->getUID()]); + $this->userElementMapper->findOne(['file_id' => $elements['profileNodeId'], 'user_id' => $user->getUID()]); } catch (\Throwable $th) { - throw new LibresignException($this->l10n->t('Field %s does not belong to user', $elements['profileFileId'])); + throw new LibresignException($this->l10n->t('Field %s does not belong to user', $elements['profileNodeId'])); } } } diff --git a/lib/Middleware/GlobalInjectionMiddleware.php b/lib/Middleware/GlobalInjectionMiddleware.php index 66e9db14e7..dae22bb77d 100644 --- a/lib/Middleware/GlobalInjectionMiddleware.php +++ b/lib/Middleware/GlobalInjectionMiddleware.php @@ -34,7 +34,7 @@ class GlobalInjectionMiddleware extends Middleware { public function afterController(Controller $controller, string $methodName, Response $response) { if ($controller instanceof ViewController) { $policy = new ContentSecurityPolicy(); - $policy->allowEvalScript(true); + $policy->addAllowedFrameDomain("'self'"); $response->setContentSecurityPolicy($policy); } return $response; diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php index b6ccd9c6dd..2e9c2d0ae3 100644 --- a/lib/Service/AccountService.php +++ b/lib/Service/AccountService.php @@ -47,6 +47,7 @@ use OCP\Files\Config\IMountProviderCollection; use OCP\Files\Config\IUserMountCache; use OCP\Files\File; +use OCP\Files\Folder; use OCP\Files\IMimeTypeDetector; use OCP\Files\IRootFolder; use OCP\Http\Client\IClientService; @@ -405,9 +406,12 @@ private function saveFileOfVisibleElementUsingSession(array $data, string $sessi $rootSignatureFolder = $this->folderService->getFolder(); $folderName = $sessionId; if ($rootSignatureFolder->nodeExists($folderName)) { - throw new \Exception($this->l10n->t('File already exists')); + /** @var Folder $folderToFile */ + $folderToFile = $rootSignatureFolder->get($folderName); + } else { + /** @var Folder $folderToFile */ + $folderToFile = $rootSignatureFolder->newFolder($folderName); } - $folderToFile = $rootSignatureFolder->newFolder($folderName); $filename = implode( '_', [ @@ -461,9 +465,24 @@ private function getFileRaw(array $data) { return $content; } - public function deleteSignatureElement(string $userId, int $elementId): void { - $element = $this->userElementMapper->findOne(['id' => $elementId, 'user_id' => $userId]); - $this->userElementMapper->delete($element); + public function deleteSignatureElement(?IUser $user, string $sessionId, int $nodeId): void { + if ($user instanceof IUser) { + $element = $this->userElementMapper->findOne([ + 'file_id' => $nodeId, + 'user_id' => $user->getUID(), + ]); + $this->userElementMapper->delete($element); + $file = $this->root->getById($element->getFileId()); + if ($file) { + current($file)->delete(); + } + } else { + $rootSignatureFolder = $this->folderService->getFolder(); + $folderName = $sessionId; + if ($rootSignatureFolder->nodeExists($folderName)) { + $rootSignatureFolder->delete($folderName); + } + } } /** diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index c3ba5d63a5..c92db651c1 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -25,8 +25,10 @@ namespace OCA\Libresign\Service; use OCA\Libresign\Db\File; +use OCA\Libresign\Db\FileElement; use OCA\Libresign\Db\FileElementMapper; use OCA\Libresign\Db\FileMapper; +use OCA\Libresign\Db\IdentifyMethod; use OCA\Libresign\Db\SignRequest; use OCA\Libresign\Db\SignRequestMapper; use OCA\Libresign\Exception\LibresignException; @@ -236,6 +238,9 @@ private function getSigners(): array { } } } + if ($signatureToShow['me'] && !is_null($this->signRequest)) { + $signatureToShow['signatureMethods'] = $this->identifyMethodService->getSignMethodsOfIdentifiedFactors($this->signRequest->getId()); + } $signatureToShow['identifyMethods'] = array_reduce($signatureToShow['identifyMethods'], function ($carry, $list) { foreach ($list as $identifyMethod) { $carry[] = [ @@ -452,19 +457,153 @@ public function listAssociatedFilesOfSignFlow($page = null, $length = null, arra $page = $page ?? 1; $length = $length ?? (int) $this->appConfig->getAppValue('length_of_page', '100'); - $data = $this->signRequestMapper->getFilesAssociatedFilesWithMeFormatted( + $return = $this->signRequestMapper->getFilesAssociatedFilesWithMeFormatted( $this->me, $page, $length, $filter, ); - $data['pagination']->setRootPath('/file/list'); + + $signers = $this->signRequestMapper->getByMultipleFileId(array_column($return['data'], 'id')); + $identifyMethods = $this->signRequestMapper->getIdentifyMethodsFromSigners($signers); + $visibleElements = $this->signRequestMapper->getVisibleElementsFromSigners($signers); + $return['data'] = $this->associateAllAndFormat($this->me, $return['data'], $signers, $identifyMethods, $visibleElements); + + $return['pagination']->setRootPath('/file/list'); return [ - 'data' => $data['data'], - 'pagination' => $data['pagination']->getPagination($page, $length) + 'data' => $return['data'], + 'pagination' => $return['pagination']->getPagination($page, $length) ]; } + /** + * @param IUser $userId + * @param array $files + * @param array $signers + * @param array> $identifyMethods + * @param SignRequest[][] + */ + private function associateAllAndFormat(IUser $user, array $files, array $signers, array $identifyMethods, array $visibleElements): array { + foreach ($files as $key => $file) { + $totalSigned = 0; + foreach ($signers as $signerKey => $signer) { + if ($signer->getFileId() === $file['id']) { + /** @var array */ + $identifyMethodsOfSigner = $identifyMethods[$signer->getId()] ?? []; + $data = [ + 'email' => array_reduce($identifyMethodsOfSigner, function (string $carry, IdentifyMethod $identifyMethod): string { + if ($identifyMethod->getIdentifierKey() === IdentifyMethodService::IDENTIFY_EMAIL) { + return $identifyMethod->getIdentifierValue(); + } + return $carry; + }, ''), + 'description' => $signer->getDescription(), + 'displayName' => + array_reduce($identifyMethodsOfSigner, function (string $carry, IdentifyMethod $identifyMethod): string { + if (!$carry && $identifyMethod->getMandatory()) { + return $identifyMethod->getIdentifierValue(); + } + return $carry; + }, $signer->getDisplayName()), + 'request_sign_date' => (new \DateTime()) + ->setTimestamp($signer->getCreatedAt()) + ->format('Y-m-d H:i:s'), + 'signed' => null, + 'signRequestId' => $signer->getId(), + 'me' => array_reduce($identifyMethodsOfSigner, function (bool $carry, IdentifyMethod $identifyMethod) use ($user): bool { + if ($identifyMethod->getIdentifierKey() === IdentifyMethodService::IDENTIFY_ACCOUNT) { + if ($user->getUID() === $identifyMethod->getIdentifierValue()) { + return true; + } + } elseif ($identifyMethod->getIdentifierKey() === IdentifyMethodService::IDENTIFY_EMAIL) { + if (!$user->getEMailAddress()) { + return false; + } + if ($user->getEMailAddress() === $identifyMethod->getIdentifierValue()) { + return true; + } + } + return $carry; + }, false), + 'visibleElements' => array_map(function (FileElement $visibleElement) use ($file) { + $element = [ + 'elementId' => $visibleElement->getId(), + 'signRequestId' => $visibleElement->getSignRequestId(), + 'type' => $visibleElement->getType(), + 'coordinates' => [ + 'page' => $visibleElement->getPage(), + 'urx' => $visibleElement->getUrx(), + 'ury' => $visibleElement->getUry(), + 'llx' => $visibleElement->getLlx(), + 'lly' => $visibleElement->getLly() + ] + ]; + $metadata = json_decode($file['metadata'], true); + $dimension = $metadata['d'][$element['coordinates']['page'] - 1]; + + $element['coordinates']['left'] = $element['coordinates']['llx']; + $element['coordinates']['height'] = abs($element['coordinates']['ury'] - $element['coordinates']['lly']); + $element['coordinates']['top'] = $dimension['h'] - $element['coordinates']['ury']; + $element['coordinates']['width'] = $element['coordinates']['urx'] - $element['coordinates']['llx']; + + return $element; + }, $visibleElements[$signer->getId()] ?? []), + 'identifyMethods' => array_map(function (IdentifyMethod $identifyMethod) use ($signer): array { + return [ + 'method' => $identifyMethod->getIdentifierKey(), + 'value' => $identifyMethod->getIdentifierValue(), + 'mandatory' => $identifyMethod->getMandatory(), + ]; + }, array_values($identifyMethodsOfSigner)), + ]; + + if ($data['me']) { + $temp = array_map(function (IdentifyMethod $identifyMethodEntity) use ($signer): array { + $this->identifyMethodService->setCurrentIdentifyMethod($identifyMethodEntity); + $identifyMethod = $this->identifyMethodService->getInstanceOfIdentifyMethod( + $identifyMethodEntity->getIdentifierKey(), + $identifyMethodEntity->getIdentifierValue(), + ); + $signatureMethods = $identifyMethod->getSignatureMethods(); + $return = []; + foreach ($signatureMethods as $signatureMethod) { + if (!$signatureMethod->isEnabled()) { + continue; + } + $signatureMethod->setEntity($identifyMethod->getEntity()); + $return[$signatureMethod->getName()] = $signatureMethod->toArray(); + } + return $return; + }, array_values($identifyMethodsOfSigner)); + $data['signatureMethods'] = []; + foreach ($temp as $methods) { + $data['signatureMethods'] = array_merge($data['signatureMethods'], $methods); + } + $data['sign_uuid'] = $signer->getUuid(); + $files[$key]['url'] = $this->urlGenerator->linkToRoute('libresign.page.getPdfFile', ['uuid' => $signer->getuuid()]); + } + + if ($signer->getSigned()) { + $data['signed'] = $this->dateTimeFormatter->formatDateTime($signer->getSigned()); + $totalSigned++; + } + ksort($data); + $files[$key]['signers'][] = $data; + unset($signers[$signerKey]); + } + } + if (empty($files[$key]['signers'])) { + $files[$key]['signers'] = []; + $files[$key]['statusText'] = $this->l10n->t('no signers'); + } else { + $files[$key]['statusText'] = $this->fileMapper->getTextOfStatus((int) $files[$key]['status']); + } + unset($files[$key]['id']); + ksort($files[$key]); + } + return $files; + } + public function getMyLibresignFile(int $nodeId): File { return $this->signRequestMapper->getMyLibresignFile( userId: $this->me->getUID(), diff --git a/lib/Service/SignFileService.php b/lib/Service/SignFileService.php index a12b27d5a6..37408d54b6 100644 --- a/lib/Service/SignFileService.php +++ b/lib/Service/SignFileService.php @@ -232,8 +232,8 @@ public function setVisibleElements(array $list): self { }); if ($element) { $c = current($element); - if (!empty($c['profileFileId'])) { - $nodeId = $c['profileFileId']; + if (!empty($c['profileNodeId'])) { + $nodeId = $c['profileNodeId']; } else { throw new LibresignException($this->l10n->t('Invalid data to sign file'), 1); } @@ -259,7 +259,7 @@ public function setVisibleElements(array $list): self { if (!$node) { throw new \Exception('empty'); } - $node = $node[0]; + $node = current($node); } catch (\Throwable $th) { throw new LibresignException($this->l10n->t('You need to define a visible signature or initials to sign this document.')); } @@ -400,10 +400,10 @@ public function getFileToSing(FileEntity $libresignFile): \OCP\Files\Node { return $originalFile; } - public function getLibresignFile(?int $fileId, ?string $signRequestUuid = null): FileEntity { + public function getLibresignFile(?int $nodeId, ?string $signRequestUuid = null): FileEntity { try { - if ($fileId) { - $libresignFile = $this->fileMapper->getByFileId($fileId); + if ($nodeId) { + $libresignFile = $this->fileMapper->getByFileId($nodeId); } elseif ($signRequestUuid) { $signRequest = $this->signRequestMapper->getByUuid($signRequestUuid); $libresignFile = $this->fileMapper->getById($signRequest->getFileId()); diff --git a/lib/Service/SignerElementsService.php b/lib/Service/SignerElementsService.php index 13ad37eda4..cb3acf70ff 100644 --- a/lib/Service/SignerElementsService.php +++ b/lib/Service/SignerElementsService.php @@ -42,13 +42,8 @@ public function __construct( ) { } - /** - * @return ((int|string)[]|\DateTime|int|string)[] - * - * @psalm-return array{id?: int, type?: string, file?: array{url: string, fileId: int}, uid?: string, starred?: 0|1, createdAt?: \DateTime} - */ - public function getUserElementByElementId(string $userId, $elementId): array { - $element = $this->userElementMapper->findOne(['id' => $elementId, 'user_id' => $userId]); + public function getUserElementByNodeId(string $userId, $nodeId): array { + $element = $this->userElementMapper->findOne(['file_id' => $nodeId, 'user_id' => $userId]); $exists = $this->signatureFileExists($element); if (!$exists) { return []; @@ -58,7 +53,7 @@ public function getUserElementByElementId(string $userId, $elementId): array { 'type' => $element->getType(), 'file' => [ 'url' => $this->urlGenerator->linkToRoute('core.Preview.getPreviewByFileId', ['fileId' => $element->getFileId(), 'x' => self::ELEMENT_SIGN_WIDTH, 'y' => self::ELEMENT_SIGN_HEIGHT]), - 'fileId' => $element->getFileId() + 'nodeId' => $element->getFileId() ], 'uid' => $element->getUserId(), 'starred' => $element->getStarred() ? 1 : 0, @@ -79,7 +74,7 @@ public function getUserElements(string $userId): array { 'type' => $element->getType(), 'file' => [ 'url' => $this->urlGenerator->linkToRoute('core.Preview.getPreviewByFileId', ['fileId' => $element->getFileId(), 'x' => self::ELEMENT_SIGN_WIDTH, 'y' => self::ELEMENT_SIGN_HEIGHT]), - 'fileId' => $element->getFileId() + 'nodeId' => $element->getFileId() ], 'starred' => $element->getStarred() ? 1 : 0, 'createdAt' => $element->getCreatedAt()->format('Y-m-d H:i:s'), @@ -120,9 +115,9 @@ public function getElementsFromSessionAsArray(): array { 'file' => [ 'url' => $this->urlGenerator->linkToRoute('ocs.libresign.account.getSignatureElementPreview', [ 'apiVersion' => 'v1', - 'fileId' => $fileElement->getId(), + 'nodeId' => $fileElement->getId(), ]), - 'fileId' => $fileElement->getId(), + 'nodeId' => $fileElement->getId(), ], 'starred' => 0, 'createdAt' => (new \DateTime())->setTimestamp((int) $timestamp)->format('Y-m-d H:i:s'), diff --git a/package-lock.json b/package-lock.json index 204be8893e..b4981ac1b8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "blueimp-md5": "^2.19.0", "crypto-js": "^4.2.0", "dompurify": "^3.1.0", + "js-confetti": "^0.12.0", "linkify-string": "^4.1.3", "lodash-es": "^4.17.21", "pinia": "^2.1.7", @@ -12847,6 +12848,11 @@ "resolved": "https://registry.npmjs.org/jpeg-exif/-/jpeg-exif-1.1.4.tgz", "integrity": "sha512-a+bKEcCjtuW5WTdgeXFzswSrdqi0jk4XlEtZlx5A94wCoBpFjfFTbo/Tra5SpNCl/YFZPvcV1dJc+TAYeg6ROQ==" }, + "node_modules/js-confetti": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/js-confetti/-/js-confetti-0.12.0.tgz", + "integrity": "sha512-1R0Akxn3Zn82pMqW65N1V2NwKkZJ75bvBN/VAb36Ya0YHwbaSiAJZVRr/19HBxH/O8x2x01UFAbYI18VqlDN6g==" + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/package.json b/package.json index 4aae205d46..d0b624ebff 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ "blueimp-md5": "^2.19.0", "crypto-js": "^4.2.0", "dompurify": "^3.1.0", + "js-confetti": "^0.12.0", "linkify-string": "^4.1.3", "lodash-es": "^4.17.21", "pinia": "^2.1.7", diff --git a/src/App.vue b/src/App.vue index fdb755f021..c691d11266 100644 --- a/src/App.vue +++ b/src/App.vue @@ -22,7 +22,7 @@ --> diff --git a/src/Components/RightSidebar/RequestSignatureTab.vue b/src/Components/RightSidebar/RequestSignatureTab.vue index c444d71e3c..630f15892d 100644 --- a/src/Components/RightSidebar/RequestSignatureTab.vue +++ b/src/Components/RightSidebar/RequestSignatureTab.vue @@ -4,7 +4,7 @@
+ id="request-signature-tab"> @@ -79,6 +79,8 @@ import VisibleElements from '../Request/VisibleElements.vue' import { loadState } from '@nextcloud/initial-state' import { useFilesStore } from '../../store/files.js' import { useSignStore } from '../../store/sign.js' +import { useSidebarStore } from '../../store/sidebar.js' +import router from '../../router/router.js' export default { name: 'RequestSignatureTab', @@ -92,10 +94,17 @@ export default { IdentifySigner, VisibleElements, }, + props: { + useModal: { + type: Boolean, + default: false, + }, + }, setup() { const filesStore = useFilesStore() const signStore = useSignStore() - return { filesStore, signStore } + const sidebarStore = useSidebarStore() + return { filesStore, signStore, sidebarStore } }, data() { return { @@ -161,7 +170,8 @@ export default { this.showSignModal = false }, validationFile() { - this.$router.push({ name: 'validationFile', params: { uuid: this.filesStore.getFile().uuid } }) + this.$router.push({ name: 'ValidationFile', params: { uuid: this.filesStore.getFile().uuid } }) + this.sidebarStore.hideSidebar() }, addSigner() { this.signerToEdit = {} @@ -196,10 +206,14 @@ export default { } return accumulator }, '') - this.signStore.document = this.filesStore.getFile() - const route = this.$router.resolve({ name: 'SignPDF', params: { uuid } }) - this.modalSrc = route.href - this.showSignModal = true + if (this.useModal) { + const route = router.resolve({ name: 'SignPDFExternal', params: { uuid } }) + this.modalSrc = route.href + this.showSignModal = true + return + } + this.signStore.setDocumentToSign(this.filesStore.getFile()) + this.$router.push({ name: 'SignPDF', params: { uuid } }) }, async save() { this.hasLoading = true diff --git a/src/Components/RightSidebar/RightSidebar.vue b/src/Components/RightSidebar/RightSidebar.vue index 4165289dee..800afb3e72 100644 --- a/src/Components/RightSidebar/RightSidebar.vue +++ b/src/Components/RightSidebar/RightSidebar.vue @@ -1,11 +1,18 @@