diff --git a/lib/Controller/FileController.php b/lib/Controller/FileController.php index db3525c9b6..dc2cf23192 100644 --- a/lib/Controller/FileController.php +++ b/lib/Controller/FileController.php @@ -12,6 +12,7 @@ use OCA\Files_Sharing\SharedStorage; use OCA\Libresign\AppInfo\Application; use OCA\Libresign\Db\File as FileEntity; +use OCA\Libresign\Db\FileMapper; use OCA\Libresign\Db\SignRequestMapper; use OCA\Libresign\Exception\LibresignException; use OCA\Libresign\Helper\JSActions; @@ -62,6 +63,7 @@ public function __construct( private IUserSession $userSession, private SessionService $sessionService, private SignRequestMapper $signRequestMapper, + private FileMapper $fileMapper, private IdentifyMethodService $identifyMethodService, private RequestSignatureService $requestSignatureService, private AccountService $accountService, @@ -438,16 +440,16 @@ public function save(array $file, string $name = '', array $settings = []): Data 'userManager' => $this->userSession->getUser(), 'status' => FileEntity::STATUS_DRAFT, ]; - $this->requestSignatureService->save($data); + $file = $this->requestSignatureService->save($data); return new DataResponse( [ 'message' => $this->l10n->t('Success'), 'name' => $name, 'id' => $node->getId(), - 'etag' => $node->getEtag(), - 'path' => $node->getPath(), - 'type' => $node->getType(), + 'status' => $file->getStatus(), + 'statusText' => $this->fileMapper->getTextOfStatus($file->getStatus()), + 'created_at' => $file->getCreatedAt()->format(\DateTimeInterface::ATOM), ], Http::STATUS_OK ); diff --git a/lib/Db/FileMapper.php b/lib/Db/FileMapper.php index 28dc846700..1f3f2fda51 100644 --- a/lib/Db/FileMapper.php +++ b/lib/Db/FileMapper.php @@ -8,6 +8,7 @@ namespace OCA\Libresign\Db; +use OCA\Libresign\Enum\FileStatus; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\QBMapper; use OCP\Comments\ICommentsManager; @@ -245,21 +246,23 @@ public function getFileType(int $id): string { return 'not_libresign_file'; } - public function getTextOfStatus(int $status): ?string { + public function getTextOfStatus(int|FileStatus $status): string { + if (is_int($status)) { + $status = FileStatus::from($status); + } return match ($status) { // TRANSLATORS Name of the status when document is not a LibreSign file - File::STATUS_NOT_LIBRESIGN_FILE => $this->l->t('not LibreSign file'), + FileStatus::NOT_LIBRESIGN_FILE => $this->l->t('not LibreSign file'), // TRANSLATORS Name of the status that the document is still as a draft - File::STATUS_DRAFT => $this->l->t('draft'), + FileStatus::DRAFT => $this->l->t('draft'), // TRANSLATORS Name of the status that the document can be signed - File::STATUS_ABLE_TO_SIGN => $this->l->t('available for signature'), + FileStatus::ABLE_TO_SIGN => $this->l->t('available for signature'), // TRANSLATORS Name of the status when the document has already been partially signed - File::STATUS_PARTIAL_SIGNED => $this->l->t('partially signed'), + FileStatus::PARTIAL_SIGNED => $this->l->t('partially signed'), // TRANSLATORS Name of the status when the document has been completely signed - File::STATUS_SIGNED => $this->l->t('signed'), + FileStatus::SIGNED => $this->l->t('signed'), // TRANSLATORS Name of the status when the document was deleted - File::STATUS_DELETED => $this->l->t('deleted'), - default => '', + FileStatus::DELETED => $this->l->t('deleted'), }; } diff --git a/lib/Db/IdDocsMapper.php b/lib/Db/IdDocsMapper.php index 801a597d07..76e58cdfb3 100644 --- a/lib/Db/IdDocsMapper.php +++ b/lib/Db/IdDocsMapper.php @@ -303,7 +303,7 @@ private function getIdDocStatusText(int $status): string { return match ($status) { File::STATUS_ABLE_TO_SIGN => $this->l10n->t('waiting for approval'), File::STATUS_SIGNED => $this->l10n->t('approved'), - default => $this->fileMapper->getTextOfStatus($status) ?? '', + default => $this->fileMapper->getTextOfStatus($status), }; } } diff --git a/lib/Enum/FileStatus.php b/lib/Enum/FileStatus.php new file mode 100644 index 0000000000..8157c3b63d --- /dev/null +++ b/lib/Enum/FileStatus.php @@ -0,0 +1,24 @@ +