Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/Controller/FileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
);
Expand Down
19 changes: 11 additions & 8 deletions lib/Db/FileMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'),
};
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Db/IdDocsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
}
24 changes: 24 additions & 0 deletions lib/Enum/FileStatus.php
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 4 additions & 4 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
* }
* @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,
Expand Down
15 changes: 8 additions & 7 deletions openapi-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,9 @@
"message",
"name",
"id",
"etag",
"path",
"type"
"status",
"statusText",
"created_at"
],
"properties": {
"message": {
Expand All @@ -542,13 +542,14 @@
"type": "integer",
"format": "int64"
},
"etag": {
"type": "string"
"status": {
"type": "integer",
"format": "int64"
},
"path": {
"statusText": {
"type": "string"
},
"type": {
"created_at": {
"type": "string"
}
}
Expand Down
15 changes: 8 additions & 7 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,9 @@
"message",
"name",
"id",
"etag",
"path",
"type"
"status",
"statusText",
"created_at"
],
"properties": {
"message": {
Expand All @@ -472,13 +472,14 @@
"type": "integer",
"format": "int64"
},
"etag": {
"type": "string"
"status": {
"type": "integer",
"format": "int64"
},
"path": {
"statusText": {
"type": "string"
},
"type": {
"created_at": {
"type": "string"
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/types/openapi/openapi-full.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/types/openapi/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading