Merge pull request #6094 from LibreSign/fix/return-right-fields-when-save-a-new-file

fix: add status and created_at fields to file upload response
This commit is contained in:
Vitor Mattos 2025-12-11 11:28:00 -03:00 committed by GitHub
commit e5d703c51a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 72 additions and 39 deletions

View file

@ -12,6 +12,7 @@ use InvalidArgumentException;
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 @@ class FileController extends AEnvironmentAwareController {
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 @@ class FileController extends AEnvironmentAwareController {
'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
);

View file

@ -8,6 +8,7 @@ declare(strict_types=1);
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 @@ class FileMapper extends QBMapper {
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'),
};
}

View file

@ -303,7 +303,7 @@ class IdDocsMapper extends QBMapper {
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),
};
}
}

24
lib/Enum/FileStatus.php Normal file
View file

@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Enum;
/**
* File status enum
*
* Represents all possible states a LibreSign file can be in
*/
enum FileStatus: int {
case NOT_LIBRESIGN_FILE = -1;
case DRAFT = 0;
case ABLE_TO_SIGN = 1;
case PARTIAL_SIGNED = 2;
case SIGNED = 3;
case DELETED = 4;
}

View file

@ -42,11 +42,11 @@ namespace OCA\Libresign;
* }
* @psalm-type LibresignNextcloudFile = array{
* message: string,
* name: string,
* name: non-falsy-string,
* id: int,
* etag: string,
* path: string,
* type: string,
* status: int,
* statusText: string,
* created_at: string,
* }
* @psalm-type LibresignIdentifyAccount = array{
* id: non-negative-int,

View file

@ -527,9 +527,9 @@
"message",
"name",
"id",
"etag",
"path",
"type"
"status",
"statusText",
"created_at"
],
"properties": {
"message": {
@ -542,13 +542,14 @@
"type": "integer",
"format": "int64"
},
"etag": {
"status": {
"type": "integer",
"format": "int64"
},
"statusText": {
"type": "string"
},
"path": {
"type": "string"
},
"type": {
"created_at": {
"type": "string"
}
}

View file

@ -457,9 +457,9 @@
"message",
"name",
"id",
"etag",
"path",
"type"
"status",
"statusText",
"created_at"
],
"properties": {
"message": {
@ -472,13 +472,14 @@
"type": "integer",
"format": "int64"
},
"etag": {
"status": {
"type": "integer",
"format": "int64"
},
"statusText": {
"type": "string"
},
"path": {
"type": "string"
},
"type": {
"created_at": {
"type": "string"
}
}

View file

@ -1611,9 +1611,10 @@ export type components = {
name: string;
/** Format: int64 */
id: number;
etag: string;
path: string;
type: string;
/** Format: int64 */
status: number;
statusText: string;
created_at: string;
};
Notify: {
date: string;

View file

@ -1155,9 +1155,10 @@ export type components = {
name: string;
/** Format: int64 */
id: number;
etag: string;
path: string;
type: string;
/** Format: int64 */
status: number;
statusText: string;
created_at: string;
};
Notify: {
date: string;