Skip to content

Commit d11ab5b

Browse files
authored
Merge pull request #6098 from LibreSign/backport/6094/stable31
[stable31] fix: add status and created_at fields to file upload response
2 parents 4c5e20e + 9036e19 commit d11ab5b

9 files changed

Lines changed: 70 additions & 37 deletions

File tree

lib/Controller/FileController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCA\Files_Sharing\SharedStorage;
1313
use OCA\Libresign\AppInfo\Application;
1414
use OCA\Libresign\Db\File as FileEntity;
15+
use OCA\Libresign\Db\FileMapper;
1516
use OCA\Libresign\Db\SignRequestMapper;
1617
use OCA\Libresign\Exception\LibresignException;
1718
use OCA\Libresign\Helper\JSActions;
@@ -62,6 +63,7 @@ public function __construct(
6263
private IUserSession $userSession,
6364
private SessionService $sessionService,
6465
private SignRequestMapper $signRequestMapper,
66+
private FileMapper $fileMapper,
6567
private IdentifyMethodService $identifyMethodService,
6668
private RequestSignatureService $requestSignatureService,
6769
private AccountService $accountService,
@@ -438,16 +440,16 @@ public function save(array $file, string $name = '', array $settings = []): Data
438440
'userManager' => $this->userSession->getUser(),
439441
'status' => FileEntity::STATUS_DRAFT,
440442
];
441-
$this->requestSignatureService->save($data);
443+
$file = $this->requestSignatureService->save($data);
442444

443445
return new DataResponse(
444446
[
445447
'message' => $this->l10n->t('Success'),
446448
'name' => $name,
447449
'id' => $node->getId(),
448-
'etag' => $node->getEtag(),
449-
'path' => $node->getPath(),
450-
'type' => $node->getType(),
450+
'status' => $file->getStatus(),
451+
'statusText' => $this->fileMapper->getTextOfStatus($file->getStatus()),
452+
'created_at' => $file->getCreatedAt()->format(\DateTimeInterface::ATOM),
451453
],
452454
Http::STATUS_OK
453455
);

lib/Db/FileMapper.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace OCA\Libresign\Db;
1010

11+
use OCA\Libresign\Enum\FileStatus;
1112
use OCP\AppFramework\Db\DoesNotExistException;
1213
use OCP\AppFramework\Db\QBMapper;
1314
use OCP\Comments\ICommentsManager;
@@ -245,21 +246,23 @@ public function getFileType(int $id): string {
245246
return 'not_libresign_file';
246247
}
247248

248-
public function getTextOfStatus(int $status): ?string {
249+
public function getTextOfStatus(int|FileStatus $status): string {
250+
if (is_int($status)) {
251+
$status = FileStatus::from($status);
252+
}
249253
return match ($status) {
250254
// TRANSLATORS Name of the status when document is not a LibreSign file
251-
File::STATUS_NOT_LIBRESIGN_FILE => $this->l->t('not LibreSign file'),
255+
FileStatus::NOT_LIBRESIGN_FILE => $this->l->t('not LibreSign file'),
252256
// TRANSLATORS Name of the status that the document is still as a draft
253-
File::STATUS_DRAFT => $this->l->t('draft'),
257+
FileStatus::DRAFT => $this->l->t('draft'),
254258
// TRANSLATORS Name of the status that the document can be signed
255-
File::STATUS_ABLE_TO_SIGN => $this->l->t('available for signature'),
259+
FileStatus::ABLE_TO_SIGN => $this->l->t('available for signature'),
256260
// TRANSLATORS Name of the status when the document has already been partially signed
257-
File::STATUS_PARTIAL_SIGNED => $this->l->t('partially signed'),
261+
FileStatus::PARTIAL_SIGNED => $this->l->t('partially signed'),
258262
// TRANSLATORS Name of the status when the document has been completely signed
259-
File::STATUS_SIGNED => $this->l->t('signed'),
263+
FileStatus::SIGNED => $this->l->t('signed'),
260264
// TRANSLATORS Name of the status when the document was deleted
261-
File::STATUS_DELETED => $this->l->t('deleted'),
262-
default => '',
265+
FileStatus::DELETED => $this->l->t('deleted'),
263266
};
264267
}
265268

lib/Db/IdDocsMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ private function getIdDocStatusText(int $status): string {
303303
return match ($status) {
304304
File::STATUS_ABLE_TO_SIGN => $this->l10n->t('waiting for approval'),
305305
File::STATUS_SIGNED => $this->l10n->t('approved'),
306-
default => $this->fileMapper->getTextOfStatus($status) ?? '',
306+
default => $this->fileMapper->getTextOfStatus($status),
307307
};
308308
}
309309
}

lib/Enum/FileStatus.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Libresign\Enum;
11+
12+
/**
13+
* File status enum
14+
*
15+
* Represents all possible states a LibreSign file can be in
16+
*/
17+
enum FileStatus: int {
18+
case NOT_LIBRESIGN_FILE = -1;
19+
case DRAFT = 0;
20+
case ABLE_TO_SIGN = 1;
21+
case PARTIAL_SIGNED = 2;
22+
case SIGNED = 3;
23+
case DELETED = 4;
24+
}

lib/ResponseDefinitions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
* }
4343
* @psalm-type LibresignNextcloudFile = array{
4444
* message: string,
45-
* name: string,
45+
* name: non-falsy-string,
4646
* id: int,
47-
* etag: string,
48-
* path: string,
49-
* type: string,
47+
* status: int,
48+
* statusText: string,
49+
* created_at: string,
5050
* }
5151
* @psalm-type LibresignIdentifyAccount = array{
5252
* id: non-negative-int,

openapi-full.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -527,9 +527,9 @@
527527
"message",
528528
"name",
529529
"id",
530-
"etag",
531-
"path",
532-
"type"
530+
"status",
531+
"statusText",
532+
"created_at"
533533
],
534534
"properties": {
535535
"message": {
@@ -542,13 +542,14 @@
542542
"type": "integer",
543543
"format": "int64"
544544
},
545-
"etag": {
546-
"type": "string"
545+
"status": {
546+
"type": "integer",
547+
"format": "int64"
547548
},
548-
"path": {
549+
"statusText": {
549550
"type": "string"
550551
},
551-
"type": {
552+
"created_at": {
552553
"type": "string"
553554
}
554555
}

openapi.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,9 @@
457457
"message",
458458
"name",
459459
"id",
460-
"etag",
461-
"path",
462-
"type"
460+
"status",
461+
"statusText",
462+
"created_at"
463463
],
464464
"properties": {
465465
"message": {
@@ -472,13 +472,14 @@
472472
"type": "integer",
473473
"format": "int64"
474474
},
475-
"etag": {
476-
"type": "string"
475+
"status": {
476+
"type": "integer",
477+
"format": "int64"
477478
},
478-
"path": {
479+
"statusText": {
479480
"type": "string"
480481
},
481-
"type": {
482+
"created_at": {
482483
"type": "string"
483484
}
484485
}

src/types/openapi/openapi-full.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,9 +1611,10 @@ export type components = {
16111611
name: string;
16121612
/** Format: int64 */
16131613
id: number;
1614-
etag: string;
1615-
path: string;
1616-
type: string;
1614+
/** Format: int64 */
1615+
status: number;
1616+
statusText: string;
1617+
created_at: string;
16171618
};
16181619
Notify: {
16191620
date: string;

src/types/openapi/openapi.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,9 +1155,10 @@ export type components = {
11551155
name: string;
11561156
/** Format: int64 */
11571157
id: number;
1158-
etag: string;
1159-
path: string;
1160-
type: string;
1158+
/** Format: int64 */
1159+
status: number;
1160+
statusText: string;
1161+
created_at: string;
11611162
};
11621163
Notify: {
11631164
date: string;

0 commit comments

Comments
 (0)