mirror of
https://github.com/LibreSign/libresign.git
synced 2025-12-18 05:20:45 +01:00
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:
commit
e5d703c51a
9 changed files with 72 additions and 39 deletions
|
|
@ -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
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
24
lib/Enum/FileStatus.php
Normal 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;
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
17
openapi.json
17
openapi.json
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue