diff --git a/lib/Controller/AccountController.php b/lib/Controller/AccountController.php index a23536a82c..768c03f617 100644 --- a/lib/Controller/AccountController.php +++ b/lib/Controller/AccountController.php @@ -40,7 +40,6 @@ use Psr\Log\LoggerInterface; /** - * @psalm-import-type LibresignAccountFile from ResponseDefinitions * @psalm-import-type LibresignCertificatePfxData from ResponseDefinitions * @psalm-import-type LibresignFile from ResponseDefinitions * @psalm-import-type LibresignPagination from ResponseDefinitions @@ -187,73 +186,6 @@ public function signatureGenerate( } } - /** - * Add files to account profile - * - * @param LibresignAccountFile[] $files The list of files to add to profile - * @return DataResponse, array{}>|DataResponse - * - * 200: Certificate saved with success - * 401: No file provided or other problem with provided file - */ - #[NoAdminRequired] - #[NoCSRFRequired] - #[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/account/files', requirements: ['apiVersion' => '(v1)'])] - public function addFiles(array $files): DataResponse { - try { - $this->accountService->addFilesToAccount($files, $this->userSession->getUser()); - return new DataResponse([], Http::STATUS_OK); - } catch (\Exception $exception) { - $exceptionData = json_decode($exception->getMessage()); - if (isset($exceptionData->file)) { - $message = [ - 'file' => $exceptionData->file, - 'type' => $exceptionData->type, - 'message' => $exceptionData->message - ]; - } else { - $message = [ - 'file' => null, - 'type' => null, - 'message' => $exception->getMessage() - ]; - } - return new DataResponse( - $message, - Http::STATUS_UNAUTHORIZED - ); - } - } - - /** - * Delete file from account - * - * @param int $nodeId the nodeId of file to be delete - * - * @return DataResponse, array{}>|DataResponse - * - * 200: File deleted with success - * 401: Failure to delete file from account - */ - #[NoAdminRequired] - #[NoCSRFRequired] - #[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/account/files', requirements: ['apiVersion' => '(v1)'])] - public function deleteFile(int $nodeId): DataResponse { - try { - $this->accountService->deleteFileFromAccount($nodeId, $this->userSession->getUser()); - return new DataResponse([], Http::STATUS_OK); - } catch (\Exception $exception) { - return new DataResponse( - [ - 'messages' => [ - $exception->getMessage(), - ], - ], - Http::STATUS_UNAUTHORIZED, - ); - } - } - /** * Who am I * @@ -293,64 +225,6 @@ public function me(): DataResponse { ); } - /** - * List account files of authenticated account - * - * @param array{approved?: 'yes'}|null $filter Filter params - * @param int|null $page the number of page to return - * @param int|null $length Total of elements to return - * @return DataResponse|DataResponse - * - * 200: Certificate saved with success - * 404: No file provided or other problem with provided file - */ - #[NoAdminRequired] - #[NoCSRFRequired] - #[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/account/files', requirements: ['apiVersion' => '(v1)'])] - public function accountFileListToOwner(array $filter = [], ?int $page = null, ?int $length = null): DataResponse { - try { - $filter['userId'] = $this->userSession->getUser()->getUID(); - $return = $this->accountFileService->accountFileList($filter, $page, $length); - return new DataResponse($return, Http::STATUS_OK); - } catch (\Throwable $th) { - return new DataResponse( - [ - 'message' => $th->getMessage() - ], - Http::STATUS_NOT_FOUND - ); - } - } - - /** - * List account files that need to be approved - * - * @param array{approved?: 'yes'}|null $filter Filter params - * @param int|null $page the number of page to return - * @param int|null $length Total of elements to return - * @return DataResponse|DataResponse - * - * 200: OK - * 404: Account not found - */ - #[NoAdminRequired] - #[NoCSRFRequired] - #[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/account/files/approval/list', requirements: ['apiVersion' => '(v1)'])] - public function accountFileListToApproval(array $filter = [], ?int $page = null, ?int $length = null): DataResponse { - try { - $this->validateHelper->userCanApproveValidationDocuments($this->userSession->getUser()); - $return = $this->accountFileService->accountFileList($filter, $page, $length); - return new DataResponse($return, Http::STATUS_OK); - } catch (\Throwable $th) { - return new DataResponse( - [ - 'message' => $th->getMessage() - ], - Http::STATUS_NOT_FOUND - ); - } - } - /** * Update the account phone number * diff --git a/lib/Controller/IdDocsController.php b/lib/Controller/IdDocsController.php new file mode 100644 index 0000000000..b2c07feeeb --- /dev/null +++ b/lib/Controller/IdDocsController.php @@ -0,0 +1,191 @@ +, array{}>|DataResponse + * + * 200: Certificate saved with success + * 401: No file provided or other problem with provided file + */ + #[PublicPage] + #[AnonRateLimit(limit: 30, period: 60)] + #[NoAdminRequired] + #[NoCSRFRequired] + #[RequireSignRequestUuid(skipIfAuthenticated: true)] + #[ApiRoute(verb: 'POST', url: '/api/{apiVersion}/id-docs', requirements: ['apiVersion' => '(v1)'])] + public function addFiles(array $files): DataResponse { + try { + if ($user = $this->userSession->getUser()) { + $this->idDocsService->addFilesToAccount($files, $user); + } elseif ($signRequest = $this->getSignRequestEntity()) { + $this->idDocsService->addFilesToDocumentFolder($files, $signRequest); + } else { + throw new Exception('Invalid data'); + } + return new DataResponse([], Http::STATUS_OK); + } catch (\Exception $exception) { + $exceptionData = json_decode($exception->getMessage()); + if (isset($exceptionData->file)) { + $message = [ + 'file' => $exceptionData->file, + 'type' => $exceptionData->type, + 'message' => $exceptionData->message + ]; + } else { + $message = [ + 'file' => null, + 'type' => null, + 'message' => $exception->getMessage() + ]; + } + return new DataResponse( + $message, + Http::STATUS_UNAUTHORIZED + ); + } + } + + /** + * Delete file from account + * + * @param int $nodeId the nodeId of file to be delete + * + * @return DataResponse, array{}>|DataResponse + * + * 200: File deleted with success + * 401: Failure to delete file from account + */ + #[NoAdminRequired] + #[NoCSRFRequired] + #[ApiRoute(verb: 'DELETE', url: '/api/{apiVersion}/id-docs', requirements: ['apiVersion' => '(v1)'])] + public function deleteFile(int $nodeId): DataResponse { + try { + $this->idDocsService->deleteFileFromAccount($nodeId, $this->userSession->getUser()); + return new DataResponse([], Http::STATUS_OK); + } catch (\Exception $exception) { + return new DataResponse( + [ + 'messages' => [ + $exception->getMessage(), + ], + ], + Http::STATUS_UNAUTHORIZED, + ); + } + } + + /** + * List files of unauthenticated account + * + * @param array{approved?: 'yes'}|null $filter Filter params + * @param int|null $page the number of page to return + * @param int|null $length Total of elements to return + * @return DataResponse|DataResponse + * + * 200: Certificate saved with success + * 404: No file provided or other problem with provided file + */ + #[PublicPage] + #[AnonRateLimit(limit: 30, period: 60)] + #[NoCSRFRequired] + #[RequireSignRequestUuid(skipIfAuthenticated: true)] + #[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/id-docs', requirements: ['apiVersion' => '(v1)'])] + public function listOfUnauthenticatedSigner(array $filter = [], ?int $page = null, ?int $length = null): DataResponse { + try { + if ($user = $this->userSession->getUser()) { + $filter['userId'] = $user->getUID(); + } elseif ($signRequest = $this->getSignRequestEntity()) { + $filter['singRequestId'] = $signRequest->getId(); + } else { + throw new Exception('Invalid data'); + } + + $return = $this->idDocsService->list($filter, $page, $length); + return new DataResponse($return, Http::STATUS_OK); + } catch (\Throwable $th) { + return new DataResponse( + [ + 'message' => $th->getMessage() + ], + Http::STATUS_NOT_FOUND + ); + } + } + + /** + * List files that need to be approved + * + * @param array{approved?: 'yes'}|null $filter Filter params + * @param int|null $page the number of page to return + * @param int|null $length Total of elements to return + * @return DataResponse|DataResponse + * + * 200: OK + * 404: Account not found + */ + #[NoAdminRequired] + #[NoCSRFRequired] + #[ApiRoute(verb: 'GET', url: '/api/{apiVersion}/id-docs/approval/list', requirements: ['apiVersion' => '(v1)'])] + public function listToApproval(array $filter = [], ?int $page = null, ?int $length = null): DataResponse { + try { + $this->validateHelper->userCanApproveValidationDocuments($this->userSession->getUser()); + $return = $this->accountFileService->accountFileList($filter, $page, $length); + return new DataResponse($return, Http::STATUS_OK); + } catch (\Throwable $th) { + return new DataResponse( + [ + 'message' => $th->getMessage() + ], + Http::STATUS_NOT_FOUND + ); + } + } +} diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index b0256404ed..9a9bf044b5 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -290,11 +290,18 @@ public function sign(string $uuid): TemplateResponse { ->setFile($this->getFileEntity()) ->setHost($this->request->getServerHost()) ->setMe($this->userSession->getUser()) + ->setSignerIdentified() ->setIdentifyMethodId($this->sessionService->getIdentifyMethodId()) ->setSignRequest($this->getSignRequestEntity()) ->showVisibleElements() ->showSigners() + ->showSettings() ->toArray(); + $this->initialState->provideInitialState('config', [ + 'identificationDocumentsFlow' => $file['settings']['needIdentificationDocuments'] ?? false, + ]); + $this->initialState->provideInitialState('needIdentificationDocuments', $file['settings']['needIdentificationDocuments'] ?? false); + $this->initialState->provideInitialState('identificationDocumentsWaitingApproval', $file['settings']['identificationDocumentsWaitingApproval'] ?? false); $this->initialState->provideInitialState('status', $file['status']); $this->initialState->provideInitialState('statusText', $file['statusText']); $this->initialState->provideInitialState('signers', $file['signers']); diff --git a/lib/Db/AccountFileMapper.php b/lib/Db/AccountFileMapper.php index 28ad33f14a..f5ecf9e80e 100644 --- a/lib/Db/AccountFileMapper.php +++ b/lib/Db/AccountFileMapper.php @@ -8,8 +8,8 @@ namespace OCA\Libresign\Db; -use OCA\Libresign\Helper\Pagination; use OCP\AppFramework\Db\Entity; + use OCP\AppFramework\Db\QBMapper; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\Types; @@ -75,179 +75,6 @@ public function getByFileId(int $fileId): AccountFile { return $this->findEntity($qb); } - public function accountFileList(array $filter, ?int $page = null, ?int $length = null): array { - $filter['length'] = $length; - $filter['page'] = $page; - $pagination = $this->getUserAccountFile($filter); - $pagination->setMaxPerPage($length); - $pagination->setCurrentPage($page); - $currentPageResults = $pagination->getCurrentPageResults(); - - $url = $this->urlGenerator->linkToRoute('libresign.page.getPdfFile', ['uuid' => '_replace_']); - $url = str_replace('_replace_', '', $url); - - $data = []; - $fileIds = []; - - foreach ($currentPageResults as $row) { - $fileIds[] = $row['id']; - $data[] = $this->formatListRow($row, $url); - } - $signers = $this->signRequestMapper->getByMultipleFileId($fileIds); - $return['data'] = $this->assocFileToSignRequestAndFormat($data, $signers); - $return['pagination'] = $pagination; - return $return; - } - - private function getQueryBuilder(array $filter = [], bool $count = false): IQueryBuilder { - $qb = $this->db->getQueryBuilder(); - if ($count) { - $qb->select($qb->func()->count()) - ->setFirstResult(0) - ->setMaxResults(null); - } else { - $qb - ->select( - 'f.id', - 'f.uuid', - 'f.name', - 'f.callback', - 'f.status', - 'f.node_id', - 'af.file_type', - 'f.created_at', - ) - ->selectAlias('u.uid_lower', 'account_uid') - ->selectAlias('u.displayname', 'account_displayname') - ->groupBy( - 'f.id', - 'f.uuid', - 'f.name', - 'f.callback', - 'f.status', - 'f.node_id', - 'f.created_at', - 'af.file_type', - 'u.uid_lower', - 'u.displayname' - ); - if (isset($filter['length']) && isset($filter['page'])) { - $qb->setFirstResult($filter['length'] * ($filter['page'] - 1)); - $qb->setMaxResults($filter['length']); - } - } - $qb - ->from($this->getTableName(), 'af') - ->join('af', 'libresign_file', 'f', 'f.id = af.file_id') - ->join('af', 'users', 'u', 'af.user_id = u.uid') - ->leftJoin('f', 'libresign_sign_request', 'sr', 'sr.file_id = f.id'); - if (!empty($filter['userId'])) { - $qb->where( - $qb->expr()->eq('af.user_id', $qb->createNamedParameter($filter['userId'])), - ); - } - if (!empty($filter['approved'])) { - if ($filter['approved'] === 'yes') { - $qb->andWhere( - $qb->expr()->eq('f.status', $qb->createNamedParameter(File::STATUS_SIGNED, Types::INTEGER)), - ); - } - } - if (!empty($filter['userId'])) { - $qb->andWhere( - $qb->expr()->eq('af.user_id', $qb->createNamedParameter($filter['userId'])), - ); - } - return $qb; - } - - private function getUserAccountFile(array $filter = []): Pagination { - $qb = $this->getQueryBuilder( - filter: $filter, - ); - $countQb = $this->getQueryBuilder( - filter: $filter, - count: true, - ); - - $pagination = new Pagination($qb, $this->urlGenerator, $countQb); - return $pagination; - } - - private function formatListRow(array $row, string $url): array { - $row['account'] = [ - 'uid' => $row['account_uid'], - 'displayName' => $row['account_displayname'] - ]; - $row['file_type'] = [ - 'type' => $row['file_type'], - 'name' => $this->fileTypeMapper->getNameOfType($row['file_type']), - 'description' => $this->fileTypeMapper->getDescriptionOfType($row['file_type']), - ]; - $row['created_at'] = (new \DateTime()) - ->setTimestamp((int)$row['created_at']) - ->format('Y-m-d H:i:s'); - $row['file'] = [ - 'name' => $row['name'], - 'status' => $row['status'], - 'statusText' => $this->fileMapper->getTextOfStatus((int)$row['status']), - 'created_at' => $row['created_at'], - 'file' => [ - 'type' => 'pdf', - 'nodeId' => (int)$row['node_id'], - 'url' => $url . $row['uuid'], - ], - 'callback' => $row['callback'], - 'uuid' => $row['uuid'], - ]; - unset( - $row['node_id'], - $row['name'], - $row['status'], - $row['created_at'], - $row['account_displayname'], - $row['account_uid'], - $row['callback'], - $row['uuid'], - $row['account_uid'], - ); - return $row; - } - - /** - * @param array $files - * @param SignRequest[] $signers - */ - private function assocFileToSignRequestAndFormat(array $files, array $signers): array { - foreach ($files as $key => $file) { - $totalSigned = 0; - $files[$key]['file']['signers'] = []; - foreach ($signers as $signerKey => $signer) { - if ($signer->getFileId() === $file['id']) { - $data = [ - 'description' => $signer->getDescription(), - 'displayName' => $signer->getDisplayName(), - 'request_sign_date' => (new \DateTime()) - ->setTimestamp($signer->getCreatedAt()) - ->format('Y-m-d H:i:s'), - 'sign_date' => null, - 'signRequestId' => $signer->getId(), - ]; - if ($signer->getSigned()) { - $data['sign_date'] = (new \DateTime()) - ->setTimestamp($signer->getSigned()) - ->format('Y-m-d H:i:s'); - $totalSigned++; - } - $files[$key]['file']['signers'][] = $data; - unset($signers[$signerKey]); - } - } - unset($files[$key]['id']); - } - return $files; - } - public function delete(Entity $entity): Entity { $qb = $this->db->getQueryBuilder(); diff --git a/lib/Db/File.php b/lib/Db/File.php index 9d91c49f77..b2bd4cf6a8 100644 --- a/lib/Db/File.php +++ b/lib/Db/File.php @@ -22,6 +22,8 @@ * @method ?string getSignedHash() * @method void setUserId(string $userId) * @method ?string getUserId() + * @method void setSignRequestId(string $signRequestId) + * @method ?int getSignRequestId() * @method void setUuid(string $uuid) * @method string getUuid() * @method void setCreatedAt(int $createdAt) @@ -42,6 +44,7 @@ class File extends Entity { protected string $name = ''; protected ?int $status = null; protected ?string $userId = null; + protected ?int $signRequestId = null; protected ?int $signedNodeId = null; protected ?string $signedHash = null; protected ?string $callback = null; @@ -56,6 +59,7 @@ class File extends Entity { public function __construct() { $this->addType('id', Types::INTEGER); $this->addType('nodeId', Types::INTEGER); + $this->addType('signRequestId', Types::INTEGER); $this->addType('signedNodeId', Types::INTEGER); $this->addType('signedHash', Types::STRING); $this->addType('userId', Types::STRING); diff --git a/lib/Db/IdDocsMapper.php b/lib/Db/IdDocsMapper.php new file mode 100644 index 0000000000..580245e5b0 --- /dev/null +++ b/lib/Db/IdDocsMapper.php @@ -0,0 +1,218 @@ + + */ +class IdDocsMapper extends QBMapper { + public function __construct( + IDBConnection $db, + private IURLGenerator $urlGenerator, + private FileMapper $fileMapper, + private SignRequestMapper $signRequestMapper, + private FileTypeMapper $fileTypeMapper, + ) { + parent::__construct($db, 'libresign_id_docs'); + } + + public function list(array $filter, ?int $page = null, ?int $length = null): array { + $filter['length'] = $length; + $filter['page'] = $page; + $pagination = $this->getDocs($filter); + $pagination->setMaxPerPage($length); + $pagination->setCurrentPage($page); + $currentPageResults = $pagination->getCurrentPageResults(); + + $url = $this->urlGenerator->linkToRoute('libresign.page.getPdfFile', ['uuid' => '_replace_']); + $url = str_replace('_replace_', '', $url); + + $data = []; + $fileIds = []; + + foreach ($currentPageResults as $row) { + $fileIds[] = $row['id']; + $data[] = $this->formatListRow($row, $url); + } + $signers = $this->signRequestMapper->getByMultipleFileId($fileIds); + $return['data'] = $this->assocFileToSignRequestAndFormat($data, $signers); + $return['pagination'] = $pagination; + return $return; + } + + private function getQueryBuilder(array $filter = [], bool $count = false): IQueryBuilder { + $qb = $this->db->getQueryBuilder(); + if ($count) { + $qb->select($qb->func()->count()) + ->setFirstResult(0) + ->setMaxResults(null); + } else { + $qb + ->select( + 'f.id', + 'f.uuid', + 'f.name', + 'f.callback', + 'f.status', + 'f.node_id', + 'id.file_type', + 'f.created_at', + ) + ->groupBy( + 'f.id', + 'f.uuid', + 'f.name', + 'f.callback', + 'f.status', + 'f.node_id', + 'f.created_at', + 'id.file_type', + ); + if (isset($filter['length']) && isset($filter['page'])) { + $qb->setFirstResult($filter['length'] * ($filter['page'] - 1)); + $qb->setMaxResults($filter['length']); + } + } + $qb + ->from($this->getTableName(), 'id') + ->join('id', 'libresign_file', 'f', 'f.id = id.file_id'); + if (empty($filter['singRequestId'])) { + if (!$count) { + $qb->addSelect('im.identifier_key') + ->addSelect('im.identifier_value') + ->addGroupBy('im.identifier_key') + ->addGroupBy('im.identifier_value'); + } + $qb + ->join('f', 'libresign_sign_request', 'sr', 'sr.file_id = f.id') + ->join('sr', 'libresign_identify_method', 'im', 'im.sign_request_id = sr.id') + ->where( + $qb->expr()->eq('sr.id', $qb->createNamedParameter($filter['singRequestId'])), + ); + } + if (!empty($filter['userId'])) { + if (!$count) { + $qb->selectAlias('u.uid_lower', 'account_uid') + ->selectAlias('u.displayname', 'account_displayname') + ->addGroupBy('u.uid_lower') + ->addGroupBy('u.displayname'); + } + $qb + ->join('id', 'users', 'u', 'id.user_id = u.uid') + ->where( + $qb->expr()->eq('id.user_id', $qb->createNamedParameter($filter['userId'])), + ); + } + if (!empty($filter['approved'])) { + if ($filter['approved'] === 'yes') { + $qb->andWhere( + $qb->expr()->eq('f.status', $qb->createNamedParameter(File::STATUS_SIGNED, Types::INTEGER)), + ); + } + } + return $qb; + } + + private function getDocs(array $filter = []): Pagination { + $qb = $this->getQueryBuilder( + filter: $filter, + ); + $countQb = $this->getQueryBuilder( + filter: $filter, + count: true, + ); + + $pagination = new Pagination($qb, $this->urlGenerator, $countQb); + return $pagination; + } + + private function formatListRow(array $row, string $url): array { + $row['account'] = [ + 'uid' => $row['account_uid'], + 'displayName' => $row['account_displayname'] + ]; + $row['file_type'] = [ + 'type' => $row['file_type'], + 'name' => $this->fileTypeMapper->getNameOfType($row['file_type']), + 'description' => $this->fileTypeMapper->getDescriptionOfType($row['file_type']), + ]; + $row['created_at'] = (new \DateTime()) + ->setTimestamp((int)$row['created_at']) + ->format('Y-m-d H:i:s'); + $row['file'] = [ + 'name' => $row['name'], + 'status' => $row['status'], + 'statusText' => $this->fileMapper->getTextOfStatus((int)$row['status']), + 'created_at' => $row['created_at'], + 'file' => [ + 'type' => 'pdf', + 'nodeId' => (int)$row['node_id'], + 'url' => $url . $row['uuid'], + ], + 'callback' => $row['callback'], + 'uuid' => $row['uuid'], + ]; + unset( + $row['node_id'], + $row['name'], + $row['status'], + $row['created_at'], + $row['account_displayname'], + $row['account_uid'], + $row['callback'], + $row['uuid'], + $row['account_uid'], + ); + return $row; + } + + /** + * @param array $files + * @param SignRequest[] $signers + */ + private function assocFileToSignRequestAndFormat(array $files, array $signers): array { + foreach ($files as $key => $file) { + $totalSigned = 0; + $files[$key]['file']['signers'] = []; + foreach ($signers as $signerKey => $signer) { + if ($signer->getFileId() === $file['id']) { + $data = [ + 'description' => $signer->getDescription(), + 'displayName' => $signer->getDisplayName(), + 'request_sign_date' => (new \DateTime()) + ->setTimestamp($signer->getCreatedAt()) + ->format('Y-m-d H:i:s'), + 'sign_date' => null, + 'signRequestId' => $signer->getId(), + ]; + if ($signer->getSigned()) { + $data['sign_date'] = (new \DateTime()) + ->setTimestamp($signer->getSigned()) + ->format('Y-m-d H:i:s'); + $totalSigned++; + } + $files[$key]['file']['signers'][] = $data; + unset($signers[$signerKey]); + } + } + unset($files[$key]['id']); + } + return $files; + } +} diff --git a/lib/Migration/Version12000Date20250127160457.php b/lib/Migration/Version12000Date20250127160457.php new file mode 100644 index 0000000000..76166b76af --- /dev/null +++ b/lib/Migration/Version12000Date20250127160457.php @@ -0,0 +1,57 @@ +hasTable('libresign_id_docs')) { + $table = $schema->createTable('libresign_id_docs'); + + $table->addColumn('id', Types::BIGINT, [ + 'autoincrement' => true, + 'notnull' => true, + ]); + $table->addColumn('file_id', Types::BIGINT, [ + 'notnull' => true, + ]); + $table->addColumn('sign_request_id', Types::BIGINT, [ + 'unsigned' => true, + ]); + $table->addColumn('user_id', Types::STRING, [ + 'length' => 64, + ]); + $table->addColumn('file_type', Types::STRING, [ + 'notnull' => true, + ]); + $table->setPrimaryKey(['id']); + $table->addIndex(['file_id']); + $table->addIndex(['sign_request_id']); + $table->addIndex(['user_id']); + $table->addUniqueIndex(['sign_request_id', 'user_id', 'file_type'], 'libresign_id_docs_unique'); + } + return $schema; + } +} diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php index a918593d51..d1340c0152 100644 --- a/lib/ResponseDefinitions.php +++ b/lib/ResponseDefinitions.php @@ -34,7 +34,7 @@ * fileId?: non-negative-int, * url?: string, * } - * @psalm-type LibresignAccountFile = array{ + * @psalm-type LibresignIdDocs = array{ * file: LibresignNewFile, * name?: string, * type?: string, diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php index 82724c3ab7..30f908ad4d 100644 --- a/lib/Service/AccountService.php +++ b/lib/Service/AccountService.php @@ -147,35 +147,6 @@ public function validateCertificateData(array $data): void { } } - public function validateAccountFiles(array $files, IUser $user): void { - foreach ($files as $fileIndex => $file) { - $this->validateAccountFile($fileIndex, $file, $user); - } - } - - private function validateAccountFile(int $fileIndex, array $file, IUser $user): void { - $profileFileTypes = $this->fileTypeMapper->getTypes(); - if (!array_key_exists($file['type'], $profileFileTypes)) { - throw new LibresignException(json_encode([ - 'type' => 'danger', - 'file' => $fileIndex, - 'message' => $this->l10n->t('Invalid file type.') - ])); - } - - try { - $this->validateHelper->validateFileTypeExists($file['type']); - $this->validateHelper->validateNewFile($file, ValidateHelper::TYPE_ACCOUNT_DOCUMENT, $user); - $this->validateHelper->validateUserHasNoFileWithThisType($user->getUID(), $file['type']); - } catch (\Exception $e) { - throw new LibresignException(json_encode([ - 'type' => 'danger', - 'file' => $fileIndex, - 'message' => $e->getMessage() - ])); - } - } - /** * Get signRequest by Uuid */ @@ -330,24 +301,6 @@ public function getSettings(?IUser $user = null): array { return $return; } - public function addFilesToAccount(array $files, IUser $user): void { - $this->validateAccountFiles($files, $user); - foreach ($files as $fileData) { - $dataToSave = $fileData; - $dataToSave['userManager'] = $user; - $dataToSave['name'] = $fileData['name'] ?? $fileData['type']; - $file = $this->requestSignatureService->saveFile($dataToSave); - - $this->accountFileService->addFile($file, $user, $fileData['type']); - } - } - - public function deleteFileFromAccount(int $nodeId, IUser $user): void { - $this->validateHelper->validateAccountFileIsOwnedByUser($nodeId, $user->getUID()); - $accountFile = $this->accountFileMapper->getByUserIdAndNodeId($user->getUID(), $nodeId); - $this->accountFileService->deleteFile($accountFile->getFileId(), $user->getUID()); - } - public function saveVisibleElements(array $elements, string $sessionId, ?IUser $user): void { foreach ($elements as $element) { $this->saveVisibleElement($element, $sessionId, $user); @@ -386,7 +339,7 @@ private function updateDataOfVisibleElement(array $data): void { private function saveFileOfVisibleElementUsingUser(array $data, IUser $user): File { $rootSignatureFolder = $this->folderService->getFolder(); - $folderName = $this->folderService->getFolderName($data, $user); + $folderName = $this->folderService->getFolderName($data, $user->getUID()); if ($rootSignatureFolder->nodeExists($folderName)) { throw new \Exception($this->l10n->t('File already exists')); } diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 34d7124c00..d1fea8c381 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -52,6 +52,7 @@ class FileService { private bool $showMessages = false; private bool $validateFile = false; private bool $signersLibreSignLoaded = false; + private bool $signerIdentified = false; private string $fileContent = ''; private string $host = ''; private ?File $file = null; @@ -141,6 +142,11 @@ public function setMe(?IUser $user): self { return $this; } + public function setSignerIdentified(bool $identified = true): self { + $this->signerIdentified = $identified; + return $this; + } + public function setIdentifyMethodId(?int $id): self { $this->identifyMethodId = $id; return $this; @@ -570,7 +576,9 @@ private function loadSettings(): void { if ($this->me) { $this->fileData->settings = array_merge($this->fileData->settings, $this->accountService->getSettings($this->me)); $this->fileData->settings['phoneNumber'] = $this->getPhoneNumber(); - $status = $this->getIdentificationDocumentsStatus($this->me->getUID()); + } + if ($this->signerIdentified || $this->me) { + $status = $this->getIdentificationDocumentsStatus(); if ($status === self::IDENTIFICATION_DOCUMENTS_NEED_SEND) { $this->fileData->settings['needIdentificationDocuments'] = true; $this->fileData->settings['identificationDocumentsWaitingApproval'] = false; @@ -581,14 +589,18 @@ private function loadSettings(): void { } } - public function getIdentificationDocumentsStatus(?string $userId): int { + public function getIdentificationDocumentsStatus(string $userId = ''): int { if (!$this->appConfig->getValueBool(Application::APP_ID, 'identification_documents', false)) { return self::IDENTIFICATION_DOCUMENTS_DISABLED; } + if (!$userId && $this->me instanceof IUser) { + $userId = $this->me->getUID(); + } if (!empty($userId)) { $files = $this->fileMapper->getFilesOfAccount($userId); } + if (empty($files) || !count($files)) { return self::IDENTIFICATION_DOCUMENTS_NEED_SEND; } diff --git a/lib/Service/FolderService.php b/lib/Service/FolderService.php index 5c1a52c9f5..3b4d04c560 100644 --- a/lib/Service/FolderService.php +++ b/lib/Service/FolderService.php @@ -146,7 +146,7 @@ private function getLibreSignDefaultPath(): string { * @param array{settings: array, name: string} $data * @param IUser $owner */ - public function getFolderName(array $data, IUser $owner): string { + public function getFolderName(array $data, $identifier): string { if (isset($data['settings']['folderName'])) { return $data['settings']['folderName']; } @@ -161,7 +161,7 @@ public function getFolderName(array $data, IUser $owner): string { 'name' => 'name' ]; $data['settings']['folderPatterns'][] = [ - 'name' => 'userId' + 'name' => 'identifier' ]; } $folderName = null; @@ -175,8 +175,8 @@ public function getFolderName(array $data, IUser $owner): string { $folderName[] = $data['name']; } break; - case 'userId': - $folderName[] = $owner->getUID(); + case 'identifier': + $folderName[] = $identifier; break; } } diff --git a/lib/Service/IdDocsService.php b/lib/Service/IdDocsService.php new file mode 100644 index 0000000000..dc0a485227 --- /dev/null +++ b/lib/Service/IdDocsService.php @@ -0,0 +1,117 @@ +fileTypeMapper->getTypes(); + if (!array_key_exists($file['type'], $profileFileTypes)) { + throw new LibresignException(json_encode([ + 'type' => 'danger', + 'file' => $fileIndex, + 'message' => $this->l10n->t('Invalid file type.') + ])); + } + } + + private function validateAccountFile(int $fileIndex, array $file, IUser $user): void { + $profileFileTypes = $this->fileTypeMapper->getTypes(); + if (!array_key_exists($file['type'], $profileFileTypes)) { + throw new LibresignException(json_encode([ + 'type' => 'danger', + 'file' => $fileIndex, + 'message' => $this->l10n->t('Invalid file type.') + ])); + } + + try { + $this->validateHelper->validateFileTypeExists($file['type']); + $this->validateHelper->validateNewFile($file, ValidateHelper::TYPE_ACCOUNT_DOCUMENT, $user); + $this->validateHelper->validateUserHasNoFileWithThisType($user->getUID(), $file['type']); + } catch (\Exception $e) { + throw new LibresignException(json_encode([ + 'type' => 'danger', + 'file' => $fileIndex, + 'message' => $e->getMessage() + ])); + } + } + + public function validateAccountFiles(array $files, IUser $user): void { + foreach ($files as $fileIndex => $file) { + $this->validateTypeOfFile($fileIndex, $file); + $this->validateAccountFile($fileIndex, $file, $user); + } + } + + public function addFilesToAccount(array $files, IUser $user): void { + $this->validateAccountFiles($files, $user); + foreach ($files as $fileData) { + $dataToSave = $fileData; + $dataToSave['userManager'] = $user; + $dataToSave['name'] = $fileData['name'] ?? $fileData['type']; + $file = $this->requestSignatureService->saveFile($dataToSave); + + $this->accountFileService->addFile($file, $user, $fileData['type']); + } + } + + public function addFilesToDocumentFolder(array $files, SignRequest $signRequest): void { + foreach ($files as $fileIndex => $file) { + $this->validateTypeOfFile($fileIndex, $file); + } + foreach ($files as $fileData) { + $dataToSave = $fileData; + $dataToSave['signRequest'] = $signRequest; + $dataToSave['name'] = $fileData['name'] ?? $fileData['type']; + $file = $this->requestSignatureService->saveFile($dataToSave); + + $this->accountFileService->addFile($file, $user, $fileData['type']); + } + } + + public function list(array $filter, ?int $page = null, ?int $length = null): array { + $page = $page ?? 1; + $length = $length ?? (int)$this->appConfig->getValueInt(Application::APP_ID, 'length_of_page', 100); + $data = $this->idDocsMapper->list($filter, $page, $length); + $data['pagination']->setRouteName('ocs.libresign.File.list'); + return [ + 'data' => $data['data'], + 'pagination' => $data['pagination']->getPagination($page, $length, $filter) + ]; + } + + public function deleteFileFromAccount(int $nodeId, IUser $user): void { + $this->validateHelper->validateAccountFileIsOwnedByUser($nodeId, $user->getUID()); + $accountFile = $this->accountFileMapper->getByUserIdAndNodeId($user->getUID(), $nodeId); + $this->accountFileService->deleteFile($accountFile->getFileId(), $user->getUID()); + } +} diff --git a/lib/Service/RequestSignatureService.php b/lib/Service/RequestSignatureService.php index da0cb5aa81..f85750d697 100644 --- a/lib/Service/RequestSignatureService.php +++ b/lib/Service/RequestSignatureService.php @@ -57,7 +57,7 @@ public function save(array $data): FileEntity { /** * Save file data * - * @param array{userManager: IUser, name: string, callback: string, uuid?: ?string, status: int, file?: array{fileId?: int, fileNode?: Node}} $data + * @param array{?userManager: IUser, ?signRequest: SignRequest, name: string, callback: string, uuid?: ?string, status: int, file?: array{fileId?: int, fileNode?: Node}} $data */ public function saveFile(array $data): FileEntity { if (!empty($data['uuid'])) { @@ -82,7 +82,11 @@ public function saveFile(array $data): FileEntity { $file = new FileEntity(); $file->setNodeId($node->getId()); - $file->setUserId($data['userManager']->getUID()); + if ($data['userManager'] instanceof IUser) { + $file->setUserId($data['userManager']->getUID()); + } elseif ($data['signRequest'] instanceof SignRequestEntity) { + $file->setSignRequestId($data['signRequest']->getId()); + } $file->setUuid(UUIDUtil::getUUID()); $file->setCreatedAt(time()); $file->setName($data['name']); diff --git a/lib/Service/TFile.php b/lib/Service/TFile.php index 44ee159d2c..8790ddac4b 100644 --- a/lib/Service/TFile.php +++ b/lib/Service/TFile.php @@ -8,8 +8,10 @@ namespace OCA\Libresign\Service; +use OCA\Libresign\Db\SignRequest; use OCP\Files\Node; use OCP\Http\Client\IClientService; +use OCP\IUser; use setasign\Fpdi\PdfParserService\Type\PdfTypeException; trait TFile { @@ -18,7 +20,7 @@ trait TFile { protected IClientService $client; public function getNodeFromData(array $data): Node { - if (!$this->folderService->getUserId()) { + if (!$this->folderService->getUserId() && $data['userManager'] instanceof IUser) { $this->folderService->setUserId($data['userManager']->getUID()); } if (isset($data['file']['fileNode']) && $data['file']['fileNode'] instanceof Node) { @@ -39,7 +41,14 @@ public function getNodeFromData(array $data): Node { } $userFolder = $this->folderService->getFolder(); - $folderName = $this->folderService->getFolderName($data, $data['userManager']); + if ($data['userManager'] instanceof IUser) { + $identifier = $data['userManager']->getUID(); + } elseif ($data['userManager'] instanceof SignRequest) { + $identifier = $data['userManager']->getDisplayName(); + } else { + $identifier = ''; + } + $folderName = $this->folderService->getFolderName($data, $identifier); if ($userFolder->nodeExists($folderName)) { throw new \Exception($this->l10n->t('File already exists')); } diff --git a/openapi-full.json b/openapi-full.json index f6a1453e17..999d5b7036 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -20,23 +20,6 @@ } }, "schemas": { - "AccountFile": { - "type": "object", - "required": [ - "file" - ], - "properties": { - "file": { - "$ref": "#/components/schemas/NewFile" - }, - "name": { - "type": "string" - }, - "type": { - "type": "string" - } - } - }, "CertificatePfxData": { "type": "object", "required": [ @@ -332,6 +315,23 @@ } } }, + "IdDocs": { + "type": "object", + "required": [ + "file" + ], + "properties": { + "file": { + "$ref": "#/components/schemas/NewFile" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, "IdentifyAccount": { "type": "object", "required": [ @@ -2021,43 +2021,20 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/files": { - "post": { - "operationId": "account-add-files", - "summary": "Add files to account profile", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/me": { + "get": { + "operationId": "account-me", + "summary": "Who am I", + "description": "Validates API access data and returns the authenticated user's data.", "tags": [ "account" ], "security": [ - { - "bearer_auth": [] - }, + {}, { "basic_auth": [] } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "files" - ], - "properties": { - "files": { - "type": "array", - "description": "The list of files to add to profile", - "items": { - "$ref": "#/components/schemas/AccountFile" - } - } - } - } - } - } - }, "parameters": [ { "name": "apiVersion", @@ -2084,7 +2061,7 @@ ], "responses": { "200": { - "description": "Certificate saved with success", + "description": "OK", "content": { "application/json": { "schema": { @@ -2103,7 +2080,49 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "account", + "settings" + ], + "properties": { + "account": { + "type": "object", + "required": [ + "uid", + "emailAddress", + "displayName" + ], + "properties": { + "uid": { + "type": "string" + }, + "emailAddress": { + "type": "string" + }, + "displayName": { + "type": "string" + } + } + }, + "settings": { + "type": "object", + "required": [ + "canRequestSign", + "hasSignatureFile" + ], + "properties": { + "canRequestSign": { + "type": "boolean" + }, + "hasSignatureFile": { + "type": "boolean" + } + } + } + } + } } } } @@ -2111,8 +2130,8 @@ } } }, - "401": { - "description": "No file provided or other problem with provided file", + "404": { + "description": "Invalid user or password", "content": { "application/json": { "schema": { @@ -2134,24 +2153,9 @@ "data": { "type": "object", "required": [ - "file", - "type", "message" ], "properties": { - "file": { - "type": "integer", - "format": "int64", - "nullable": true - }, - "type": { - "type": "string", - "enum": [ - "info", - "warning", - "danger" - ] - }, "message": { "type": "string" } @@ -2165,10 +2169,12 @@ } } } - }, - "delete": { - "operationId": "account-delete-file", - "summary": "Delete file from account", + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/settings": { + "patch": { + "operationId": "account-update-settings", + "summary": "Update the account phone number", "tags": [ "account" ], @@ -2180,6 +2186,23 @@ "basic_auth": [] } ], + "requestBody": { + "required": false, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "phone": { + "type": "string", + "nullable": true, + "description": "the phone number to be defined. If null will remove the phone number" + } + } + } + } + } + }, "parameters": [ { "name": "apiVersion", @@ -2193,16 +2216,6 @@ "default": "v1" } }, - { - "name": "nodeId", - "in": "query", - "description": "the nodeId of file to be delete", - "required": true, - "schema": { - "type": "integer", - "format": "int64" - } - }, { "name": "OCS-APIRequest", "in": "header", @@ -2216,7 +2229,7 @@ ], "responses": { "200": { - "description": "File deleted with success", + "description": "Settings saved", "content": { "application/json": { "schema": { @@ -2235,7 +2248,33 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "type": "object", + "required": [ + "userId", + "phone", + "message" + ], + "properties": { + "userId": { + "type": "string" + }, + "phone": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } + } + } } } } @@ -2243,8 +2282,8 @@ } } }, - "401": { - "description": "Failure to delete file from account", + "404": { + "description": "Invalid data to update phone number", "content": { "application/json": { "schema": { @@ -2266,14 +2305,11 @@ "data": { "type": "object", "required": [ - "messages" + "message" ], "properties": { - "messages": { - "type": "array", - "items": { - "type": "string" - } + "message": { + "type": "string" } } } @@ -2285,10 +2321,12 @@ } } } - }, - "get": { - "operationId": "account-account-file-list-to-owner", - "summary": "List account files of authenticated account", + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/pfx": { + "delete": { + "operationId": "account-delete-pfx", + "summary": "Delete PFX file", "tags": [ "account" ], @@ -2313,35 +2351,6 @@ "default": "v1" } }, - { - "name": "filter", - "in": "query", - "description": "Filter params", - "schema": { - "type": "string", - "nullable": true - } - }, - { - "name": "page", - "in": "query", - "description": "the number of page to return", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "length", - "in": "query", - "description": "Total of elements to return", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, { "name": "OCS-APIRequest", "in": "header", @@ -2354,8 +2363,8 @@ } ], "responses": { - "200": { - "description": "Certificate saved with success", + "202": { + "description": "Certificate deleted with success", "content": { "application/json": { "schema": { @@ -2377,52 +2386,7 @@ "data": { "type": "object", "required": [ - "pagination", - "data" - ], - "properties": { - "pagination": { - "$ref": "#/components/schemas/Pagination" - }, - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/File" - } - } - } - } - } - } - } - } - } - } - }, - "404": { - "description": "No file provided or other problem with provided file", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": { - "type": "object", - "required": [ - "message" + "message" ], "properties": { "message": { @@ -2438,18 +2402,17 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/me": { - "get": { - "operationId": "account-me", - "summary": "Who am I", - "description": "Validates API access data and returns the authenticated user's data.", + }, + "post": { + "operationId": "account-upload-pfx", + "summary": "Upload PFX file", "tags": [ "account" ], "security": [ - {}, + { + "bearer_auth": [] + }, { "basic_auth": [] } @@ -2479,8 +2442,8 @@ } ], "responses": { - "200": { - "description": "OK", + "202": { + "description": "Certificate saved with success", "content": { "application/json": { "schema": { @@ -2502,43 +2465,11 @@ "data": { "type": "object", "required": [ - "account", - "settings" + "message" ], "properties": { - "account": { - "type": "object", - "required": [ - "uid", - "emailAddress", - "displayName" - ], - "properties": { - "uid": { - "type": "string" - }, - "emailAddress": { - "type": "string" - }, - "displayName": { - "type": "string" - } - } - }, - "settings": { - "type": "object", - "required": [ - "canRequestSign", - "hasSignatureFile" - ], - "properties": { - "canRequestSign": { - "type": "boolean" - }, - "hasSignatureFile": { - "type": "boolean" - } - } + "message": { + "type": "string" } } } @@ -2549,8 +2480,8 @@ } } }, - "404": { - "description": "Invalid user or password", + "400": { + "description": "No file provided or other problem with provided file", "content": { "application/json": { "schema": { @@ -2588,12 +2519,11 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/files/approval/list": { - "get": { - "operationId": "account-account-file-list-to-approval", - "summary": "List account files that need to be approved", + }, + "patch": { + "operationId": "account-update-pfx-password", + "summary": "Update PFX file", + "description": "Used to change the password of PFX file", "tags": [ "account" ], @@ -2605,6 +2535,30 @@ "basic_auth": [] } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "current", + "new" + ], + "properties": { + "current": { + "type": "string", + "description": "Current password" + }, + "new": { + "type": "string", + "description": "New password" + } + } + } + } + } + }, "parameters": [ { "name": "apiVersion", @@ -2618,35 +2572,6 @@ "default": "v1" } }, - { - "name": "filter", - "in": "query", - "description": "Filter params", - "schema": { - "type": "string", - "nullable": true - } - }, - { - "name": "page", - "in": "query", - "description": "the number of page to return", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "length", - "in": "query", - "description": "Total of elements to return", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, { "name": "OCS-APIRequest", "in": "header", @@ -2659,8 +2584,8 @@ } ], "responses": { - "200": { - "description": "OK", + "202": { + "description": "Certificate saved with success", "content": { "application/json": { "schema": { @@ -2682,19 +2607,11 @@ "data": { "type": "object", "required": [ - "pagination", - "data" + "message" ], "properties": { - "pagination": { - "$ref": "#/components/schemas/Pagination" - }, - "data": { - "type": "array", - "nullable": true, - "items": { - "$ref": "#/components/schemas/File" - } + "message": { + "type": "string" } } } @@ -2705,8 +2622,8 @@ } } }, - "404": { - "description": "Account not found", + "400": { + "description": "No file provided or other problem with provided file", "content": { "application/json": { "schema": { @@ -2746,10 +2663,10 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/settings": { - "patch": { - "operationId": "account-update-settings", - "summary": "Update the account phone number", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/pfx/read": { + "post": { + "operationId": "account-read-pfx-data", + "summary": "Read content of PFX file", "tags": [ "account" ], @@ -2762,16 +2679,18 @@ } ], "requestBody": { - "required": false, + "required": true, "content": { "application/json": { "schema": { "type": "object", + "required": [ + "password" + ], "properties": { - "phone": { + "password": { "type": "string", - "nullable": true, - "description": "the phone number to be defined. If null will remove the phone number" + "description": "password of PFX file to decrypt the file and return his content" } } } @@ -2803,8 +2722,8 @@ } ], "responses": { - "200": { - "description": "Settings saved", + "202": { + "description": "Certificate saved with success", "content": { "application/json": { "schema": { @@ -2824,31 +2743,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "type": "object", - "required": [ - "data" - ], - "properties": { - "data": { - "type": "object", - "required": [ - "userId", - "phone", - "message" - ], - "properties": { - "userId": { - "type": "string" - }, - "phone": { - "type": "string" - }, - "message": { - "type": "string" - } - } - } - } + "$ref": "#/components/schemas/CertificatePfxData" } } } @@ -2857,8 +2752,8 @@ } } }, - "404": { - "description": "Invalid data to update phone number", + "400": { + "description": "No file provided or other problem with provided file", "content": { "application/json": { "schema": { @@ -2898,14 +2793,16 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/pfx": { - "delete": { - "operationId": "account-delete-pfx", - "summary": "Delete PFX file", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate/uuid/{uuid}": { + "get": { + "operationId": "file-validate-uuid", + "summary": "Validate a file using Uuid", + "description": "Validate a file returning file data.", "tags": [ - "account" + "file" ], "security": [ + {}, { "bearer_auth": [] }, @@ -2927,82 +2824,12 @@ } }, { - "name": "OCS-APIRequest", - "in": "header", - "description": "Required to be true for the API request to pass", + "name": "uuid", + "in": "path", + "description": "The UUID of the LibreSign file", "required": true, "schema": { - "type": "boolean", - "default": true - } - } - ], - "responses": { - "202": { - "description": "Certificate deleted with success", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": { - "type": "object", - "required": [ - "message" - ], - "properties": { - "message": { - "type": "string" - } - } - } - } - } - } - } - } - } - } - } - }, - "post": { - "operationId": "account-upload-pfx", - "summary": "Upload PFX file", - "tags": [ - "account" - ], - "security": [ - { - "bearer_auth": [] - }, - { - "basic_auth": [] - } - ], - "parameters": [ - { - "name": "apiVersion", - "in": "path", - "required": true, - "schema": { - "type": "string", - "enum": [ - "v1" - ], - "default": "v1" + "type": "string" } }, { @@ -3017,8 +2844,8 @@ } ], "responses": { - "202": { - "description": "Certificate saved with success", + "200": { + "description": "OK", "content": { "application/json": { "schema": { @@ -3038,15 +2865,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "type": "object", - "required": [ - "message" - ], - "properties": { - "message": { - "type": "string" - } - } + "$ref": "#/components/schemas/ValidateFile" } } } @@ -3055,8 +2874,8 @@ } } }, - "400": { - "description": "No file provided or other problem with provided file", + "404": { + "description": "Request failed", "content": { "application/json": { "schema": { @@ -3078,11 +2897,37 @@ "data": { "type": "object", "required": [ - "message" + "action", + "errors" ], "properties": { - "message": { - "type": "string" + "action": { + "type": "integer", + "format": "int64" + }, + "errors": { + "type": "array", + "items": { + "type": "string" + } + }, + "messages": { + "type": "array", + "items": { + "type": "object", + "required": [ + "type", + "message" + ], + "properties": { + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } } } } @@ -3094,15 +2939,18 @@ } } } - }, - "patch": { - "operationId": "account-update-pfx-password", - "summary": "Update PFX file", - "description": "Used to change the password of PFX file", + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate/file_id/{fileId}": { + "get": { + "operationId": "file-validate-file-id", + "summary": "Validate a file using FileId", + "description": "Validate a file returning file data.", "tags": [ - "account" + "file" ], "security": [ + {}, { "bearer_auth": [] }, @@ -3110,30 +2958,6 @@ "basic_auth": [] } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "current", - "new" - ], - "properties": { - "current": { - "type": "string", - "description": "Current password" - }, - "new": { - "type": "string", - "description": "New password" - } - } - } - } - } - }, "parameters": [ { "name": "apiVersion", @@ -3147,6 +2971,16 @@ "default": "v1" } }, + { + "name": "fileId", + "in": "path", + "description": "The identifier value of the LibreSign file", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + }, { "name": "OCS-APIRequest", "in": "header", @@ -3159,8 +2993,8 @@ } ], "responses": { - "202": { - "description": "Certificate saved with success", + "200": { + "description": "OK", "content": { "application/json": { "schema": { @@ -3180,15 +3014,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "type": "object", - "required": [ - "message" - ], - "properties": { - "message": { - "type": "string" - } - } + "$ref": "#/components/schemas/ValidateFile" } } } @@ -3197,8 +3023,8 @@ } } }, - "400": { - "description": "No file provided or other problem with provided file", + "404": { + "description": "Request failed", "content": { "application/json": { "schema": { @@ -3220,11 +3046,37 @@ "data": { "type": "object", "required": [ - "message" + "action", + "errors" ], "properties": { - "message": { - "type": "string" + "action": { + "type": "integer", + "format": "int64" + }, + "errors": { + "type": "array", + "items": { + "type": "string" + } + }, + "messages": { + "type": "array", + "items": { + "type": "object", + "required": [ + "type", + "message" + ], + "properties": { + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } } } } @@ -3238,14 +3090,16 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/pfx/read": { + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate": { "post": { - "operationId": "account-read-pfx-data", - "summary": "Read content of PFX file", + "operationId": "file-validate-binary", + "summary": "Validate a binary file", + "description": "Validate a binary file returning file data. Use field 'file' for the file upload", "tags": [ - "account" + "file" ], "security": [ + {}, { "bearer_auth": [] }, @@ -3253,25 +3107,6 @@ "basic_auth": [] } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "password" - ], - "properties": { - "password": { - "type": "string", - "description": "password of PFX file to decrypt the file and return his content" - } - } - } - } - } - }, "parameters": [ { "name": "apiVersion", @@ -3297,8 +3132,8 @@ } ], "responses": { - "202": { - "description": "Certificate saved with success", + "200": { + "description": "OK", "content": { "application/json": { "schema": { @@ -3318,7 +3153,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/CertificatePfxData" + "$ref": "#/components/schemas/ValidateFile" } } } @@ -3327,8 +3162,8 @@ } } }, - "400": { - "description": "No file provided or other problem with provided file", + "404": { + "description": "Request failed", "content": { "application/json": { "schema": { @@ -3350,11 +3185,37 @@ "data": { "type": "object", "required": [ - "message" + "action", + "errors" ], "properties": { - "message": { - "type": "string" + "action": { + "type": "integer", + "format": "int64" + }, + "errors": { + "type": "array", + "items": { + "type": "string" + } + }, + "messages": { + "type": "array", + "items": { + "type": "object", + "required": [ + "type", + "message" + ], + "properties": { + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } } } } @@ -3364,92 +3225,8 @@ } } } - } - } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate/uuid/{uuid}": { - "get": { - "operationId": "file-validate-uuid", - "summary": "Validate a file using Uuid", - "description": "Validate a file returning file data.", - "tags": [ - "file" - ], - "security": [ - {}, - { - "bearer_auth": [] - }, - { - "basic_auth": [] - } - ], - "parameters": [ - { - "name": "apiVersion", - "in": "path", - "required": true, - "schema": { - "type": "string", - "enum": [ - "v1" - ], - "default": "v1" - } - }, - { - "name": "uuid", - "in": "path", - "description": "The UUID of the LibreSign file", - "required": true, - "schema": { - "type": "string" - } - }, - { - "name": "OCS-APIRequest", - "in": "header", - "description": "Required to be true for the API request to pass", - "required": true, - "schema": { - "type": "boolean", - "default": true - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": { - "$ref": "#/components/schemas/ValidateFile" - } - } - } - } - } - } - } }, - "404": { + "400": { "description": "Request failed", "content": { "application/json": { @@ -3514,12 +3291,10 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate/file_id/{fileId}": { + }, "get": { - "operationId": "file-validate-file-id", - "summary": "Validate a file using FileId", + "operationId": "file-validate", + "summary": "Validate a file", "description": "Validate a file returning file data.", "tags": [ "file" @@ -3547,13 +3322,28 @@ } }, { - "name": "fileId", - "in": "path", - "description": "The identifier value of the LibreSign file", - "required": true, + "name": "type", + "in": "query", + "description": "The type of identifier could be Uuid or FileId", "schema": { - "type": "integer", - "format": "int64" + "type": "string", + "nullable": true + } + }, + { + "name": "identifier", + "in": "query", + "description": "The identifier value, could be string or integer, if UUID will be a string, if FileId will be an integer", + "schema": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer", + "format": "int64" + } + ] } }, { @@ -3665,16 +3455,14 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate": { - "post": { - "operationId": "file-validate-binary", - "summary": "Validate a binary file", - "description": "Validate a binary file returning file data. Use field 'file' for the file upload", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/list": { + "get": { + "operationId": "file-list", + "summary": "List account files that need to be approved", "tags": [ "file" ], "security": [ - {}, { "bearer_auth": [] }, @@ -3695,6 +3483,95 @@ "default": "v1" } }, + { + "name": "page", + "in": "query", + "description": "the number of page to return", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "length", + "in": "query", + "description": "Total of elements to return", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "signer_uuid", + "in": "query", + "description": "Signer UUID", + "schema": { + "type": "string", + "nullable": true + } + }, + { + "name": "nodeId", + "in": "query", + "description": "The nodeId (also called fileId). Is the id of a file at Nextcloud", + "schema": { + "type": "string", + "nullable": true + } + }, + { + "name": "status[]", + "in": "query", + "description": "Status could be none or many of 0 = draft, 1 = able to sign, 2 = partial signed, 3 = signed, 4 = deleted.", + "schema": { + "type": "array", + "nullable": true, + "items": { + "type": "integer", + "format": "int64" + } + } + }, + { + "name": "start", + "in": "query", + "description": "Start date of signature request (UNIX timestamp)", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "end", + "in": "query", + "description": "End date of signature request (UNIX timestamp)", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "sortBy", + "in": "query", + "description": "Name of the column to sort by", + "schema": { + "type": "string", + "nullable": true + } + }, + { + "name": "sortDirection", + "in": "query", + "description": "Ascending or descending order", + "schema": { + "type": "string", + "nullable": true + } + }, { "name": "OCS-APIRequest", "in": "header", @@ -3728,7 +3605,23 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/ValidateFile" + "type": "object", + "required": [ + "pagination", + "data" + ], + "properties": { + "pagination": { + "$ref": "#/components/schemas/Pagination" + }, + "data": { + "type": "array", + "nullable": true, + "items": { + "$ref": "#/components/schemas/File" + } + } + } } } } @@ -3736,9 +3629,142 @@ } } } + } + } + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/thumbnail/{nodeId}": { + "get": { + "operationId": "file-get-thumbnail", + "summary": "Return the thumbnail of a LibreSign file", + "tags": [ + "file" + ], + "security": [ + { + "bearer_auth": [] }, - "404": { - "description": "Request failed", + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "apiVersion", + "in": "path", + "required": true, + "schema": { + "type": "string", + "enum": [ + "v1" + ], + "default": "v1" + } + }, + { + "name": "nodeId", + "in": "path", + "description": "The nodeId of document", + "required": true, + "schema": { + "type": "integer", + "format": "int64", + "default": -1 + } + }, + { + "name": "x", + "in": "query", + "description": "Width of generated file", + "schema": { + "type": "integer", + "format": "int64", + "default": 32 + } + }, + { + "name": "y", + "in": "query", + "description": "Height of generated file", + "schema": { + "type": "integer", + "format": "int64", + "default": 32 + } + }, + { + "name": "a", + "in": "query", + "description": "Crop, boolean value, default false", + "schema": { + "type": "integer", + "default": 0, + "enum": [ + 0, + 1 + ] + } + }, + { + "name": "forceIcon", + "in": "query", + "description": "Force to generate a new thumbnail", + "schema": { + "type": "integer", + "default": 1, + "enum": [ + 0, + 1 + ] + } + }, + { + "name": "mode", + "in": "query", + "description": "To force a given mimetype for the file", + "schema": { + "type": "string", + "default": "fill" + } + }, + { + "name": "mimeFallback", + "in": "query", + "description": "If we have no preview enabled, we can redirect to the mime icon if any", + "schema": { + "type": "integer", + "default": 0, + "enum": [ + 0, + 1 + ] + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "*/*": { + "schema": { + "type": "string", + "format": "binary" + } + } + } + }, + "400": { + "description": "Bad request", "content": { "application/json": { "schema": { @@ -3757,43 +3783,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "object", - "required": [ - "action", - "errors" - ], - "properties": { - "action": { - "type": "integer", - "format": "int64" - }, - "errors": { - "type": "array", - "items": { - "type": "string" - } - }, - "messages": { - "type": "array", - "items": { - "type": "object", - "required": [ - "type", - "message" - ], - "properties": { - "type": { - "type": "string" - }, - "message": { - "type": "string" - } - } - } - } - } - } + "data": {} } } } @@ -3801,8 +3791,8 @@ } } }, - "400": { - "description": "Request failed", + "403": { + "description": "Forbidden", "content": { "application/json": { "schema": { @@ -3821,61 +3811,64 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "object", - "required": [ - "action", - "errors" - ], - "properties": { - "action": { - "type": "integer", - "format": "int64" - }, - "errors": { - "type": "array", - "items": { - "type": "string" - } - }, - "messages": { - "type": "array", - "items": { - "type": "object", - "required": [ - "type", - "message" - ], - "properties": { - "type": { - "type": "string" - }, - "message": { - "type": "string" - } - } - } - } - } - } + "data": {} + } + } + } + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} } } } } } } + }, + "303": { + "description": "Redirect", + "headers": { + "Location": { + "schema": { + "type": "string" + } + } + } } } - }, - "get": { - "operationId": "file-validate", - "summary": "Validate a file", - "description": "Validate a file returning file data.", + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file": { + "post": { + "operationId": "file-save", + "summary": "Send a file", + "description": "Send a new file to Nextcloud and return the fileId to request to sign usign fileId", "tags": [ "file" ], "security": [ - {}, { "bearer_auth": [] }, @@ -3883,6 +3876,35 @@ "basic_auth": [] } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "file" + ], + "properties": { + "file": { + "$ref": "#/components/schemas/NewFile", + "description": "File to save" + }, + "name": { + "type": "string", + "default": "", + "description": "The name of file to sign" + }, + "settings": { + "$ref": "#/components/schemas/FolderSettings", + "default": [], + "description": "Settings to define the pattern to store the file. See more informations at FolderService::getFolderName method." + } + } + } + } + } + }, "parameters": [ { "name": "apiVersion", @@ -3896,31 +3918,6 @@ "default": "v1" } }, - { - "name": "type", - "in": "query", - "description": "The type of identifier could be Uuid or FileId", - "schema": { - "type": "string", - "nullable": true - } - }, - { - "name": "identifier", - "in": "query", - "description": "The identifier value, could be string or integer, if UUID will be a string, if FileId will be an integer", - "schema": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "integer", - "format": "int64" - } - ] - } - }, { "name": "OCS-APIRequest", "in": "header", @@ -3954,7 +3951,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/ValidateFile" + "$ref": "#/components/schemas/NextcloudFile" } } } @@ -3963,8 +3960,8 @@ } } }, - "404": { - "description": "Request failed", + "422": { + "description": "Failed to save data", "content": { "application/json": { "schema": { @@ -3986,37 +3983,11 @@ "data": { "type": "object", "required": [ - "action", - "errors" + "message" ], "properties": { - "action": { - "type": "integer", - "format": "int64" - }, - "errors": { - "type": "array", - "items": { - "type": "string" - } - }, - "messages": { - "type": "array", - "items": { - "type": "object", - "required": [ - "type", - "message" - ], - "properties": { - "type": { - "type": "string" - }, - "message": { - "type": "string" - } - } - } + "message": { + "type": "string" } } } @@ -4030,10 +4001,11 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/list": { - "get": { - "operationId": "file-list", - "summary": "List account files that need to be approved", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/file_id/{fileId}": { + "delete": { + "operationId": "file-delete-all-request-signature-using-file-id", + "summary": "Delete File", + "description": "This will delete the file and all data", "tags": [ "file" ], @@ -4059,108 +4031,105 @@ } }, { - "name": "page", - "in": "query", - "description": "the number of page to return", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "length", - "in": "query", - "description": "Total of elements to return", + "name": "fileId", + "in": "path", + "description": "Node id of a Nextcloud file", + "required": true, "schema": { "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "signer_uuid", - "in": "query", - "description": "Signer UUID", - "schema": { - "type": "string", - "nullable": true + "format": "int64" } }, { - "name": "nodeId", - "in": "query", - "description": "The nodeId (also called fileId). Is the id of a file at Nextcloud", + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, "schema": { - "type": "string", - "nullable": true + "type": "boolean", + "default": true } - }, - { - "name": "status[]", - "in": "query", - "description": "Status could be none or many of 0 = draft, 1 = able to sign, 2 = partial signed, 3 = signed, 4 = deleted.", - "schema": { - "type": "array", - "nullable": true, - "items": { - "type": "integer", - "format": "int64" + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } } } }, - { - "name": "start", - "in": "query", - "description": "Start date of signature request (UNIX timestamp)", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "end", - "in": "query", - "description": "End date of signature request (UNIX timestamp)", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "sortBy", - "in": "query", - "description": "Name of the column to sort by", - "schema": { - "type": "string", - "nullable": true - } - }, - { - "name": "sortDirection", - "in": "query", - "description": "Ascending or descending order", - "schema": { - "type": "string", - "nullable": true + "401": { + "description": "Failed", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } + } } }, - { - "name": "OCS-APIRequest", - "in": "header", - "description": "Required to be true for the API request to pass", - "required": true, - "schema": { - "type": "boolean", - "default": true - } - } - ], - "responses": { - "200": { - "description": "OK", + "422": { + "description": "Failed", "content": { "application/json": { "schema": { @@ -4182,18 +4151,18 @@ "data": { "type": "object", "required": [ - "pagination", - "data" + "action", + "errors" ], "properties": { - "pagination": { - "$ref": "#/components/schemas/Pagination" + "action": { + "type": "integer", + "format": "int64" }, - "data": { + "errors": { "type": "array", - "nullable": true, "items": { - "$ref": "#/components/schemas/File" + "type": "string" } } } @@ -4208,12 +4177,13 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/thumbnail/{nodeId}": { - "get": { - "operationId": "file-get-thumbnail", - "summary": "Return the thumbnail of a LibreSign file", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file-element/{uuid}": { + "post": { + "operationId": "file_element-post", + "summary": "Create visible element", + "description": "Create visible element of a specific file", "tags": [ - "file" + "file_element" ], "security": [ { @@ -4223,6 +4193,47 @@ "basic_auth": [] } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "signRequestId" + ], + "properties": { + "signRequestId": { + "type": "integer", + "format": "int64", + "description": "Id of sign request" + }, + "elementId": { + "type": "integer", + "format": "int64", + "nullable": true, + "description": "ID of visible element. Each element has an ID that is returned on validation endpoints." + }, + "type": { + "type": "string", + "default": "", + "description": "The type of element to create, sginature, sinitial, date, datetime, text" + }, + "metadata": { + "type": "object", + "default": {}, + "description": "Metadata of visible elements to associate with the document" + }, + "coordinates": { + "$ref": "#/components/schemas/Coordinate", + "default": [], + "description": "Coortinates of a visible element on PDF" + } + } + } + } + } + }, "parameters": [ { "name": "apiVersion", @@ -4237,82 +4248,12 @@ } }, { - "name": "nodeId", + "name": "uuid", "in": "path", - "description": "The nodeId of document", + "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", "required": true, "schema": { - "type": "integer", - "format": "int64", - "default": -1 - } - }, - { - "name": "x", - "in": "query", - "description": "Width of generated file", - "schema": { - "type": "integer", - "format": "int64", - "default": 32 - } - }, - { - "name": "y", - "in": "query", - "description": "Height of generated file", - "schema": { - "type": "integer", - "format": "int64", - "default": 32 - } - }, - { - "name": "a", - "in": "query", - "description": "Crop, boolean value, default false", - "schema": { - "type": "integer", - "default": 0, - "enum": [ - 0, - 1 - ] - } - }, - { - "name": "forceIcon", - "in": "query", - "description": "Force to generate a new thumbnail", - "schema": { - "type": "integer", - "default": 1, - "enum": [ - 0, - 1 - ] - } - }, - { - "name": "mode", - "in": "query", - "description": "To force a given mimetype for the file", - "schema": { - "type": "string", - "default": "fill" - } - }, - { - "name": "mimeFallback", - "in": "query", - "description": "If we have no preview enabled, we can redirect to the mime icon if any", - "schema": { - "type": "integer", - "default": 0, - "enum": [ - 0, - 1 - ] + "type": "string" } }, { @@ -4329,45 +4270,6 @@ "responses": { "200": { "description": "OK", - "content": { - "*/*": { - "schema": { - "type": "string", - "format": "binary" - } - } - } - }, - "400": { - "description": "Bad request", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": {} - } - } - } - } - } - } - }, - "403": { - "description": "Forbidden", "content": { "application/json": { "schema": { @@ -4386,7 +4288,18 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "fileElementId" + ], + "properties": { + "fileElementId": { + "type": "integer", + "format": "int64" + } + } + } } } } @@ -4395,7 +4308,7 @@ } }, "404": { - "description": "Not found", + "description": "Failure when create visible element", "content": { "application/json": { "schema": { @@ -4414,34 +4327,37 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "errors" + ], + "properties": { + "errors": { + "type": "array", + "items": { + "type": "string" + } + } + } + } } } } } } } - }, - "303": { - "description": "Redirect", - "headers": { - "Location": { - "schema": { - "type": "string" - } - } - } } } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file": { - "post": { - "operationId": "file-save", - "summary": "Send a file", - "description": "Send a new file to Nextcloud and return the fileId to request to sign usign fileId", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file-element/{uuid}/{elementId}": { + "patch": { + "operationId": "file_element-patch", + "summary": "Update visible element", + "description": "Update visible element of a specific file", "tags": [ - "file" + "file_element" ], "security": [ { @@ -4458,22 +4374,28 @@ "schema": { "type": "object", "required": [ - "file" + "signRequestId" ], "properties": { - "file": { - "$ref": "#/components/schemas/NewFile", - "description": "File to save" + "signRequestId": { + "type": "integer", + "format": "int64", + "description": "Id of sign request" }, - "name": { + "type": { "type": "string", "default": "", - "description": "The name of file to sign" + "description": "The type of element to create, sginature, sinitial, date, datetime, text" }, - "settings": { - "$ref": "#/components/schemas/FolderSettings", + "metadata": { + "type": "object", + "default": {}, + "description": "Metadata of visible elements to associate with the document" + }, + "coordinates": { + "$ref": "#/components/schemas/Coordinate", "default": [], - "description": "Settings to define the pattern to store the file. See more informations at FolderService::getFolderName method." + "description": "Coortinates of a visible element on PDF" } } } @@ -4493,6 +4415,26 @@ "default": "v1" } }, + { + "name": "uuid", + "in": "path", + "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "elementId", + "in": "path", + "description": "ID of visible element. Each element has an ID that is returned on validation endpoints.", + "required": true, + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, { "name": "OCS-APIRequest", "in": "header", @@ -4526,7 +4468,16 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/NextcloudFile" + "type": "object", + "required": [ + "fileElementId" + ], + "properties": { + "fileElementId": { + "type": "integer", + "format": "int64" + } + } } } } @@ -4535,8 +4486,8 @@ } } }, - "422": { - "description": "Failed to save data", + "404": { + "description": "Failure when patch visible element", "content": { "application/json": { "schema": { @@ -4558,11 +4509,14 @@ "data": { "type": "object", "required": [ - "message" + "errors" ], "properties": { - "message": { - "type": "string" + "errors": { + "type": "array", + "items": { + "type": "string" + } } } } @@ -4574,15 +4528,13 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/file_id/{fileId}": { + }, "delete": { - "operationId": "file-delete-all-request-signature-using-file-id", - "summary": "Delete File", - "description": "This will delete the file and all data", + "operationId": "file_element-delete", + "summary": "Delete visible element", + "description": "Delete visible element of a specific file", "tags": [ - "file" + "file_element" ], "security": [ { @@ -4606,9 +4558,18 @@ } }, { - "name": "fileId", + "name": "uuid", "in": "path", - "description": "Node id of a Nextcloud file", + "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "elementId", + "in": "path", + "description": "ID of visible element. Each element has an ID that is returned on validation endpoints.", "required": true, "schema": { "type": "integer", @@ -4647,17 +4608,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "object", - "required": [ - "message" - ], - "properties": { - "message": { - "type": "string" - } - } - } + "data": {} } } } @@ -4665,8 +4616,8 @@ } } }, - "401": { - "description": "Failed", + "404": { + "description": "Failure when delete visible element or file not found", "content": { "application/json": { "schema": { @@ -4688,11 +4639,14 @@ "data": { "type": "object", "required": [ - "message" + "errors" ], "properties": { - "message": { - "type": "string" + "errors": { + "type": "array", + "items": { + "type": "string" + } } } } @@ -4702,9 +4656,102 @@ } } } + } + } + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/id-docs": { + "post": { + "operationId": "id_docs-add-files", + "summary": "Add files to account profile", + "tags": [ + "id_docs" + ], + "security": [ + { + "bearer_auth": [] }, - "422": { - "description": "Failed", + { + "basic_auth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "files" + ], + "properties": { + "files": { + "type": "array", + "description": "The list of files to add to profile", + "items": { + "$ref": "#/components/schemas/IdDocs" + } + } + } + } + } + } + }, + "parameters": [ + { + "name": "apiVersion", + "in": "path", + "required": true, + "schema": { + "type": "string", + "enum": [ + "v1" + ], + "default": "v1" + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "Certificate saved with success", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} + } + } + } + } + } + } + }, + "401": { + "description": "No file provided or other problem with provided file", "content": { "application/json": { "schema": { @@ -4726,19 +4773,26 @@ "data": { "type": "object", "required": [ - "action", - "errors" + "file", + "type", + "message" ], "properties": { - "action": { + "file": { "type": "integer", - "format": "int64" + "format": "int64", + "nullable": true }, - "errors": { - "type": "array", - "items": { - "type": "string" - } + "type": { + "type": "string", + "enum": [ + "info", + "warning", + "danger" + ] + }, + "message": { + "type": "string" } } } @@ -4750,15 +4804,12 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file-element/{uuid}": { - "post": { - "operationId": "file_element-post", - "summary": "Create visible element", - "description": "Create visible element of a specific file", + }, + "delete": { + "operationId": "id_docs-delete-file", + "summary": "Delete file from account", "tags": [ - "file_element" + "id_docs" ], "security": [ { @@ -4768,47 +4819,6 @@ "basic_auth": [] } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "signRequestId" - ], - "properties": { - "signRequestId": { - "type": "integer", - "format": "int64", - "description": "Id of sign request" - }, - "elementId": { - "type": "integer", - "format": "int64", - "nullable": true, - "description": "ID of visible element. Each element has an ID that is returned on validation endpoints." - }, - "type": { - "type": "string", - "default": "", - "description": "The type of element to create, sginature, sinitial, date, datetime, text" - }, - "metadata": { - "type": "object", - "default": {}, - "description": "Metadata of visible elements to associate with the document" - }, - "coordinates": { - "$ref": "#/components/schemas/Coordinate", - "default": [], - "description": "Coortinates of a visible element on PDF" - } - } - } - } - } - }, "parameters": [ { "name": "apiVersion", @@ -4823,12 +4833,13 @@ } }, { - "name": "uuid", - "in": "path", - "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", + "name": "nodeId", + "in": "query", + "description": "the nodeId of file to be delete", "required": true, "schema": { - "type": "string" + "type": "integer", + "format": "int64" } }, { @@ -4844,7 +4855,7 @@ ], "responses": { "200": { - "description": "OK", + "description": "File deleted with success", "content": { "application/json": { "schema": { @@ -4863,18 +4874,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "object", - "required": [ - "fileElementId" - ], - "properties": { - "fileElementId": { - "type": "integer", - "format": "int64" - } - } - } + "data": {} } } } @@ -4882,8 +4882,8 @@ } } }, - "404": { - "description": "Failure when create visible element", + "401": { + "description": "Failure to delete file from account", "content": { "application/json": { "schema": { @@ -4905,10 +4905,10 @@ "data": { "type": "object", "required": [ - "errors" + "messages" ], "properties": { - "errors": { + "messages": { "type": "array", "items": { "type": "string" @@ -4924,15 +4924,12 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file-element/{uuid}/{elementId}": { - "patch": { - "operationId": "file_element-patch", - "summary": "Update visible element", - "description": "Update visible element of a specific file", + }, + "get": { + "operationId": "id_docs-list-to-owner", + "summary": "List files of authenticated account", "tags": [ - "file_element" + "id_docs" ], "security": [ { @@ -4942,41 +4939,6 @@ "basic_auth": [] } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "signRequestId" - ], - "properties": { - "signRequestId": { - "type": "integer", - "format": "int64", - "description": "Id of sign request" - }, - "type": { - "type": "string", - "default": "", - "description": "The type of element to create, sginature, sinitial, date, datetime, text" - }, - "metadata": { - "type": "object", - "default": {}, - "description": "Metadata of visible elements to associate with the document" - }, - "coordinates": { - "$ref": "#/components/schemas/Coordinate", - "default": [], - "description": "Coortinates of a visible element on PDF" - } - } - } - } - } - }, "parameters": [ { "name": "apiVersion", @@ -4991,19 +4953,28 @@ } }, { - "name": "uuid", - "in": "path", - "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", - "required": true, + "name": "filter", + "in": "query", + "description": "Filter params", "schema": { - "type": "string" + "type": "string", + "nullable": true } }, { - "name": "elementId", - "in": "path", - "description": "ID of visible element. Each element has an ID that is returned on validation endpoints.", - "required": true, + "name": "page", + "in": "query", + "description": "the number of page to return", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "length", + "in": "query", + "description": "Total of elements to return", "schema": { "type": "integer", "format": "int64", @@ -5023,7 +4994,7 @@ ], "responses": { "200": { - "description": "OK", + "description": "Certificate saved with success", "content": { "application/json": { "schema": { @@ -5045,12 +5016,18 @@ "data": { "type": "object", "required": [ - "fileElementId" + "pagination", + "data" ], "properties": { - "fileElementId": { - "type": "integer", - "format": "int64" + "pagination": { + "$ref": "#/components/schemas/Pagination" + }, + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/File" + } } } } @@ -5062,7 +5039,7 @@ } }, "404": { - "description": "Failure when patch visible element", + "description": "No file provided or other problem with provided file", "content": { "application/json": { "schema": { @@ -5084,14 +5061,11 @@ "data": { "type": "object", "required": [ - "errors" + "message" ], "properties": { - "errors": { - "type": "array", - "items": { - "type": "string" - } + "message": { + "type": "string" } } } @@ -5103,13 +5077,14 @@ } } } - }, - "delete": { - "operationId": "file_element-delete", - "summary": "Delete visible element", - "description": "Delete visible element of a specific file", + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/id-docs/approval/list": { + "get": { + "operationId": "id_docs-list-to-approval", + "summary": "List files that need to be approved", "tags": [ - "file_element" + "id_docs" ], "security": [ { @@ -5133,22 +5108,32 @@ } }, { - "name": "uuid", - "in": "path", - "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", - "required": true, + "name": "filter", + "in": "query", + "description": "Filter params", "schema": { - "type": "string" + "type": "string", + "nullable": true } }, { - "name": "elementId", - "in": "path", - "description": "ID of visible element. Each element has an ID that is returned on validation endpoints.", - "required": true, + "name": "page", + "in": "query", + "description": "the number of page to return", "schema": { "type": "integer", - "format": "int64" + "format": "int64", + "nullable": true + } + }, + { + "name": "length", + "in": "query", + "description": "Total of elements to return", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true } }, { @@ -5183,7 +5168,25 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "pagination", + "data" + ], + "properties": { + "pagination": { + "$ref": "#/components/schemas/Pagination" + }, + "data": { + "type": "array", + "nullable": true, + "items": { + "$ref": "#/components/schemas/File" + } + } + } + } } } } @@ -5192,7 +5195,7 @@ } }, "404": { - "description": "Failure when delete visible element or file not found", + "description": "Account not found", "content": { "application/json": { "schema": { @@ -5214,14 +5217,11 @@ "data": { "type": "object", "required": [ - "errors" + "message" ], "properties": { - "errors": { - "type": "array", - "items": { - "type": "string" - } + "message": { + "type": "string" } } } diff --git a/openapi.json b/openapi.json index 7628b2eb79..65483c3efb 100644 --- a/openapi.json +++ b/openapi.json @@ -20,23 +20,6 @@ } }, "schemas": { - "AccountFile": { - "type": "object", - "required": [ - "file" - ], - "properties": { - "file": { - "$ref": "#/components/schemas/NewFile" - }, - "name": { - "type": "string" - }, - "type": { - "type": "string" - } - } - }, "CertificatePfxData": { "type": "object", "required": [ @@ -269,6 +252,23 @@ } } }, + "IdDocs": { + "type": "object", + "required": [ + "file" + ], + "properties": { + "file": { + "$ref": "#/components/schemas/NewFile" + }, + "name": { + "type": "string" + }, + "type": { + "type": "string" + } + } + }, "IdentifyAccount": { "type": "object", "required": [ @@ -1925,43 +1925,20 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/files": { - "post": { - "operationId": "account-add-files", - "summary": "Add files to account profile", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/me": { + "get": { + "operationId": "account-me", + "summary": "Who am I", + "description": "Validates API access data and returns the authenticated user's data.", "tags": [ "account" ], "security": [ - { - "bearer_auth": [] - }, + {}, { "basic_auth": [] } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "files" - ], - "properties": { - "files": { - "type": "array", - "description": "The list of files to add to profile", - "items": { - "$ref": "#/components/schemas/AccountFile" - } - } - } - } - } - } - }, "parameters": [ { "name": "apiVersion", @@ -1988,7 +1965,7 @@ ], "responses": { "200": { - "description": "Certificate saved with success", + "description": "OK", "content": { "application/json": { "schema": { @@ -2007,7 +1984,49 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "account", + "settings" + ], + "properties": { + "account": { + "type": "object", + "required": [ + "uid", + "emailAddress", + "displayName" + ], + "properties": { + "uid": { + "type": "string" + }, + "emailAddress": { + "type": "string" + }, + "displayName": { + "type": "string" + } + } + }, + "settings": { + "type": "object", + "required": [ + "canRequestSign", + "hasSignatureFile" + ], + "properties": { + "canRequestSign": { + "type": "boolean" + }, + "hasSignatureFile": { + "type": "boolean" + } + } + } + } + } } } } @@ -2015,8 +2034,8 @@ } } }, - "401": { - "description": "No file provided or other problem with provided file", + "404": { + "description": "Invalid user or password", "content": { "application/json": { "schema": { @@ -2038,24 +2057,9 @@ "data": { "type": "object", "required": [ - "file", - "type", "message" ], "properties": { - "file": { - "type": "integer", - "format": "int64", - "nullable": true - }, - "type": { - "type": "string", - "enum": [ - "info", - "warning", - "danger" - ] - }, "message": { "type": "string" } @@ -2069,10 +2073,12 @@ } } } - }, - "delete": { - "operationId": "account-delete-file", - "summary": "Delete file from account", + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/settings": { + "patch": { + "operationId": "account-update-settings", + "summary": "Update the account phone number", "tags": [ "account" ], @@ -2084,6 +2090,23 @@ "basic_auth": [] } ], + "requestBody": { + "required": false, + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "phone": { + "type": "string", + "nullable": true, + "description": "the phone number to be defined. If null will remove the phone number" + } + } + } + } + } + }, "parameters": [ { "name": "apiVersion", @@ -2097,16 +2120,6 @@ "default": "v1" } }, - { - "name": "nodeId", - "in": "query", - "description": "the nodeId of file to be delete", - "required": true, - "schema": { - "type": "integer", - "format": "int64" - } - }, { "name": "OCS-APIRequest", "in": "header", @@ -2120,7 +2133,7 @@ ], "responses": { "200": { - "description": "File deleted with success", + "description": "Settings saved", "content": { "application/json": { "schema": { @@ -2139,7 +2152,33 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "data" + ], + "properties": { + "data": { + "type": "object", + "required": [ + "userId", + "phone", + "message" + ], + "properties": { + "userId": { + "type": "string" + }, + "phone": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } + } + } } } } @@ -2147,8 +2186,8 @@ } } }, - "401": { - "description": "Failure to delete file from account", + "404": { + "description": "Invalid data to update phone number", "content": { "application/json": { "schema": { @@ -2170,14 +2209,11 @@ "data": { "type": "object", "required": [ - "messages" + "message" ], "properties": { - "messages": { - "type": "array", - "items": { - "type": "string" - } + "message": { + "type": "string" } } } @@ -2189,10 +2225,12 @@ } } } - }, - "get": { - "operationId": "account-account-file-list-to-owner", - "summary": "List account files of authenticated account", + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/pfx": { + "delete": { + "operationId": "account-delete-pfx", + "summary": "Delete PFX file", "tags": [ "account" ], @@ -2217,35 +2255,6 @@ "default": "v1" } }, - { - "name": "filter", - "in": "query", - "description": "Filter params", - "schema": { - "type": "string", - "nullable": true - } - }, - { - "name": "page", - "in": "query", - "description": "the number of page to return", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "length", - "in": "query", - "description": "Total of elements to return", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, { "name": "OCS-APIRequest", "in": "header", @@ -2258,8 +2267,8 @@ } ], "responses": { - "200": { - "description": "Certificate saved with success", + "202": { + "description": "Certificate deleted with success", "content": { "application/json": { "schema": { @@ -2281,52 +2290,7 @@ "data": { "type": "object", "required": [ - "pagination", - "data" - ], - "properties": { - "pagination": { - "$ref": "#/components/schemas/Pagination" - }, - "data": { - "type": "array", - "items": { - "$ref": "#/components/schemas/File" - } - } - } - } - } - } - } - } - } - } - }, - "404": { - "description": "No file provided or other problem with provided file", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": { - "type": "object", - "required": [ - "message" + "message" ], "properties": { "message": { @@ -2342,18 +2306,17 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/me": { - "get": { - "operationId": "account-me", - "summary": "Who am I", - "description": "Validates API access data and returns the authenticated user's data.", + }, + "post": { + "operationId": "account-upload-pfx", + "summary": "Upload PFX file", "tags": [ "account" ], "security": [ - {}, + { + "bearer_auth": [] + }, { "basic_auth": [] } @@ -2383,8 +2346,8 @@ } ], "responses": { - "200": { - "description": "OK", + "202": { + "description": "Certificate saved with success", "content": { "application/json": { "schema": { @@ -2406,43 +2369,11 @@ "data": { "type": "object", "required": [ - "account", - "settings" + "message" ], "properties": { - "account": { - "type": "object", - "required": [ - "uid", - "emailAddress", - "displayName" - ], - "properties": { - "uid": { - "type": "string" - }, - "emailAddress": { - "type": "string" - }, - "displayName": { - "type": "string" - } - } - }, - "settings": { - "type": "object", - "required": [ - "canRequestSign", - "hasSignatureFile" - ], - "properties": { - "canRequestSign": { - "type": "boolean" - }, - "hasSignatureFile": { - "type": "boolean" - } - } + "message": { + "type": "string" } } } @@ -2453,8 +2384,8 @@ } } }, - "404": { - "description": "Invalid user or password", + "400": { + "description": "No file provided or other problem with provided file", "content": { "application/json": { "schema": { @@ -2492,12 +2423,11 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/files/approval/list": { - "get": { - "operationId": "account-account-file-list-to-approval", - "summary": "List account files that need to be approved", + }, + "patch": { + "operationId": "account-update-pfx-password", + "summary": "Update PFX file", + "description": "Used to change the password of PFX file", "tags": [ "account" ], @@ -2509,6 +2439,30 @@ "basic_auth": [] } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "current", + "new" + ], + "properties": { + "current": { + "type": "string", + "description": "Current password" + }, + "new": { + "type": "string", + "description": "New password" + } + } + } + } + } + }, "parameters": [ { "name": "apiVersion", @@ -2522,35 +2476,6 @@ "default": "v1" } }, - { - "name": "filter", - "in": "query", - "description": "Filter params", - "schema": { - "type": "string", - "nullable": true - } - }, - { - "name": "page", - "in": "query", - "description": "the number of page to return", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "length", - "in": "query", - "description": "Total of elements to return", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, { "name": "OCS-APIRequest", "in": "header", @@ -2563,8 +2488,8 @@ } ], "responses": { - "200": { - "description": "OK", + "202": { + "description": "Certificate saved with success", "content": { "application/json": { "schema": { @@ -2586,19 +2511,11 @@ "data": { "type": "object", "required": [ - "pagination", - "data" + "message" ], "properties": { - "pagination": { - "$ref": "#/components/schemas/Pagination" - }, - "data": { - "type": "array", - "nullable": true, - "items": { - "$ref": "#/components/schemas/File" - } + "message": { + "type": "string" } } } @@ -2609,8 +2526,8 @@ } } }, - "404": { - "description": "Account not found", + "400": { + "description": "No file provided or other problem with provided file", "content": { "application/json": { "schema": { @@ -2650,10 +2567,10 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/settings": { - "patch": { - "operationId": "account-update-settings", - "summary": "Update the account phone number", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/pfx/read": { + "post": { + "operationId": "account-read-pfx-data", + "summary": "Read content of PFX file", "tags": [ "account" ], @@ -2666,16 +2583,18 @@ } ], "requestBody": { - "required": false, + "required": true, "content": { "application/json": { "schema": { "type": "object", + "required": [ + "password" + ], "properties": { - "phone": { + "password": { "type": "string", - "nullable": true, - "description": "the phone number to be defined. If null will remove the phone number" + "description": "password of PFX file to decrypt the file and return his content" } } } @@ -2707,8 +2626,8 @@ } ], "responses": { - "200": { - "description": "Settings saved", + "202": { + "description": "Certificate saved with success", "content": { "application/json": { "schema": { @@ -2728,31 +2647,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "type": "object", - "required": [ - "data" - ], - "properties": { - "data": { - "type": "object", - "required": [ - "userId", - "phone", - "message" - ], - "properties": { - "userId": { - "type": "string" - }, - "phone": { - "type": "string" - }, - "message": { - "type": "string" - } - } - } - } + "$ref": "#/components/schemas/CertificatePfxData" } } } @@ -2761,8 +2656,8 @@ } } }, - "404": { - "description": "Invalid data to update phone number", + "400": { + "description": "No file provided or other problem with provided file", "content": { "application/json": { "schema": { @@ -2802,14 +2697,16 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/pfx": { - "delete": { - "operationId": "account-delete-pfx", - "summary": "Delete PFX file", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate/uuid/{uuid}": { + "get": { + "operationId": "file-validate-uuid", + "summary": "Validate a file using Uuid", + "description": "Validate a file returning file data.", "tags": [ - "account" + "file" ], "security": [ + {}, { "bearer_auth": [] }, @@ -2831,82 +2728,12 @@ } }, { - "name": "OCS-APIRequest", - "in": "header", - "description": "Required to be true for the API request to pass", + "name": "uuid", + "in": "path", + "description": "The UUID of the LibreSign file", "required": true, "schema": { - "type": "boolean", - "default": true - } - } - ], - "responses": { - "202": { - "description": "Certificate deleted with success", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": { - "type": "object", - "required": [ - "message" - ], - "properties": { - "message": { - "type": "string" - } - } - } - } - } - } - } - } - } - } - } - }, - "post": { - "operationId": "account-upload-pfx", - "summary": "Upload PFX file", - "tags": [ - "account" - ], - "security": [ - { - "bearer_auth": [] - }, - { - "basic_auth": [] - } - ], - "parameters": [ - { - "name": "apiVersion", - "in": "path", - "required": true, - "schema": { - "type": "string", - "enum": [ - "v1" - ], - "default": "v1" + "type": "string" } }, { @@ -2921,8 +2748,8 @@ } ], "responses": { - "202": { - "description": "Certificate saved with success", + "200": { + "description": "OK", "content": { "application/json": { "schema": { @@ -2942,15 +2769,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "type": "object", - "required": [ - "message" - ], - "properties": { - "message": { - "type": "string" - } - } + "$ref": "#/components/schemas/ValidateFile" } } } @@ -2959,8 +2778,8 @@ } } }, - "400": { - "description": "No file provided or other problem with provided file", + "404": { + "description": "Request failed", "content": { "application/json": { "schema": { @@ -2982,11 +2801,37 @@ "data": { "type": "object", "required": [ - "message" + "action", + "errors" ], "properties": { - "message": { - "type": "string" + "action": { + "type": "integer", + "format": "int64" + }, + "errors": { + "type": "array", + "items": { + "type": "string" + } + }, + "messages": { + "type": "array", + "items": { + "type": "object", + "required": [ + "type", + "message" + ], + "properties": { + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } } } } @@ -2998,15 +2843,18 @@ } } } - }, - "patch": { - "operationId": "account-update-pfx-password", - "summary": "Update PFX file", - "description": "Used to change the password of PFX file", + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate/file_id/{fileId}": { + "get": { + "operationId": "file-validate-file-id", + "summary": "Validate a file using FileId", + "description": "Validate a file returning file data.", "tags": [ - "account" + "file" ], "security": [ + {}, { "bearer_auth": [] }, @@ -3014,30 +2862,6 @@ "basic_auth": [] } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "current", - "new" - ], - "properties": { - "current": { - "type": "string", - "description": "Current password" - }, - "new": { - "type": "string", - "description": "New password" - } - } - } - } - } - }, "parameters": [ { "name": "apiVersion", @@ -3051,6 +2875,16 @@ "default": "v1" } }, + { + "name": "fileId", + "in": "path", + "description": "The identifier value of the LibreSign file", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + }, { "name": "OCS-APIRequest", "in": "header", @@ -3063,8 +2897,8 @@ } ], "responses": { - "202": { - "description": "Certificate saved with success", + "200": { + "description": "OK", "content": { "application/json": { "schema": { @@ -3084,15 +2918,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "type": "object", - "required": [ - "message" - ], - "properties": { - "message": { - "type": "string" - } - } + "$ref": "#/components/schemas/ValidateFile" } } } @@ -3101,8 +2927,8 @@ } } }, - "400": { - "description": "No file provided or other problem with provided file", + "404": { + "description": "Request failed", "content": { "application/json": { "schema": { @@ -3124,11 +2950,37 @@ "data": { "type": "object", "required": [ - "message" + "action", + "errors" ], "properties": { - "message": { - "type": "string" + "action": { + "type": "integer", + "format": "int64" + }, + "errors": { + "type": "array", + "items": { + "type": "string" + } + }, + "messages": { + "type": "array", + "items": { + "type": "object", + "required": [ + "type", + "message" + ], + "properties": { + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } } } } @@ -3142,14 +2994,16 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/pfx/read": { + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate": { "post": { - "operationId": "account-read-pfx-data", - "summary": "Read content of PFX file", + "operationId": "file-validate-binary", + "summary": "Validate a binary file", + "description": "Validate a binary file returning file data. Use field 'file' for the file upload", "tags": [ - "account" + "file" ], "security": [ + {}, { "bearer_auth": [] }, @@ -3157,25 +3011,6 @@ "basic_auth": [] } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "password" - ], - "properties": { - "password": { - "type": "string", - "description": "password of PFX file to decrypt the file and return his content" - } - } - } - } - } - }, "parameters": [ { "name": "apiVersion", @@ -3201,8 +3036,8 @@ } ], "responses": { - "202": { - "description": "Certificate saved with success", + "200": { + "description": "OK", "content": { "application/json": { "schema": { @@ -3222,7 +3057,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/CertificatePfxData" + "$ref": "#/components/schemas/ValidateFile" } } } @@ -3231,8 +3066,8 @@ } } }, - "400": { - "description": "No file provided or other problem with provided file", + "404": { + "description": "Request failed", "content": { "application/json": { "schema": { @@ -3254,11 +3089,37 @@ "data": { "type": "object", "required": [ - "message" + "action", + "errors" ], "properties": { - "message": { - "type": "string" + "action": { + "type": "integer", + "format": "int64" + }, + "errors": { + "type": "array", + "items": { + "type": "string" + } + }, + "messages": { + "type": "array", + "items": { + "type": "object", + "required": [ + "type", + "message" + ], + "properties": { + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + } + } } } } @@ -3268,92 +3129,8 @@ } } } - } - } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate/uuid/{uuid}": { - "get": { - "operationId": "file-validate-uuid", - "summary": "Validate a file using Uuid", - "description": "Validate a file returning file data.", - "tags": [ - "file" - ], - "security": [ - {}, - { - "bearer_auth": [] - }, - { - "basic_auth": [] - } - ], - "parameters": [ - { - "name": "apiVersion", - "in": "path", - "required": true, - "schema": { - "type": "string", - "enum": [ - "v1" - ], - "default": "v1" - } - }, - { - "name": "uuid", - "in": "path", - "description": "The UUID of the LibreSign file", - "required": true, - "schema": { - "type": "string" - } - }, - { - "name": "OCS-APIRequest", - "in": "header", - "description": "Required to be true for the API request to pass", - "required": true, - "schema": { - "type": "boolean", - "default": true - } - } - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": { - "$ref": "#/components/schemas/ValidateFile" - } - } - } - } - } - } - } }, - "404": { + "400": { "description": "Request failed", "content": { "application/json": { @@ -3418,12 +3195,10 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate/file_id/{fileId}": { + }, "get": { - "operationId": "file-validate-file-id", - "summary": "Validate a file using FileId", + "operationId": "file-validate", + "summary": "Validate a file", "description": "Validate a file returning file data.", "tags": [ "file" @@ -3451,13 +3226,28 @@ } }, { - "name": "fileId", - "in": "path", - "description": "The identifier value of the LibreSign file", - "required": true, + "name": "type", + "in": "query", + "description": "The type of identifier could be Uuid or FileId", "schema": { - "type": "integer", - "format": "int64" + "type": "string", + "nullable": true + } + }, + { + "name": "identifier", + "in": "query", + "description": "The identifier value, could be string or integer, if UUID will be a string, if FileId will be an integer", + "schema": { + "oneOf": [ + { + "type": "string" + }, + { + "type": "integer", + "format": "int64" + } + ] } }, { @@ -3569,16 +3359,14 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate": { - "post": { - "operationId": "file-validate-binary", - "summary": "Validate a binary file", - "description": "Validate a binary file returning file data. Use field 'file' for the file upload", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/list": { + "get": { + "operationId": "file-list", + "summary": "List account files that need to be approved", "tags": [ "file" ], "security": [ - {}, { "bearer_auth": [] }, @@ -3599,6 +3387,95 @@ "default": "v1" } }, + { + "name": "page", + "in": "query", + "description": "the number of page to return", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "length", + "in": "query", + "description": "Total of elements to return", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "signer_uuid", + "in": "query", + "description": "Signer UUID", + "schema": { + "type": "string", + "nullable": true + } + }, + { + "name": "nodeId", + "in": "query", + "description": "The nodeId (also called fileId). Is the id of a file at Nextcloud", + "schema": { + "type": "string", + "nullable": true + } + }, + { + "name": "status[]", + "in": "query", + "description": "Status could be none or many of 0 = draft, 1 = able to sign, 2 = partial signed, 3 = signed, 4 = deleted.", + "schema": { + "type": "array", + "nullable": true, + "items": { + "type": "integer", + "format": "int64" + } + } + }, + { + "name": "start", + "in": "query", + "description": "Start date of signature request (UNIX timestamp)", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "end", + "in": "query", + "description": "End date of signature request (UNIX timestamp)", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "sortBy", + "in": "query", + "description": "Name of the column to sort by", + "schema": { + "type": "string", + "nullable": true + } + }, + { + "name": "sortDirection", + "in": "query", + "description": "Ascending or descending order", + "schema": { + "type": "string", + "nullable": true + } + }, { "name": "OCS-APIRequest", "in": "header", @@ -3632,7 +3509,23 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/ValidateFile" + "type": "object", + "required": [ + "pagination", + "data" + ], + "properties": { + "pagination": { + "$ref": "#/components/schemas/Pagination" + }, + "data": { + "type": "array", + "nullable": true, + "items": { + "$ref": "#/components/schemas/File" + } + } + } } } } @@ -3640,9 +3533,142 @@ } } } + } + } + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/thumbnail/{nodeId}": { + "get": { + "operationId": "file-get-thumbnail", + "summary": "Return the thumbnail of a LibreSign file", + "tags": [ + "file" + ], + "security": [ + { + "bearer_auth": [] }, - "404": { - "description": "Request failed", + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "apiVersion", + "in": "path", + "required": true, + "schema": { + "type": "string", + "enum": [ + "v1" + ], + "default": "v1" + } + }, + { + "name": "nodeId", + "in": "path", + "description": "The nodeId of document", + "required": true, + "schema": { + "type": "integer", + "format": "int64", + "default": -1 + } + }, + { + "name": "x", + "in": "query", + "description": "Width of generated file", + "schema": { + "type": "integer", + "format": "int64", + "default": 32 + } + }, + { + "name": "y", + "in": "query", + "description": "Height of generated file", + "schema": { + "type": "integer", + "format": "int64", + "default": 32 + } + }, + { + "name": "a", + "in": "query", + "description": "Crop, boolean value, default false", + "schema": { + "type": "integer", + "default": 0, + "enum": [ + 0, + 1 + ] + } + }, + { + "name": "forceIcon", + "in": "query", + "description": "Force to generate a new thumbnail", + "schema": { + "type": "integer", + "default": 1, + "enum": [ + 0, + 1 + ] + } + }, + { + "name": "mode", + "in": "query", + "description": "To force a given mimetype for the file", + "schema": { + "type": "string", + "default": "fill" + } + }, + { + "name": "mimeFallback", + "in": "query", + "description": "If we have no preview enabled, we can redirect to the mime icon if any", + "schema": { + "type": "integer", + "default": 0, + "enum": [ + 0, + 1 + ] + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "*/*": { + "schema": { + "type": "string", + "format": "binary" + } + } + } + }, + "400": { + "description": "Bad request", "content": { "application/json": { "schema": { @@ -3661,43 +3687,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "object", - "required": [ - "action", - "errors" - ], - "properties": { - "action": { - "type": "integer", - "format": "int64" - }, - "errors": { - "type": "array", - "items": { - "type": "string" - } - }, - "messages": { - "type": "array", - "items": { - "type": "object", - "required": [ - "type", - "message" - ], - "properties": { - "type": { - "type": "string" - }, - "message": { - "type": "string" - } - } - } - } - } - } + "data": {} } } } @@ -3705,8 +3695,8 @@ } } }, - "400": { - "description": "Request failed", + "403": { + "description": "Forbidden", "content": { "application/json": { "schema": { @@ -3725,61 +3715,64 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "object", - "required": [ - "action", - "errors" - ], - "properties": { - "action": { - "type": "integer", - "format": "int64" - }, - "errors": { - "type": "array", - "items": { - "type": "string" - } - }, - "messages": { - "type": "array", - "items": { - "type": "object", - "required": [ - "type", - "message" - ], - "properties": { - "type": { - "type": "string" - }, - "message": { - "type": "string" - } - } - } - } - } - } + "data": {} + } + } + } + } + } + } + }, + "404": { + "description": "Not found", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} } } } } } } + }, + "303": { + "description": "Redirect", + "headers": { + "Location": { + "schema": { + "type": "string" + } + } + } } } - }, - "get": { - "operationId": "file-validate", - "summary": "Validate a file", - "description": "Validate a file returning file data.", + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file": { + "post": { + "operationId": "file-save", + "summary": "Send a file", + "description": "Send a new file to Nextcloud and return the fileId to request to sign usign fileId", "tags": [ "file" ], "security": [ - {}, { "bearer_auth": [] }, @@ -3787,6 +3780,35 @@ "basic_auth": [] } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "file" + ], + "properties": { + "file": { + "$ref": "#/components/schemas/NewFile", + "description": "File to save" + }, + "name": { + "type": "string", + "default": "", + "description": "The name of file to sign" + }, + "settings": { + "$ref": "#/components/schemas/FolderSettings", + "default": [], + "description": "Settings to define the pattern to store the file. See more informations at FolderService::getFolderName method." + } + } + } + } + } + }, "parameters": [ { "name": "apiVersion", @@ -3800,31 +3822,6 @@ "default": "v1" } }, - { - "name": "type", - "in": "query", - "description": "The type of identifier could be Uuid or FileId", - "schema": { - "type": "string", - "nullable": true - } - }, - { - "name": "identifier", - "in": "query", - "description": "The identifier value, could be string or integer, if UUID will be a string, if FileId will be an integer", - "schema": { - "oneOf": [ - { - "type": "string" - }, - { - "type": "integer", - "format": "int64" - } - ] - } - }, { "name": "OCS-APIRequest", "in": "header", @@ -3858,7 +3855,7 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/ValidateFile" + "$ref": "#/components/schemas/NextcloudFile" } } } @@ -3867,8 +3864,8 @@ } } }, - "404": { - "description": "Request failed", + "422": { + "description": "Failed to save data", "content": { "application/json": { "schema": { @@ -3890,37 +3887,11 @@ "data": { "type": "object", "required": [ - "action", - "errors" + "message" ], "properties": { - "action": { - "type": "integer", - "format": "int64" - }, - "errors": { - "type": "array", - "items": { - "type": "string" - } - }, - "messages": { - "type": "array", - "items": { - "type": "object", - "required": [ - "type", - "message" - ], - "properties": { - "type": { - "type": "string" - }, - "message": { - "type": "string" - } - } - } + "message": { + "type": "string" } } } @@ -3934,10 +3905,11 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/list": { - "get": { - "operationId": "file-list", - "summary": "List account files that need to be approved", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/file_id/{fileId}": { + "delete": { + "operationId": "file-delete-all-request-signature-using-file-id", + "summary": "Delete File", + "description": "This will delete the file and all data", "tags": [ "file" ], @@ -3963,108 +3935,105 @@ } }, { - "name": "page", - "in": "query", - "description": "the number of page to return", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "length", - "in": "query", - "description": "Total of elements to return", + "name": "fileId", + "in": "path", + "description": "Node id of a Nextcloud file", + "required": true, "schema": { "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "signer_uuid", - "in": "query", - "description": "Signer UUID", - "schema": { - "type": "string", - "nullable": true + "format": "int64" } }, { - "name": "nodeId", - "in": "query", - "description": "The nodeId (also called fileId). Is the id of a file at Nextcloud", + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, "schema": { - "type": "string", - "nullable": true + "type": "boolean", + "default": true } - }, - { - "name": "status[]", - "in": "query", - "description": "Status could be none or many of 0 = draft, 1 = able to sign, 2 = partial signed, 3 = signed, 4 = deleted.", - "schema": { - "type": "array", - "nullable": true, - "items": { - "type": "integer", - "format": "int64" + } + ], + "responses": { + "200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } } } }, - { - "name": "start", - "in": "query", - "description": "Start date of signature request (UNIX timestamp)", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "end", - "in": "query", - "description": "End date of signature request (UNIX timestamp)", - "schema": { - "type": "integer", - "format": "int64", - "nullable": true - } - }, - { - "name": "sortBy", - "in": "query", - "description": "Name of the column to sort by", - "schema": { - "type": "string", - "nullable": true - } - }, - { - "name": "sortDirection", - "in": "query", - "description": "Ascending or descending order", - "schema": { - "type": "string", - "nullable": true + "401": { + "description": "Failed", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } + } } }, - { - "name": "OCS-APIRequest", - "in": "header", - "description": "Required to be true for the API request to pass", - "required": true, - "schema": { - "type": "boolean", - "default": true - } - } - ], - "responses": { - "200": { - "description": "OK", + "422": { + "description": "Failed", "content": { "application/json": { "schema": { @@ -4086,18 +4055,18 @@ "data": { "type": "object", "required": [ - "pagination", - "data" + "action", + "errors" ], "properties": { - "pagination": { - "$ref": "#/components/schemas/Pagination" + "action": { + "type": "integer", + "format": "int64" }, - "data": { + "errors": { "type": "array", - "nullable": true, "items": { - "$ref": "#/components/schemas/File" + "type": "string" } } } @@ -4112,12 +4081,13 @@ } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/thumbnail/{nodeId}": { - "get": { - "operationId": "file-get-thumbnail", - "summary": "Return the thumbnail of a LibreSign file", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file-element/{uuid}": { + "post": { + "operationId": "file_element-post", + "summary": "Create visible element", + "description": "Create visible element of a specific file", "tags": [ - "file" + "file_element" ], "security": [ { @@ -4127,6 +4097,47 @@ "basic_auth": [] } ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "signRequestId" + ], + "properties": { + "signRequestId": { + "type": "integer", + "format": "int64", + "description": "Id of sign request" + }, + "elementId": { + "type": "integer", + "format": "int64", + "nullable": true, + "description": "ID of visible element. Each element has an ID that is returned on validation endpoints." + }, + "type": { + "type": "string", + "default": "", + "description": "The type of element to create, sginature, sinitial, date, datetime, text" + }, + "metadata": { + "type": "object", + "default": {}, + "description": "Metadata of visible elements to associate with the document" + }, + "coordinates": { + "$ref": "#/components/schemas/Coordinate", + "default": [], + "description": "Coortinates of a visible element on PDF" + } + } + } + } + } + }, "parameters": [ { "name": "apiVersion", @@ -4141,82 +4152,12 @@ } }, { - "name": "nodeId", + "name": "uuid", "in": "path", - "description": "The nodeId of document", + "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", "required": true, "schema": { - "type": "integer", - "format": "int64", - "default": -1 - } - }, - { - "name": "x", - "in": "query", - "description": "Width of generated file", - "schema": { - "type": "integer", - "format": "int64", - "default": 32 - } - }, - { - "name": "y", - "in": "query", - "description": "Height of generated file", - "schema": { - "type": "integer", - "format": "int64", - "default": 32 - } - }, - { - "name": "a", - "in": "query", - "description": "Crop, boolean value, default false", - "schema": { - "type": "integer", - "default": 0, - "enum": [ - 0, - 1 - ] - } - }, - { - "name": "forceIcon", - "in": "query", - "description": "Force to generate a new thumbnail", - "schema": { - "type": "integer", - "default": 1, - "enum": [ - 0, - 1 - ] - } - }, - { - "name": "mode", - "in": "query", - "description": "To force a given mimetype for the file", - "schema": { - "type": "string", - "default": "fill" - } - }, - { - "name": "mimeFallback", - "in": "query", - "description": "If we have no preview enabled, we can redirect to the mime icon if any", - "schema": { - "type": "integer", - "default": 0, - "enum": [ - 0, - 1 - ] + "type": "string" } }, { @@ -4233,45 +4174,6 @@ "responses": { "200": { "description": "OK", - "content": { - "*/*": { - "schema": { - "type": "string", - "format": "binary" - } - } - } - }, - "400": { - "description": "Bad request", - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "ocs" - ], - "properties": { - "ocs": { - "type": "object", - "required": [ - "meta", - "data" - ], - "properties": { - "meta": { - "$ref": "#/components/schemas/OCSMeta" - }, - "data": {} - } - } - } - } - } - } - }, - "403": { - "description": "Forbidden", "content": { "application/json": { "schema": { @@ -4290,7 +4192,18 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "fileElementId" + ], + "properties": { + "fileElementId": { + "type": "integer", + "format": "int64" + } + } + } } } } @@ -4299,7 +4212,7 @@ } }, "404": { - "description": "Not found", + "description": "Failure when create visible element", "content": { "application/json": { "schema": { @@ -4318,34 +4231,37 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "errors" + ], + "properties": { + "errors": { + "type": "array", + "items": { + "type": "string" + } + } + } + } } } } } } } - }, - "303": { - "description": "Redirect", - "headers": { - "Location": { - "schema": { - "type": "string" - } - } - } } } } }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file": { - "post": { - "operationId": "file-save", - "summary": "Send a file", - "description": "Send a new file to Nextcloud and return the fileId to request to sign usign fileId", + "/ocs/v2.php/apps/libresign/api/{apiVersion}/file-element/{uuid}/{elementId}": { + "patch": { + "operationId": "file_element-patch", + "summary": "Update visible element", + "description": "Update visible element of a specific file", "tags": [ - "file" + "file_element" ], "security": [ { @@ -4362,22 +4278,28 @@ "schema": { "type": "object", "required": [ - "file" + "signRequestId" ], "properties": { - "file": { - "$ref": "#/components/schemas/NewFile", - "description": "File to save" + "signRequestId": { + "type": "integer", + "format": "int64", + "description": "Id of sign request" }, - "name": { + "type": { "type": "string", "default": "", - "description": "The name of file to sign" + "description": "The type of element to create, sginature, sinitial, date, datetime, text" }, - "settings": { - "$ref": "#/components/schemas/FolderSettings", + "metadata": { + "type": "object", + "default": {}, + "description": "Metadata of visible elements to associate with the document" + }, + "coordinates": { + "$ref": "#/components/schemas/Coordinate", "default": [], - "description": "Settings to define the pattern to store the file. See more informations at FolderService::getFolderName method." + "description": "Coortinates of a visible element on PDF" } } } @@ -4397,6 +4319,26 @@ "default": "v1" } }, + { + "name": "uuid", + "in": "path", + "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "elementId", + "in": "path", + "description": "ID of visible element. Each element has an ID that is returned on validation endpoints.", + "required": true, + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, { "name": "OCS-APIRequest", "in": "header", @@ -4430,7 +4372,16 @@ "$ref": "#/components/schemas/OCSMeta" }, "data": { - "$ref": "#/components/schemas/NextcloudFile" + "type": "object", + "required": [ + "fileElementId" + ], + "properties": { + "fileElementId": { + "type": "integer", + "format": "int64" + } + } } } } @@ -4439,8 +4390,8 @@ } } }, - "422": { - "description": "Failed to save data", + "404": { + "description": "Failure when patch visible element", "content": { "application/json": { "schema": { @@ -4462,11 +4413,14 @@ "data": { "type": "object", "required": [ - "message" + "errors" ], "properties": { - "message": { - "type": "string" + "errors": { + "type": "array", + "items": { + "type": "string" + } } } } @@ -4478,15 +4432,13 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file/file_id/{fileId}": { + }, "delete": { - "operationId": "file-delete-all-request-signature-using-file-id", - "summary": "Delete File", - "description": "This will delete the file and all data", + "operationId": "file_element-delete", + "summary": "Delete visible element", + "description": "Delete visible element of a specific file", "tags": [ - "file" + "file_element" ], "security": [ { @@ -4510,9 +4462,18 @@ } }, { - "name": "fileId", + "name": "uuid", "in": "path", - "description": "Node id of a Nextcloud file", + "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "elementId", + "in": "path", + "description": "ID of visible element. Each element has an ID that is returned on validation endpoints.", "required": true, "schema": { "type": "integer", @@ -4551,17 +4512,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "object", - "required": [ - "message" - ], - "properties": { - "message": { - "type": "string" - } - } - } + "data": {} } } } @@ -4569,8 +4520,8 @@ } } }, - "401": { - "description": "Failed", + "404": { + "description": "Failure when delete visible element or file not found", "content": { "application/json": { "schema": { @@ -4592,11 +4543,14 @@ "data": { "type": "object", "required": [ - "message" + "errors" ], "properties": { - "message": { - "type": "string" + "errors": { + "type": "array", + "items": { + "type": "string" + } } } } @@ -4606,9 +4560,102 @@ } } } + } + } + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/id-docs": { + "post": { + "operationId": "id_docs-add-files", + "summary": "Add files to account profile", + "tags": [ + "id_docs" + ], + "security": [ + { + "bearer_auth": [] }, - "422": { - "description": "Failed", + { + "basic_auth": [] + } + ], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "files" + ], + "properties": { + "files": { + "type": "array", + "description": "The list of files to add to profile", + "items": { + "$ref": "#/components/schemas/IdDocs" + } + } + } + } + } + } + }, + "parameters": [ + { + "name": "apiVersion", + "in": "path", + "required": true, + "schema": { + "type": "string", + "enum": [ + "v1" + ], + "default": "v1" + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "Certificate saved with success", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": {} + } + } + } + } + } + } + }, + "401": { + "description": "No file provided or other problem with provided file", "content": { "application/json": { "schema": { @@ -4630,19 +4677,26 @@ "data": { "type": "object", "required": [ - "action", - "errors" + "file", + "type", + "message" ], "properties": { - "action": { + "file": { "type": "integer", - "format": "int64" + "format": "int64", + "nullable": true }, - "errors": { - "type": "array", - "items": { - "type": "string" - } + "type": { + "type": "string", + "enum": [ + "info", + "warning", + "danger" + ] + }, + "message": { + "type": "string" } } } @@ -4654,15 +4708,12 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file-element/{uuid}": { - "post": { - "operationId": "file_element-post", - "summary": "Create visible element", - "description": "Create visible element of a specific file", + }, + "delete": { + "operationId": "id_docs-delete-file", + "summary": "Delete file from account", "tags": [ - "file_element" + "id_docs" ], "security": [ { @@ -4672,47 +4723,6 @@ "basic_auth": [] } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "signRequestId" - ], - "properties": { - "signRequestId": { - "type": "integer", - "format": "int64", - "description": "Id of sign request" - }, - "elementId": { - "type": "integer", - "format": "int64", - "nullable": true, - "description": "ID of visible element. Each element has an ID that is returned on validation endpoints." - }, - "type": { - "type": "string", - "default": "", - "description": "The type of element to create, sginature, sinitial, date, datetime, text" - }, - "metadata": { - "type": "object", - "default": {}, - "description": "Metadata of visible elements to associate with the document" - }, - "coordinates": { - "$ref": "#/components/schemas/Coordinate", - "default": [], - "description": "Coortinates of a visible element on PDF" - } - } - } - } - } - }, "parameters": [ { "name": "apiVersion", @@ -4727,12 +4737,13 @@ } }, { - "name": "uuid", - "in": "path", - "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", + "name": "nodeId", + "in": "query", + "description": "the nodeId of file to be delete", "required": true, "schema": { - "type": "string" + "type": "integer", + "format": "int64" } }, { @@ -4748,7 +4759,7 @@ ], "responses": { "200": { - "description": "OK", + "description": "File deleted with success", "content": { "application/json": { "schema": { @@ -4767,18 +4778,7 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": { - "type": "object", - "required": [ - "fileElementId" - ], - "properties": { - "fileElementId": { - "type": "integer", - "format": "int64" - } - } - } + "data": {} } } } @@ -4786,8 +4786,8 @@ } } }, - "404": { - "description": "Failure when create visible element", + "401": { + "description": "Failure to delete file from account", "content": { "application/json": { "schema": { @@ -4809,10 +4809,10 @@ "data": { "type": "object", "required": [ - "errors" + "messages" ], "properties": { - "errors": { + "messages": { "type": "array", "items": { "type": "string" @@ -4828,15 +4828,12 @@ } } } - } - }, - "/ocs/v2.php/apps/libresign/api/{apiVersion}/file-element/{uuid}/{elementId}": { - "patch": { - "operationId": "file_element-patch", - "summary": "Update visible element", - "description": "Update visible element of a specific file", + }, + "get": { + "operationId": "id_docs-list-to-owner", + "summary": "List files of authenticated account", "tags": [ - "file_element" + "id_docs" ], "security": [ { @@ -4846,41 +4843,6 @@ "basic_auth": [] } ], - "requestBody": { - "required": true, - "content": { - "application/json": { - "schema": { - "type": "object", - "required": [ - "signRequestId" - ], - "properties": { - "signRequestId": { - "type": "integer", - "format": "int64", - "description": "Id of sign request" - }, - "type": { - "type": "string", - "default": "", - "description": "The type of element to create, sginature, sinitial, date, datetime, text" - }, - "metadata": { - "type": "object", - "default": {}, - "description": "Metadata of visible elements to associate with the document" - }, - "coordinates": { - "$ref": "#/components/schemas/Coordinate", - "default": [], - "description": "Coortinates of a visible element on PDF" - } - } - } - } - } - }, "parameters": [ { "name": "apiVersion", @@ -4895,19 +4857,28 @@ } }, { - "name": "uuid", - "in": "path", - "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", - "required": true, + "name": "filter", + "in": "query", + "description": "Filter params", "schema": { - "type": "string" + "type": "string", + "nullable": true } }, { - "name": "elementId", - "in": "path", - "description": "ID of visible element. Each element has an ID that is returned on validation endpoints.", - "required": true, + "name": "page", + "in": "query", + "description": "the number of page to return", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true + } + }, + { + "name": "length", + "in": "query", + "description": "Total of elements to return", "schema": { "type": "integer", "format": "int64", @@ -4927,7 +4898,7 @@ ], "responses": { "200": { - "description": "OK", + "description": "Certificate saved with success", "content": { "application/json": { "schema": { @@ -4949,12 +4920,18 @@ "data": { "type": "object", "required": [ - "fileElementId" + "pagination", + "data" ], "properties": { - "fileElementId": { - "type": "integer", - "format": "int64" + "pagination": { + "$ref": "#/components/schemas/Pagination" + }, + "data": { + "type": "array", + "items": { + "$ref": "#/components/schemas/File" + } } } } @@ -4966,7 +4943,7 @@ } }, "404": { - "description": "Failure when patch visible element", + "description": "No file provided or other problem with provided file", "content": { "application/json": { "schema": { @@ -4988,14 +4965,11 @@ "data": { "type": "object", "required": [ - "errors" + "message" ], "properties": { - "errors": { - "type": "array", - "items": { - "type": "string" - } + "message": { + "type": "string" } } } @@ -5007,13 +4981,14 @@ } } } - }, - "delete": { - "operationId": "file_element-delete", - "summary": "Delete visible element", - "description": "Delete visible element of a specific file", + } + }, + "/ocs/v2.php/apps/libresign/api/{apiVersion}/id-docs/approval/list": { + "get": { + "operationId": "id_docs-list-to-approval", + "summary": "List files that need to be approved", "tags": [ - "file_element" + "id_docs" ], "security": [ { @@ -5037,22 +5012,32 @@ } }, { - "name": "uuid", - "in": "path", - "description": "UUID of sign request. The signer UUID is what the person receives via email when asked to sign. This is not the file UUID.", - "required": true, + "name": "filter", + "in": "query", + "description": "Filter params", "schema": { - "type": "string" + "type": "string", + "nullable": true } }, { - "name": "elementId", - "in": "path", - "description": "ID of visible element. Each element has an ID that is returned on validation endpoints.", - "required": true, + "name": "page", + "in": "query", + "description": "the number of page to return", "schema": { "type": "integer", - "format": "int64" + "format": "int64", + "nullable": true + } + }, + { + "name": "length", + "in": "query", + "description": "Total of elements to return", + "schema": { + "type": "integer", + "format": "int64", + "nullable": true } }, { @@ -5087,7 +5072,25 @@ "meta": { "$ref": "#/components/schemas/OCSMeta" }, - "data": {} + "data": { + "type": "object", + "required": [ + "pagination", + "data" + ], + "properties": { + "pagination": { + "$ref": "#/components/schemas/Pagination" + }, + "data": { + "type": "array", + "nullable": true, + "items": { + "$ref": "#/components/schemas/File" + } + } + } + } } } } @@ -5096,7 +5099,7 @@ } }, "404": { - "description": "Failure when delete visible element or file not found", + "description": "Account not found", "content": { "application/json": { "schema": { @@ -5118,14 +5121,11 @@ "data": { "type": "object", "required": [ - "errors" + "message" ], "properties": { - "errors": { - "type": "array", - "items": { - "type": "string" - } + "message": { + "type": "string" } } } diff --git a/src/router/router.js b/src/router/router.js index 3bc608854d..75f2a6ef67 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -165,7 +165,7 @@ const router = new Router({ props: true, }, { - path: '/f/account/files/approve/:uuid', + path: '/f/id-docs/approve/:uuid', name: 'AccountFileApprove', component: () => import('../views/SignPDF/SignPDF.vue'), props: true, diff --git a/src/store/identificationDocument.js b/src/store/identificationDocument.js new file mode 100644 index 0000000000..e88b197f18 --- /dev/null +++ b/src/store/identificationDocument.js @@ -0,0 +1,44 @@ +/** + * SPDX-FileCopyrightText: 2025 LibreCode coop and contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +import { defineStore } from 'pinia' + +import { loadState } from '@nextcloud/initial-state' + +export const useIdentificationDocumentStore = function(...args) { + const store = defineStore('identificationDocument', { + state: () => ({ + modal: false, + enabled: loadState('libresign', 'needIdentificationDocuments', false), + waitingApproval: loadState('libresign', 'identificationDocumentsWaitingApproval', false), + }), + actions: { + needIdentificationDocument() { + return this.enabled && !this.waitingApproval + }, + setEnabled(enabled) { + this.enabled = enabled + }, + setWaitingApproval(waitingApproval) { + this.waitingApproval = waitingApproval + }, + showModal() { + this.modal = true + }, + closeModal() { + this.modal = false + }, + }, + }) + + const identificationDocumentStore = store(...args) + + // Make sure we only register the listeners once + if (!identificationDocumentStore._initialized) { + identificationDocumentStore._initialized = true + } + + return identificationDocumentStore +} diff --git a/src/types/openapi/openapi-full.ts b/src/types/openapi/openapi-full.ts index 2836e8d42b..ad40a8b5da 100644 --- a/src/types/openapi/openapi-full.ts +++ b/src/types/openapi/openapi-full.ts @@ -366,25 +366,6 @@ export type paths = { patch?: never; trace?: never; }; - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/files": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - /** List account files of authenticated account */ - get: operations["account-account-file-list-to-owner"]; - put?: never; - /** Add files to account profile */ - post: operations["account-add-files"]; - /** Delete file from account */ - delete: operations["account-delete-file"]; - options?: never; - head?: never; - patch?: never; - trace?: never; - }; "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/me": { parameters: { query?: never; @@ -405,23 +386,6 @@ export type paths = { patch?: never; trace?: never; }; - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/files/approval/list": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - /** List account files that need to be approved */ - get: operations["account-account-file-list-to-approval"]; - put?: never; - post?: never; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; - }; "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/settings": { parameters: { query?: never; @@ -660,6 +624,42 @@ export type paths = { patch: operations["file_element-patch"]; trace?: never; }; + "/ocs/v2.php/apps/libresign/api/{apiVersion}/id-docs": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** List files of authenticated account */ + get: operations["id_docs-list-to-owner"]; + put?: never; + /** Add files to account profile */ + post: operations["id_docs-add-files"]; + /** Delete file from account */ + delete: operations["id_docs-delete-file"]; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + "/ocs/v2.php/apps/libresign/api/{apiVersion}/id-docs/approval/list": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** List files that need to be approved */ + get: operations["id_docs-list-to-approval"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/ocs/v2.php/apps/libresign/api/{apiVersion}/identify-account/search": { parameters: { query?: never; @@ -1045,11 +1045,6 @@ export type paths = { export type webhooks = Record; export type components = { schemas: { - AccountFile: { - file: components["schemas"]["NewFile"]; - name?: string; - type?: string; - }; CertificatePfxData: { name: string; subject: string; @@ -1134,6 +1129,11 @@ export type components = { setting?: string; }; }; + IdDocs: { + file: components["schemas"]["NewFile"]; + name?: string; + type?: string; + }; IdentifyAccount: { /** Format: int64 */ id: number; @@ -1866,168 +1866,6 @@ export interface operations { }; }; }; - "account-account-file-list-to-owner": { - parameters: { - query?: { - /** @description Filter params */ - filter?: string | null; - /** @description the number of page to return */ - page?: number | null; - /** @description Total of elements to return */ - length?: number | null; - }; - header: { - /** @description Required to be true for the API request to pass */ - "OCS-APIRequest": boolean; - }; - path: { - apiVersion: "v1"; - }; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description Certificate saved with success */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - pagination: components["schemas"]["Pagination"]; - data: components["schemas"]["File"][]; - }; - }; - }; - }; - }; - /** @description No file provided or other problem with provided file */ - 404: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - message: string; - }; - }; - }; - }; - }; - }; - }; - "account-add-files": { - parameters: { - query?: never; - header: { - /** @description Required to be true for the API request to pass */ - "OCS-APIRequest": boolean; - }; - path: { - apiVersion: "v1"; - }; - cookie?: never; - }; - requestBody: { - content: { - "application/json": { - /** @description The list of files to add to profile */ - files: components["schemas"]["AccountFile"][]; - }; - }; - }; - responses: { - /** @description Certificate saved with success */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: unknown; - }; - }; - }; - }; - /** @description No file provided or other problem with provided file */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - /** Format: int64 */ - file: number | null; - /** @enum {string} */ - type: "info" | "warning" | "danger"; - message: string; - }; - }; - }; - }; - }; - }; - }; - "account-delete-file": { - parameters: { - query: { - /** @description the nodeId of file to be delete */ - nodeId: number; - }; - header: { - /** @description Required to be true for the API request to pass */ - "OCS-APIRequest": boolean; - }; - path: { - apiVersion: "v1"; - }; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description File deleted with success */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: unknown; - }; - }; - }; - }; - /** @description Failure to delete file from account */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - messages: string[]; - }; - }; - }; - }; - }; - }; - }; "account-me": { parameters: { query?: never; @@ -2084,62 +1922,6 @@ export interface operations { }; }; }; - "account-account-file-list-to-approval": { - parameters: { - query?: { - /** @description Filter params */ - filter?: string | null; - /** @description the number of page to return */ - page?: number | null; - /** @description Total of elements to return */ - length?: number | null; - }; - header: { - /** @description Required to be true for the API request to pass */ - "OCS-APIRequest": boolean; - }; - path: { - apiVersion: "v1"; - }; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description OK */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - pagination: components["schemas"]["Pagination"]; - data: components["schemas"]["File"][] | null; - }; - }; - }; - }; - }; - /** @description Account not found */ - 404: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - message: string; - }; - }; - }; - }; - }; - }; - }; "account-update-settings": { parameters: { query?: never; @@ -3110,6 +2892,224 @@ export interface operations { }; }; }; + "id_docs-list-to-owner": { + parameters: { + query?: { + /** @description Filter params */ + filter?: string | null; + /** @description the number of page to return */ + page?: number | null; + /** @description Total of elements to return */ + length?: number | null; + }; + header: { + /** @description Required to be true for the API request to pass */ + "OCS-APIRequest": boolean; + }; + path: { + apiVersion: "v1"; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Certificate saved with success */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + pagination: components["schemas"]["Pagination"]; + data: components["schemas"]["File"][]; + }; + }; + }; + }; + }; + /** @description No file provided or other problem with provided file */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + message: string; + }; + }; + }; + }; + }; + }; + }; + "id_docs-add-files": { + parameters: { + query?: never; + header: { + /** @description Required to be true for the API request to pass */ + "OCS-APIRequest": boolean; + }; + path: { + apiVersion: "v1"; + }; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { + /** @description The list of files to add to profile */ + files: components["schemas"]["IdDocs"][]; + }; + }; + }; + responses: { + /** @description Certificate saved with success */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: unknown; + }; + }; + }; + }; + /** @description No file provided or other problem with provided file */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + /** Format: int64 */ + file: number | null; + /** @enum {string} */ + type: "info" | "warning" | "danger"; + message: string; + }; + }; + }; + }; + }; + }; + }; + "id_docs-delete-file": { + parameters: { + query: { + /** @description the nodeId of file to be delete */ + nodeId: number; + }; + header: { + /** @description Required to be true for the API request to pass */ + "OCS-APIRequest": boolean; + }; + path: { + apiVersion: "v1"; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description File deleted with success */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: unknown; + }; + }; + }; + }; + /** @description Failure to delete file from account */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + messages: string[]; + }; + }; + }; + }; + }; + }; + }; + "id_docs-list-to-approval": { + parameters: { + query?: { + /** @description Filter params */ + filter?: string | null; + /** @description the number of page to return */ + page?: number | null; + /** @description Total of elements to return */ + length?: number | null; + }; + header: { + /** @description Required to be true for the API request to pass */ + "OCS-APIRequest": boolean; + }; + path: { + apiVersion: "v1"; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + pagination: components["schemas"]["Pagination"]; + data: components["schemas"]["File"][] | null; + }; + }; + }; + }; + }; + /** @description Account not found */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + message: string; + }; + }; + }; + }; + }; + }; + }; "identify_account-search": { parameters: { query?: { diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 7d5062e5fe..eb496cbb8f 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -366,25 +366,6 @@ export type paths = { patch?: never; trace?: never; }; - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/files": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - /** List account files of authenticated account */ - get: operations["account-account-file-list-to-owner"]; - put?: never; - /** Add files to account profile */ - post: operations["account-add-files"]; - /** Delete file from account */ - delete: operations["account-delete-file"]; - options?: never; - head?: never; - patch?: never; - trace?: never; - }; "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/me": { parameters: { query?: never; @@ -405,23 +386,6 @@ export type paths = { patch?: never; trace?: never; }; - "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/files/approval/list": { - parameters: { - query?: never; - header?: never; - path?: never; - cookie?: never; - }; - /** List account files that need to be approved */ - get: operations["account-account-file-list-to-approval"]; - put?: never; - post?: never; - delete?: never; - options?: never; - head?: never; - patch?: never; - trace?: never; - }; "/ocs/v2.php/apps/libresign/api/{apiVersion}/account/settings": { parameters: { query?: never; @@ -660,6 +624,42 @@ export type paths = { patch: operations["file_element-patch"]; trace?: never; }; + "/ocs/v2.php/apps/libresign/api/{apiVersion}/id-docs": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** List files of authenticated account */ + get: operations["id_docs-list-to-owner"]; + put?: never; + /** Add files to account profile */ + post: operations["id_docs-add-files"]; + /** Delete file from account */ + delete: operations["id_docs-delete-file"]; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; + "/ocs/v2.php/apps/libresign/api/{apiVersion}/id-docs/approval/list": { + parameters: { + query?: never; + header?: never; + path?: never; + cookie?: never; + }; + /** List files that need to be approved */ + get: operations["id_docs-list-to-approval"]; + put?: never; + post?: never; + delete?: never; + options?: never; + head?: never; + patch?: never; + trace?: never; + }; "/ocs/v2.php/apps/libresign/api/{apiVersion}/identify-account/search": { parameters: { query?: never; @@ -922,11 +922,6 @@ export type paths = { export type webhooks = Record; export type components = { schemas: { - AccountFile: { - file: components["schemas"]["NewFile"]; - name?: string; - type?: string; - }; CertificatePfxData: { name: string; subject: string; @@ -996,6 +991,11 @@ export type components = { setting?: string; }; }; + IdDocs: { + file: components["schemas"]["NewFile"]; + name?: string; + type?: string; + }; IdentifyAccount: { /** Format: int64 */ id: number; @@ -1720,168 +1720,6 @@ export interface operations { }; }; }; - "account-account-file-list-to-owner": { - parameters: { - query?: { - /** @description Filter params */ - filter?: string | null; - /** @description the number of page to return */ - page?: number | null; - /** @description Total of elements to return */ - length?: number | null; - }; - header: { - /** @description Required to be true for the API request to pass */ - "OCS-APIRequest": boolean; - }; - path: { - apiVersion: "v1"; - }; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description Certificate saved with success */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - pagination: components["schemas"]["Pagination"]; - data: components["schemas"]["File"][]; - }; - }; - }; - }; - }; - /** @description No file provided or other problem with provided file */ - 404: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - message: string; - }; - }; - }; - }; - }; - }; - }; - "account-add-files": { - parameters: { - query?: never; - header: { - /** @description Required to be true for the API request to pass */ - "OCS-APIRequest": boolean; - }; - path: { - apiVersion: "v1"; - }; - cookie?: never; - }; - requestBody: { - content: { - "application/json": { - /** @description The list of files to add to profile */ - files: components["schemas"]["AccountFile"][]; - }; - }; - }; - responses: { - /** @description Certificate saved with success */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: unknown; - }; - }; - }; - }; - /** @description No file provided or other problem with provided file */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - /** Format: int64 */ - file: number | null; - /** @enum {string} */ - type: "info" | "warning" | "danger"; - message: string; - }; - }; - }; - }; - }; - }; - }; - "account-delete-file": { - parameters: { - query: { - /** @description the nodeId of file to be delete */ - nodeId: number; - }; - header: { - /** @description Required to be true for the API request to pass */ - "OCS-APIRequest": boolean; - }; - path: { - apiVersion: "v1"; - }; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description File deleted with success */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: unknown; - }; - }; - }; - }; - /** @description Failure to delete file from account */ - 401: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - messages: string[]; - }; - }; - }; - }; - }; - }; - }; "account-me": { parameters: { query?: never; @@ -1938,62 +1776,6 @@ export interface operations { }; }; }; - "account-account-file-list-to-approval": { - parameters: { - query?: { - /** @description Filter params */ - filter?: string | null; - /** @description the number of page to return */ - page?: number | null; - /** @description Total of elements to return */ - length?: number | null; - }; - header: { - /** @description Required to be true for the API request to pass */ - "OCS-APIRequest": boolean; - }; - path: { - apiVersion: "v1"; - }; - cookie?: never; - }; - requestBody?: never; - responses: { - /** @description OK */ - 200: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - pagination: components["schemas"]["Pagination"]; - data: components["schemas"]["File"][] | null; - }; - }; - }; - }; - }; - /** @description Account not found */ - 404: { - headers: { - [name: string]: unknown; - }; - content: { - "application/json": { - ocs: { - meta: components["schemas"]["OCSMeta"]; - data: { - message: string; - }; - }; - }; - }; - }; - }; - }; "account-update-settings": { parameters: { query?: never; @@ -2964,6 +2746,224 @@ export interface operations { }; }; }; + "id_docs-list-to-owner": { + parameters: { + query?: { + /** @description Filter params */ + filter?: string | null; + /** @description the number of page to return */ + page?: number | null; + /** @description Total of elements to return */ + length?: number | null; + }; + header: { + /** @description Required to be true for the API request to pass */ + "OCS-APIRequest": boolean; + }; + path: { + apiVersion: "v1"; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description Certificate saved with success */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + pagination: components["schemas"]["Pagination"]; + data: components["schemas"]["File"][]; + }; + }; + }; + }; + }; + /** @description No file provided or other problem with provided file */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + message: string; + }; + }; + }; + }; + }; + }; + }; + "id_docs-add-files": { + parameters: { + query?: never; + header: { + /** @description Required to be true for the API request to pass */ + "OCS-APIRequest": boolean; + }; + path: { + apiVersion: "v1"; + }; + cookie?: never; + }; + requestBody: { + content: { + "application/json": { + /** @description The list of files to add to profile */ + files: components["schemas"]["IdDocs"][]; + }; + }; + }; + responses: { + /** @description Certificate saved with success */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: unknown; + }; + }; + }; + }; + /** @description No file provided or other problem with provided file */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + /** Format: int64 */ + file: number | null; + /** @enum {string} */ + type: "info" | "warning" | "danger"; + message: string; + }; + }; + }; + }; + }; + }; + }; + "id_docs-delete-file": { + parameters: { + query: { + /** @description the nodeId of file to be delete */ + nodeId: number; + }; + header: { + /** @description Required to be true for the API request to pass */ + "OCS-APIRequest": boolean; + }; + path: { + apiVersion: "v1"; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description File deleted with success */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: unknown; + }; + }; + }; + }; + /** @description Failure to delete file from account */ + 401: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + messages: string[]; + }; + }; + }; + }; + }; + }; + }; + "id_docs-list-to-approval": { + parameters: { + query?: { + /** @description Filter params */ + filter?: string | null; + /** @description the number of page to return */ + page?: number | null; + /** @description Total of elements to return */ + length?: number | null; + }; + header: { + /** @description Required to be true for the API request to pass */ + "OCS-APIRequest": boolean; + }; + path: { + apiVersion: "v1"; + }; + cookie?: never; + }; + requestBody?: never; + responses: { + /** @description OK */ + 200: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + pagination: components["schemas"]["Pagination"]; + data: components["schemas"]["File"][] | null; + }; + }; + }; + }; + }; + /** @description Account not found */ + 404: { + headers: { + [name: string]: unknown; + }; + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + message: string; + }; + }; + }; + }; + }; + }; + }; "identify_account-search": { parameters: { query?: { diff --git a/src/views/Account/partials/Documents.vue b/src/views/Account/partials/Documents.vue index 2276ba8d46..5c1623cd88 100644 --- a/src/views/Account/partials/Documents.vue +++ b/src/views/Account/partials/Documents.vue @@ -100,6 +100,13 @@ export default { FilePicker, ProgressBar, }, + props: { + signRequestUuid: { + type: String, + required: false, + default: '', + }, + }, data() { return { documentList: [], @@ -138,7 +145,11 @@ export default { }, async loadDocuments() { this.loading = true - await axios.get(generateOcsUrl('/apps/libresign/api/v1/account/files')) + const params = {}; + if (this.signRequestUuid) { + params.uuid = this.signRequestUuid + } + await axios.get(generateOcsUrl('/apps/libresign/api/v1/id-docs'), { params }) .then(({ data }) => { this.documentList = data.ocs.data.data }) @@ -156,7 +167,7 @@ export default { this.loading = true - await axios.post(generateOcsUrl('/apps/libresign/api/v1/account/files'), { + const params = { files: [{ type: this.selectedType, name: path.match(/([^/]*?)(?:\.[^.]*)?$/)[1] ?? '', @@ -164,7 +175,12 @@ export default { path, }, }], - }) + } + if (this.signRequestUuid) { + params.uuid = this.signRequestUuid; + } + + await axios.post(generateOcsUrl('/apps/libresign/api/v1/id-docs'), params) .then(() => { showSuccess(t('libresign', 'File was sent.')) }) @@ -176,7 +192,7 @@ export default { async uploadFile(type, inputFile) { this.loading = true const raw = await loadFileToBase64(inputFile) - await axios.post(generateOcsUrl('/apps/libresign/api/v1/account/files'), { + const params = { files: [{ type, name: inputFile.name, @@ -184,7 +200,11 @@ export default { base64: raw, }, }], - }) + } + if (this.signRequestUuid) { + params.uuid = this.signRequestUuid; + } + await axios.post(generateOcsUrl('/apps/libresign/api/v1/id-docs'), params) .then(() => { showSuccess(t('libresign', 'File was sent.')) }) @@ -194,7 +214,7 @@ export default { this.loading = false }, async deleteFile({ nodeId }) { - await axios.delete(generateOcsUrl('/apps/libresign/api/v1/account/files'), { + await axios.delete(generateOcsUrl('/apps/libresign/api/v1/id-docs'), { data: { nodeId }, }) .then(async () => { diff --git a/src/views/Documents/AccountValidation.vue b/src/views/Documents/AccountValidation.vue index f8f71480e6..b09e374f34 100644 --- a/src/views/Documents/AccountValidation.vue +++ b/src/views/Documents/AccountValidation.vue @@ -60,7 +60,7 @@ export default { methods: { async loadDocuments() { this.loading = true - await axios.get(generateOcsUrl('/apps/libresign/api/v1/account/files/approval/list')) + await axios.get(generateOcsUrl('/apps/libresign/api/v1/id-docs/approval/list')) .then(({ data }) => { this.documentList = data.ocs.data.data }) diff --git a/src/views/SignPDF/_partials/Sign.vue b/src/views/SignPDF/_partials/Sign.vue index 49e014ef14..2725668e12 100644 --- a/src/views/SignPDF/_partials/Sign.vue +++ b/src/views/SignPDF/_partials/Sign.vue @@ -18,6 +18,18 @@ {{ t('libresign', 'Sign the document.') }} +
+

+ {{ t('libresign', 'Identification documents') }} +

+ + {{ t('libresign', 'Your profile documents') }} + +

{{ t('libresign', 'Please define your sign password') }} @@ -46,6 +58,13 @@

+ + + l10n = $this->createMock(IL10N::class); + $this->l10n + ->method('t') + ->will($this->returnArgument(0)); + $this->signRequestMapper = $this->createMock(SignRequestMapper::class); + $this->userManager = $this->createMock(IUserManager::class); + $this->accountManager = $this->createMock(IAccountManager::class); + $this->root = $this->createMock(IRootFolder::class); + $this->userMountCache = $this->createMock(IUserMountCache::class); + $this->mimeTypeDetector = $this->createMock(IMimeTypeDetector::class); + $this->fileMapper = $this->createMock(FileMapper::class); + $this->fileTypeMapper = $this->createMock(FileTypeMapper::class); + $this->accountFileMapper = $this->createMock(AccountFileMapper::class); + $this->signFile = $this->createMock(SignFileService::class); + $this->requestSignatureService = $this->createMock(RequestSignatureService::class); + $this->certificateEngineHandler = $this->createMock(CertificateEngineHandler::class); + $this->config = $this->createMock(IConfig::class); + $this->appConfig = $this->createMock(IAppConfig::class); + $this->mountProviderCollection = $this->createMock(IMountProviderCollection::class); + $this->newUserMail = $this->createMock(NewUserMailHelper::class); + $this->identifyMethodService = $this->createMock(IdentifyMethodService::class); + $this->validateHelper = $this->createMock(ValidateHelper::class); + $this->urlGenerator = $this->createMock(IURLGenerator::class); + $this->pkcs12Handler = $this->createMock(Pkcs12Handler::class); + $this->groupManager = $this->createMock(IGroupManager::class); + $this->accountFileService = $this->createMock(AccountFileService::class); + $this->signerElementsService = $this->createMock(SignerElementsService::class); + $this->userElementMapper = $this->createMock(UserElementMapper::class); + $this->folderService = $this->createMock(FolderService::class); + $this->clientService = $this->createMock(ClientService::class); + $this->timeFactory = $this->createMock(TimeFactory::class); + } + + private function getService(): AccountService { + return new AccountService( + $this->l10n, + $this->signRequestMapper, + $this->userManager, + $this->accountManager, + $this->root, + $this->userMountCache, + $this->mimeTypeDetector, + $this->fileMapper, + $this->fileTypeMapper, + $this->accountFileMapper, + $this->signFile, + $this->requestSignatureService, + $this->certificateEngineHandler, + $this->config, + $this->appConfig, + $this->mountProviderCollection, + $this->newUserMail, + $this->identifyMethodService, + $this->validateHelper, + $this->urlGenerator, + $this->pkcs12Handler, + $this->groupManager, + $this->accountFileService, + $this->signerElementsService, + $this->userElementMapper, + $this->folderService, + $this->clientService, + $this->timeFactory + ); + } + + /** + * @dataProvider providerTestValidateCreateToSignUsingDataProvider + */ + public function testValidateCreateToSignUsingDataProvider($arguments, $expectedErrorMessage):void { + $this->markTestSkipped('Need to reimplement this test, stated to failure after add identify methods'); + if (is_callable($arguments)) { + $arguments = $arguments($this); + } + + $this->expectExceptionMessage($expectedErrorMessage); + $this->getService()->validateCreateToSign($arguments); + } + + public static function providerTestValidateCreateToSignUsingDataProvider():array { + return [ + [ #0 + [ + 'uuid' => 'invalid uuid' + ], + 'Invalid UUID' + ], + [ #1 + function ($self):array { + $uuid = '12345678-1234-1234-1234-123456789012'; + $self->signRequestMapper = $self->createMock(SignRequestMapper::class); + $self->signRequestMapper + ->method('getByUuid') + ->will($self->returnCallback(function ():void { + throw new \Exception('Beep, beep, not found!', 1); + })); + return [ + 'uuid' => $uuid + ]; + }, + 'UUID not found' + ], + [ #2 + function ($self):array { + $signRequest = $self->createMock(SignRequest::class); + $signRequest + ->method('__call') + ->with($self->equalTo('getEmail'), $self->anything()) + ->will($self->returnValue('valid@test.coop')); + $self->signRequestMapper + ->method('getByUuid') + ->will($self->returnValue($signRequest)); + return [ + 'uuid' => '12345678-1234-1234-1234-123456789012', + 'user' => [ + 'email' => 'invalid@test.coop', + ], + 'signPassword' => '132456789' + ]; + }, + 'This is not your file' + ], + [ #3 + function ($self):array { + $signRequest = $self->createMock(SignRequest::class); + $signRequest + ->method('__call') + ->with($self->equalTo('getEmail'), $self->anything()) + ->will($self->returnValue('valid@test.coop')); + $self->signRequestMapper + ->method('getByUuid') + ->will($self->returnValue($signRequest)); + $self->userManager + ->method('userExists') + ->will($self->returnValue(true)); + return [ + 'uuid' => '12345678-1234-1234-1234-123456789012', + 'user' => [ + 'email' => 'valid@test.coop', + ], + 'signPassword' => '123456789' + ]; + }, + 'User already exists' + ], + [ #4 + function ($self):array { + $signRequest = $self->createMock(SignRequest::class); + $signRequest + ->method('__call') + ->with($self->equalTo('getEmail'), $self->anything()) + ->will($self->returnValue('valid@test.coop')); + $self->signRequestMapper + ->method('getByUuid') + ->will($self->returnValue($signRequest)); + return [ + 'uuid' => '12345678-1234-1234-1234-123456789012', + 'user' => [ + 'email' => 'valid@test.coop', + ], + 'signPassword' => '132456789', + 'password' => '' + ]; + }, + 'Password is mandatory' + ], + [ #5 + function ($self):array { + $signRequest = $this->createMock(SignRequest::class); + $signRequest + ->method('__call') + ->willReturnCallback(fn (string $method) => + match ($method) { + 'getEmail' => 'valid@test.coop', + 'getFileId' => 171, + 'getUserId' => 'username', + } + ); + $file = $this->createMock(\OCA\Libresign\Db\File::class); + $self->fileMapper + ->method('getById') + ->will($self->returnValue($file)); + $self->signRequestMapper + ->method('getByUuid') + ->will($self->returnValue($signRequest)); + + $self->root + ->method('getById') + ->will($self->returnValue([])); + $folder = $this->createMock(\OCP\Files\Folder::class); + $folder + ->method('getById') + ->willReturn([]); + $self->root + ->method('getUserFolder') + ->willReturn($folder); + return [ + 'uuid' => '12345678-1234-1234-1234-123456789012', + 'user' => [ + 'email' => 'valid@test.coop', + ], + 'signPassword' => '132456789', + 'password' => '123456789' + ]; + }, + 'File not found' + ], + ]; + } + + /** + * @dataProvider providerTestValidateCertificateDataUsingDataProvider + */ + public function testValidateCertificateDataUsingDataProvider($arguments, $expectedErrorMessage):void { + if (is_callable($arguments)) { + $arguments = $arguments($this); + } + + $this->expectExceptionMessage($expectedErrorMessage); + $this->getService()->validateCertificateData($arguments); + } + + public static function providerTestValidateCertificateDataUsingDataProvider():array { + return [ + [ + [ + 'uuid' => '12345678-1234-1234-1234-123456789012', + 'user' => [ + 'email' => '', + ], + ], + 'You must have an email. You can define the email in your profile.' + ], + [ + [ + 'uuid' => '12345678-1234-1234-1234-123456789012', + 'user' => [ + 'email' => 'invalid', + ], + ], + 'Invalid email' + ] + ]; + } + + public function testValidateCertificateDataWithSuccess():void { + $signRequest = $this->createMock(SignRequest::class); + $signRequest + ->method('__call') + ->with($this->equalTo('getEmail'), $this->anything()) + ->will($this->returnValue('valid@test.coop')); + $this->signRequestMapper + ->method('getByUuid') + ->will($this->returnValue($signRequest)); + $actual = $this->getService()->validateCertificateData([ + 'uuid' => '12345678-1234-1234-1234-123456789012', + 'user' => [ + 'email' => 'valid@test.coop', + ], + 'password' => '123456789', + 'signPassword' => '123456', + ]); + $this->assertNull($actual); + } + + public function testCreateToSignWithErrorInSendingEmail():void { + $signRequest = $this->createMock(\OCA\Libresign\Db\SignRequest::class); + $signRequest + ->method('__call') + ->willReturnCallback(fn (string $method) => + match ($method) { + 'getDisplayName' => 'John Doe', + 'getId' => 1, + } + ); + $this->signRequestMapper->method('getByUuid')->will($this->returnValue($signRequest)); + $userToSign = $this->createMock(\OCP\IUser::class); + $this->userManager->method('createUser')->will($this->returnValue($userToSign)); + $this->config->method('getAppValue')->will($this->returnValue('yes')); + $template = $this->createMock(\OCP\Mail\IEMailTemplate::class); + $this->newUserMail->method('generateTemplate')->will($this->returnValue($template)); + $this->newUserMail->method('sendMail')->will($this->returnCallback(function ():void { + throw new \Exception('Error Processing Request', 1); + })); + $this->expectExceptionMessage('Unable to send the invitation'); + $this->getService()->createToSign('uuid', 'username', 'passwordOfUser', 'passwordToSign'); + } + + public function testGetPdfByUuidWithSuccessAndSignedFile():void { + $libresignFile = $this->createMock(\OCA\Libresign\Db\File::class); + $this->fileMapper + ->method('getByUuid') + ->will($this->returnValue($libresignFile)); + $this->userMountCache + ->method('getMountsForFileId') + ->willreturn([]); + $node = $this->createMock(\OCP\Files\File::class); + $this->root + ->method('getById') + ->willReturn([$node]); + + $actual = $this->getService()->getPdfByUuid('uuid'); + $this->assertInstanceOf(\OCP\Files\File::class, $actual); + } + + public function testGetPdfByUuidWithSuccessAndUnignedFile():void { + $libresignFile = $this->createMock(\OCA\Libresign\Db\File::class); + $this->fileMapper + ->method('getByUuid') + ->will($this->returnValue($libresignFile)); + $this->userMountCache + ->method('getMountsForFileId') + ->willreturn([]); + $node = $this->createMock(\OCP\Files\File::class); + $this->root + ->method('getById') + ->willReturn([$node]); + + $actual = $this->getService()->getPdfByUuid('uuid'); + $this->assertInstanceOf(\OCP\Files\File::class, $actual); + } + + public function testCanRequestSignWithUnexistentUser():void { + $actual = $this->getService()->canRequestSign(); + $this->assertFalse($actual); + } + + public function testCanRequestSignWithoutGroups():void { + $this->appConfig + ->method('getValueString') + ->willReturn(''); + $user = $this->createMock(\OCP\IUser::class); + $actual = $this->getService()->canRequestSign($user); + $this->assertFalse($actual); + } + + public function testCanRequestSignWithUserOutOfAuthorizedGroups():void { + $this->appConfig + ->method('getValueArray') + ->willReturn(['admin']); + $this->groupManager + ->method('getUserGroupIds') + ->willReturn([]); + $user = $this->createMock(\OCP\IUser::class); + $actual = $this->getService()->canRequestSign($user); + $this->assertFalse($actual); + } + + public function testCanRequestSignWithSuccess():void { + $this->appConfig + ->method('getValueArray') + ->willReturn(['admin']); + $this->groupManager + ->method('getUserGroupIds') + ->willReturn(['admin']); + $user = $this->createMock(\OCP\IUser::class); + $actual = $this->getService()->canRequestSign($user); + $this->assertTrue($actual); + } +}