Skip to content

Commit 4e6f096

Browse files
authored
Merge pull request #5407 from LibreSign/chore/grid-view-button-label
chore: gridViewButtonLabel
2 parents c6b2142 + 2500aae commit 4e6f096

10 files changed

Lines changed: 476 additions & 12 deletions

File tree

lib/Controller/AccountController.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCP\AppFramework\Http\Attribute\PublicPage;
3333
use OCP\AppFramework\Http\Attribute\UseSession;
3434
use OCP\AppFramework\Http\DataResponse;
35+
use OCP\IConfig;
3536
use OCP\IL10N;
3637
use OCP\IRequest;
3738
use OCP\IURLGenerator;
@@ -62,6 +63,7 @@ public function __construct(
6263
protected IUserSession $userSession,
6364
protected SessionService $sessionService,
6465
private ValidateHelper $validateHelper,
66+
private IConfig $config,
6567
) {
6668
parent::__construct(Application::APP_ID, $request);
6769
}
@@ -518,4 +520,43 @@ public function readPfxData(string $password): DataResponse {
518520
Http::STATUS_ACCEPTED
519521
);
520522
}
523+
524+
/**
525+
* Set user config value
526+
*
527+
* @param string $key Config key
528+
* @param mixed $value Config value
529+
* @return DataResponse<Http::STATUS_OK, array{key: string, value: mixed}, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{message: string}, array{}>
530+
*
531+
* 200: Config updated
532+
* 400: Error updating config
533+
*/
534+
#[NoAdminRequired]
535+
#[NoCSRFRequired]
536+
#[ApiRoute(verb: 'PUT', url: '/api/{apiVersion}/account/config/{key}', requirements: ['apiVersion' => '(v1)'])]
537+
public function setConfig(string $key): DataResponse {
538+
try {
539+
$user = $this->userSession->getUser();
540+
if (!$user) {
541+
throw new \Exception('User not authenticated');
542+
}
543+
$data = $this->request->getParams();
544+
$value = $data['value'] ?? null;
545+
546+
if (is_bool($value)) {
547+
$value = $value ? '1' : '0';
548+
}
549+
550+
$this->config->setUserValue($user->getUID(), Application::APP_ID, $key, $value);
551+
552+
return new DataResponse([
553+
'key' => $key,
554+
'value' => $value,
555+
], Http::STATUS_OK);
556+
} catch (\Throwable $e) {
557+
return new DataResponse([
558+
'message' => $e->getMessage(),
559+
], Http::STATUS_BAD_REQUEST);
560+
}
561+
}
521562
}

lib/Service/AccountService.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,13 @@ public function getConfig(?IUser $user = null): array {
233233
$info['hasSignatureFile'] = $this->hasSignatureFile($user);
234234
$info['phoneNumber'] = $this->getPhoneNumber($user);
235235
$info['isApprover'] = $this->validateHelper->userCanApproveValidationDocuments($user, false);
236+
$info['grid_view'] = $this->getUserConfigGridView($user);
237+
236238
return $info;
237239
}
238240

241+
242+
239243
private function getPhoneNumber(?IUser $user): string {
240244
if (!$user) {
241245
return '';
@@ -256,6 +260,14 @@ public function hasSignatureFile(?IUser $user = null): bool {
256260
}
257261
}
258262

263+
private function getUserConfigGridView(?IUser $user = null): bool {
264+
if (!$user) {
265+
return false;
266+
}
267+
268+
return $this->config->getUserValue($user->getUID(), Application::APP_ID, 'grid_view', false) === '1';
269+
}
270+
259271
/**
260272
* Get PDF node by UUID
261273
*

openapi-full.json

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,6 +3539,138 @@
35393539
}
35403540
}
35413541
},
3542+
"/ocs/v2.php/apps/libresign/api/{apiVersion}/account/config/{key}": {
3543+
"put": {
3544+
"operationId": "account-set-config",
3545+
"summary": "Set user config value",
3546+
"tags": [
3547+
"account"
3548+
],
3549+
"security": [
3550+
{
3551+
"bearer_auth": []
3552+
},
3553+
{
3554+
"basic_auth": []
3555+
}
3556+
],
3557+
"parameters": [
3558+
{
3559+
"name": "apiVersion",
3560+
"in": "path",
3561+
"required": true,
3562+
"schema": {
3563+
"type": "string",
3564+
"enum": [
3565+
"v1"
3566+
],
3567+
"default": "v1"
3568+
}
3569+
},
3570+
{
3571+
"name": "key",
3572+
"in": "path",
3573+
"description": "Config key",
3574+
"required": true,
3575+
"schema": {
3576+
"type": "string"
3577+
}
3578+
},
3579+
{
3580+
"name": "OCS-APIRequest",
3581+
"in": "header",
3582+
"description": "Required to be true for the API request to pass",
3583+
"required": true,
3584+
"schema": {
3585+
"type": "boolean",
3586+
"default": true
3587+
}
3588+
}
3589+
],
3590+
"responses": {
3591+
"200": {
3592+
"description": "Config updated",
3593+
"content": {
3594+
"application/json": {
3595+
"schema": {
3596+
"type": "object",
3597+
"required": [
3598+
"ocs"
3599+
],
3600+
"properties": {
3601+
"ocs": {
3602+
"type": "object",
3603+
"required": [
3604+
"meta",
3605+
"data"
3606+
],
3607+
"properties": {
3608+
"meta": {
3609+
"$ref": "#/components/schemas/OCSMeta"
3610+
},
3611+
"data": {
3612+
"type": "object",
3613+
"required": [
3614+
"key",
3615+
"value"
3616+
],
3617+
"properties": {
3618+
"key": {
3619+
"type": "string"
3620+
},
3621+
"value": {
3622+
"type": "object"
3623+
}
3624+
}
3625+
}
3626+
}
3627+
}
3628+
}
3629+
}
3630+
}
3631+
}
3632+
},
3633+
"400": {
3634+
"description": "Error updating config",
3635+
"content": {
3636+
"application/json": {
3637+
"schema": {
3638+
"type": "object",
3639+
"required": [
3640+
"ocs"
3641+
],
3642+
"properties": {
3643+
"ocs": {
3644+
"type": "object",
3645+
"required": [
3646+
"meta",
3647+
"data"
3648+
],
3649+
"properties": {
3650+
"meta": {
3651+
"$ref": "#/components/schemas/OCSMeta"
3652+
},
3653+
"data": {
3654+
"type": "object",
3655+
"required": [
3656+
"message"
3657+
],
3658+
"properties": {
3659+
"message": {
3660+
"type": "string"
3661+
}
3662+
}
3663+
}
3664+
}
3665+
}
3666+
}
3667+
}
3668+
}
3669+
}
3670+
}
3671+
}
3672+
}
3673+
},
35423674
"/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate/uuid/{uuid}": {
35433675
"get": {
35443676
"operationId": "file-validate-uuid",

openapi.json

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3392,6 +3392,138 @@
33923392
}
33933393
}
33943394
},
3395+
"/ocs/v2.php/apps/libresign/api/{apiVersion}/account/config/{key}": {
3396+
"put": {
3397+
"operationId": "account-set-config",
3398+
"summary": "Set user config value",
3399+
"tags": [
3400+
"account"
3401+
],
3402+
"security": [
3403+
{
3404+
"bearer_auth": []
3405+
},
3406+
{
3407+
"basic_auth": []
3408+
}
3409+
],
3410+
"parameters": [
3411+
{
3412+
"name": "apiVersion",
3413+
"in": "path",
3414+
"required": true,
3415+
"schema": {
3416+
"type": "string",
3417+
"enum": [
3418+
"v1"
3419+
],
3420+
"default": "v1"
3421+
}
3422+
},
3423+
{
3424+
"name": "key",
3425+
"in": "path",
3426+
"description": "Config key",
3427+
"required": true,
3428+
"schema": {
3429+
"type": "string"
3430+
}
3431+
},
3432+
{
3433+
"name": "OCS-APIRequest",
3434+
"in": "header",
3435+
"description": "Required to be true for the API request to pass",
3436+
"required": true,
3437+
"schema": {
3438+
"type": "boolean",
3439+
"default": true
3440+
}
3441+
}
3442+
],
3443+
"responses": {
3444+
"200": {
3445+
"description": "Config updated",
3446+
"content": {
3447+
"application/json": {
3448+
"schema": {
3449+
"type": "object",
3450+
"required": [
3451+
"ocs"
3452+
],
3453+
"properties": {
3454+
"ocs": {
3455+
"type": "object",
3456+
"required": [
3457+
"meta",
3458+
"data"
3459+
],
3460+
"properties": {
3461+
"meta": {
3462+
"$ref": "#/components/schemas/OCSMeta"
3463+
},
3464+
"data": {
3465+
"type": "object",
3466+
"required": [
3467+
"key",
3468+
"value"
3469+
],
3470+
"properties": {
3471+
"key": {
3472+
"type": "string"
3473+
},
3474+
"value": {
3475+
"type": "object"
3476+
}
3477+
}
3478+
}
3479+
}
3480+
}
3481+
}
3482+
}
3483+
}
3484+
}
3485+
},
3486+
"400": {
3487+
"description": "Error updating config",
3488+
"content": {
3489+
"application/json": {
3490+
"schema": {
3491+
"type": "object",
3492+
"required": [
3493+
"ocs"
3494+
],
3495+
"properties": {
3496+
"ocs": {
3497+
"type": "object",
3498+
"required": [
3499+
"meta",
3500+
"data"
3501+
],
3502+
"properties": {
3503+
"meta": {
3504+
"$ref": "#/components/schemas/OCSMeta"
3505+
},
3506+
"data": {
3507+
"type": "object",
3508+
"required": [
3509+
"message"
3510+
],
3511+
"properties": {
3512+
"message": {
3513+
"type": "string"
3514+
}
3515+
}
3516+
}
3517+
}
3518+
}
3519+
}
3520+
}
3521+
}
3522+
}
3523+
}
3524+
}
3525+
}
3526+
},
33953527
"/ocs/v2.php/apps/libresign/api/{apiVersion}/file/validate/uuid/{uuid}": {
33963528
"get": {
33973529
"operationId": "file-validate-uuid",

src/store/userconfig.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,26 @@
44
*/
55

66
import { defineStore } from 'pinia'
7-
import { set } from 'vue'
7+
8+
import axios from '@nextcloud/axios'
9+
import { loadState } from '@nextcloud/initial-state'
10+
import { generateOcsUrl } from '@nextcloud/router'
811

912
export const useUserConfigStore = defineStore('userconfig', {
1013
state: () => ({
11-
grid_view: true,
14+
grid_view: loadState('libresign', 'config', { grid_view: false }).grid_view,
1215
}),
1316
actions: {
17+
onUpdate(key, value) {
18+
this[key] = value
19+
},
20+
1421
async update(key, value) {
15-
set(this, key, value)
22+
this.onUpdate(key, value)
23+
24+
await axios.put(generateOcsUrl('/apps/libresign/api/v1/account/config/{key}', { key }), {
25+
value,
26+
})
1627
},
1728
},
1829
})

0 commit comments

Comments
 (0)