diff --git a/lib/Db/IdDocsMapper.php b/lib/Db/IdDocsMapper.php index 76e58cdfb..6a93c77d4 100644 --- a/lib/Db/IdDocsMapper.php +++ b/lib/Db/IdDocsMapper.php @@ -283,6 +283,8 @@ class IdDocsMapper extends QBMapper { ->format('Y-m-d H:i:s'), 'sign_date' => null, 'signRequestId' => $signer->getId(), + 'status' => $signer->getStatus(), + 'statusText' => $this->signRequestMapper->getTextOfSignerStatus($signer->getStatus()), ]; if ($signer->getSigned()) { $data['sign_date'] = (new \DateTime()) diff --git a/lib/Db/SignRequestMapper.php b/lib/Db/SignRequestMapper.php index e3e4d734a..8cd9d7eb3 100644 --- a/lib/Db/SignRequestMapper.php +++ b/lib/Db/SignRequestMapper.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace OCA\Libresign\Db; use DateTimeInterface; +use OCA\Libresign\Enum\SignRequestStatus; use OCA\Libresign\Helper\Pagination; use OCA\Libresign\Service\IdentifyMethod\IIdentifyMethod; use OCA\Libresign\Service\IdentifyMethodService; @@ -640,4 +641,8 @@ class SignRequestMapper extends QBMapper { $result = preg_replace($extensionPattern, '', $name); return $result ?? $name; } + + public function getTextOfSignerStatus(int $status): string { + return SignRequestStatus::from($status)->getLabel($this->l10n); + } } diff --git a/lib/Enum/SignRequestStatus.php b/lib/Enum/SignRequestStatus.php index 7767179b6..1470e4ab3 100644 --- a/lib/Enum/SignRequestStatus.php +++ b/lib/Enum/SignRequestStatus.php @@ -9,8 +9,21 @@ declare(strict_types=1); namespace OCA\Libresign\Enum; +use OCP\IL10N; + enum SignRequestStatus: int { case DRAFT = 0; case ABLE_TO_SIGN = 1; case SIGNED = 2; + + public function getLabel(IL10N $l10n): string { + return match($this) { + // TRANSLATORS Name of the status when signer document is in draft state + self::DRAFT => $l10n->t('Draft'), + // TRANSLATORS Name of the status when signer can sign the document + self::ABLE_TO_SIGN => $l10n->t('Pending'), + // TRANSLATORS Name of the status when signer has already signed + self::SIGNED => $l10n->t('Signed'), + }; + } } diff --git a/lib/ResponseDefinitions.php b/lib/ResponseDefinitions.php index 8fe6a468e..b712ad041 100644 --- a/lib/ResponseDefinitions.php +++ b/lib/ResponseDefinitions.php @@ -173,6 +173,8 @@ namespace OCA\Libresign; * hash_algorithm?: string, * me: bool, * signRequestId: non-negative-int, + * status: 0|1|2, + * statusText: string, * signingOrder?: non-negative-int, * identifyMethods?: LibresignIdentifyMethod[], * visibleElements?: LibresignVisibleElement[], diff --git a/lib/Service/FileService.php b/lib/Service/FileService.php index 3567ea4ea..1aafd9ff8 100644 --- a/lib/Service/FileService.php +++ b/lib/Service/FileService.php @@ -387,6 +387,8 @@ class FileService { $this->fileData->signers[$index]['me'] = false; $this->fileData->signers[$index]['signRequestId'] = $signer->getId(); $this->fileData->signers[$index]['description'] = $signer->getDescription(); + $this->fileData->signers[$index]['status'] = $signer->getStatus(); + $this->fileData->signers[$index]['statusText'] = $this->signRequestMapper->getTextOfSignerStatus($signer->getStatus()); $this->fileData->signers[$index]['signingOrder'] = $signer->getSigningOrder(); $this->fileData->signers[$index]['visibleElements'] = $this->getVisibleElements($signer->getId()); $this->fileData->signers[$index]['request_sign_date'] = $signer->getCreatedAt()->format(DateTimeInterface::ATOM); @@ -487,6 +489,9 @@ class FileService { private function loadSignersFromCertData(): void { $this->loadCertDataFromLibreSignFile(); foreach ($this->certData as $index => $signer) { + $this->fileData->signers[$index]['status'] = 2; + $this->fileData->signers[$index]['statusText'] = $this->signRequestMapper->getTextOfSignerStatus(2); + if (isset($signer['timestamp'])) { $this->fileData->signers[$index]['timestamp'] = $signer['timestamp']; if (isset($signer['timestamp']['genTime']) && $signer['timestamp']['genTime'] instanceof DateTimeInterface) { @@ -836,6 +841,7 @@ class FileService { 'signRequestId' => $signer->getId(), 'signingOrder' => $signer->getSigningOrder(), 'status' => $signer->getStatus(), + 'statusText' => $this->signRequestMapper->getTextOfSignerStatus($signer->getStatus()), 'me' => array_reduce($identifyMethodsOfSigner, function (bool $carry, IdentifyMethod $identifyMethod) use ($user): bool { if ($identifyMethod->getIdentifierKey() === IdentifyMethodService::IDENTIFY_ACCOUNT) { if ($user->getUID() === $identifyMethod->getIdentifierValue()) { diff --git a/openapi-full.json b/openapi-full.json index 2dfd0dd25..b4eb7cf6e 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -852,7 +852,9 @@ "request_sign_date", "signed", "me", - "signRequestId" + "signRequestId", + "status", + "statusText" ], "properties": { "description": { @@ -918,6 +920,18 @@ "format": "int64", "minimum": 0 }, + "status": { + "type": "integer", + "format": "int64", + "enum": [ + 0, + 1, + 2 + ] + }, + "statusText": { + "type": "string" + }, "signingOrder": { "type": "integer", "format": "int64", diff --git a/openapi.json b/openapi.json index 7aa0a0656..65d463c12 100644 --- a/openapi.json +++ b/openapi.json @@ -702,7 +702,9 @@ "request_sign_date", "signed", "me", - "signRequestId" + "signRequestId", + "status", + "statusText" ], "properties": { "description": { @@ -768,6 +770,18 @@ "format": "int64", "minimum": 0 }, + "status": { + "type": "integer", + "format": "int64", + "enum": [ + 0, + 1, + 2 + ] + }, + "statusText": { + "type": "string" + }, "signingOrder": { "type": "integer", "format": "int64", diff --git a/src/types/openapi/openapi-full.ts b/src/types/openapi/openapi-full.ts index 554d3c929..716dc960b 100644 --- a/src/types/openapi/openapi-full.ts +++ b/src/types/openapi/openapi-full.ts @@ -1716,6 +1716,12 @@ export type components = { me: boolean; /** Format: int64 */ signRequestId: number; + /** + * Format: int64 + * @enum {integer} + */ + status: 0 | 1 | 2; + statusText: string; /** Format: int64 */ signingOrder?: number; identifyMethods?: components["schemas"]["IdentifyMethod"][]; diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 77df93997..6fa82b007 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -1238,6 +1238,12 @@ export type components = { me: boolean; /** Format: int64 */ signRequestId: number; + /** + * Format: int64 + * @enum {integer} + */ + status: 0 | 1 | 2; + statusText: string; /** Format: int64 */ signingOrder?: number; identifyMethods?: components["schemas"]["IdentifyMethod"][];