Skip to content

Commit 7aa8e25

Browse files
committed
refactor: centralize LibresignAccountCapabilitySettings type
Define LibresignAccountCapabilitySettings as a shared Psalm type in ResponseDefinitions.php. AccountSettingsProvider imports and uses it as its return type. SettingsLoader imports LibresignSettings for the getUserIdentificationSettings() return type annotation. The OpenAPI schema now exposes AccountCapabilitySettings as a first- class schema object with the three required boolean fields. Signed-off-by: Vitor Mattos <[email protected]>
1 parent e74ceaa commit 7aa8e25

5 files changed

Lines changed: 39 additions & 5 deletions

File tree

lib/ResponseDefinitions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
* needIdentificationDocuments: bool,
2929
* identificationDocumentsWaitingApproval: bool,
3030
* }
31+
* @psalm-type LibresignAccountCapabilitySettings = array{
32+
* canRequestSign: bool,
33+
* hasSignatureFile: bool,
34+
* isApprover: bool,
35+
* }
3136
*
3237
* Request input contracts
3338
*

lib/Service/File/AccountSettingsProvider.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCP\Accounts\IAccountManager;
1616
use OCP\IUser;
1717

18+
/** @psalm-import-type LibresignAccountCapabilitySettings from \OCA\Libresign\ResponseDefinitions */
1819
class AccountSettingsProvider {
1920
public function __construct(
2021
private IAccountManager $accountManager,
@@ -23,12 +24,15 @@ public function __construct(
2324
) {
2425
}
2526

27+
/** @psalm-return LibresignAccountCapabilitySettings */
2628
public function getSettings(?IUser $user = null): array {
2729
$canApproveIdDocs = $this->idDocsPolicyService->userCanApproveValidationDocuments($user, false);
28-
$return['canRequestSign'] = $canApproveIdDocs;
29-
$return['hasSignatureFile'] = $this->hasSignatureFile($user);
30-
$return['isApprover'] = $canApproveIdDocs;
31-
return $return;
30+
31+
return [
32+
'canRequestSign' => $canApproveIdDocs,
33+
'hasSignatureFile' => $this->hasSignatureFile($user),
34+
'isApprover' => $canApproveIdDocs,
35+
];
3236
}
3337

3438
public function getPhoneNumber(IUser $user): string {

lib/Service/File/SettingsLoader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use OCA\Libresign\Service\IdentifyMethodService;
1818
use OCP\IUser;
1919

20+
/** @psalm-import-type LibresignSettings from \OCA\Libresign\ResponseDefinitions */
2021
class SettingsLoader {
2122
public const IDENTIFICATION_DOCUMENTS_DISABLED = 0;
2223
public const IDENTIFICATION_DOCUMENTS_NEED_SEND = 1;
@@ -125,7 +126,7 @@ private function calculateStatusFromFiles(?array $files): int {
125126
* Always returns complete settings payload with defaults.
126127
* Canonical API shape is documented as LibresignSettings in ResponseDefinitions.
127128
*
128-
* @return array<string, bool|string>
129+
* @psalm-return LibresignSettings
129130
*/
130131
public function getUserIdentificationSettings(?IUser $user, ?SignRequest $signRequest = null): array {
131132
$status = $this->getIdentificationDocumentsStatus($user, $signRequest);

openapi-full.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@
2020
}
2121
},
2222
"schemas": {
23+
"AccountCapabilitySettings": {
24+
"type": "object",
25+
"required": [
26+
"canRequestSign",
27+
"hasSignatureFile",
28+
"isApprover"
29+
],
30+
"properties": {
31+
"canRequestSign": {
32+
"type": "boolean"
33+
},
34+
"hasSignatureFile": {
35+
"type": "boolean"
36+
},
37+
"isApprover": {
38+
"type": "boolean"
39+
}
40+
}
41+
},
2342
"AccountMeResponse": {
2443
"type": "object",
2544
"required": [

src/types/openapi/openapi-full.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,11 @@ export type paths = {
16101610
export type webhooks = Record<string, never>;
16111611
export type components = {
16121612
schemas: {
1613+
AccountCapabilitySettings: {
1614+
canRequestSign: boolean;
1615+
hasSignatureFile: boolean;
1616+
isApprover: boolean;
1617+
};
16131618
AccountMeResponse: {
16141619
account: {
16151620
uid: string;

0 commit comments

Comments
 (0)