From 9c9e843c98b8f43a1dba50ad1bfca8e2bcf5c1e7 Mon Sep 17 00:00:00 2001 From: sergeyteleshev Date: Thu, 21 Aug 2025 17:01:28 +0200 Subject: [PATCH] adds schema parsing for UserFormInfoPart & ConnectionFormOptionsPart --- webapp/packages/core-utils/src/schema.ts | 4 +- .../Users/UserForm/Info/IUserFormInfoState.ts | 21 +++++----- .../Users/UserForm/Info/UserFormInfoPart.ts | 39 +++++++------------ .../Options/ConnectionFormOptionsPart.ts | 11 ++---- .../Options/IConnectionConfig.ts | 26 ++++++------- 5 files changed, 44 insertions(+), 57 deletions(-) diff --git a/webapp/packages/core-utils/src/schema.ts b/webapp/packages/core-utils/src/schema.ts index 9aa010522b..cda975811d 100644 --- a/webapp/packages/core-utils/src/schema.ts +++ b/webapp/packages/core-utils/src/schema.ts @@ -57,4 +57,6 @@ export const schemaExtra = { }, }; -export { z as schema }; +const RecordKeySchema = z.union([z.string(), z.number(), z.symbol()]); + +export { z as schema, RecordKeySchema }; diff --git a/webapp/packages/plugin-authentication-administration/src/Administration/Users/UserForm/Info/IUserFormInfoState.ts b/webapp/packages/plugin-authentication-administration/src/Administration/Users/UserForm/Info/IUserFormInfoState.ts index 2f2117a21c..a4e3ffd706 100644 --- a/webapp/packages/plugin-authentication-administration/src/Administration/Users/UserForm/Info/IUserFormInfoState.ts +++ b/webapp/packages/plugin-authentication-administration/src/Administration/Users/UserForm/Info/IUserFormInfoState.ts @@ -1,17 +1,20 @@ /* * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2024 DBeaver Corp and others + * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. */ -export interface IUserFormInfoState { - userId: string; - enabled: boolean; - password: string; - metaParameters: Record; - teams: string[]; +import { RecordKeySchema, schema } from '@cloudbeaver/core-utils'; - authRole: string; // used in TE product -} +export const USER_FORM_INFO_PART_SCHEMA = schema.object({ + userId: schema.string().trim(), + enabled: schema.boolean(), + password: schema.string().trim(), + metaParameters: schema.record(RecordKeySchema, schema.string().trim().or(schema.any())), + teams: schema.array(schema.string().trim()), + authRole: schema.string().trim(), +}); + +export type IUserFormInfoState = schema.infer; diff --git a/webapp/packages/plugin-authentication-administration/src/Administration/Users/UserForm/Info/UserFormInfoPart.ts b/webapp/packages/plugin-authentication-administration/src/Administration/Users/UserForm/Info/UserFormInfoPart.ts index 8bde7f297b..271bc9074f 100644 --- a/webapp/packages/plugin-authentication-administration/src/Administration/Users/UserForm/Info/UserFormInfoPart.ts +++ b/webapp/packages/plugin-authentication-administration/src/Administration/Users/UserForm/Info/UserFormInfoPart.ts @@ -15,7 +15,7 @@ import { isArraysEqual, isObjectsEqual, isValuesEqual } from '@cloudbeaver/core- import { isDefined } from '@dbeaver/js-helpers'; import type { IUserFormState } from '../AdministrationUserFormService.js'; -import type { IUserFormInfoState } from './IUserFormInfoState.js'; +import { USER_FORM_INFO_PART_SCHEMA, type IUserFormInfoState } from './IUserFormInfoState.js'; const DEFAULT_ENABLED = true; @@ -27,35 +27,22 @@ export class UserFormInfoPart extends FormPart, contexts: IExecutionContextProvider>): void | Promise { - this.state.password = this.state.password.trim(); - const metaParameters = this.state.metaParameters; - - if (this.formState.mode === FormMode.Create) { - this.state.userId = this.state.userId.trim(); - } - - for (const key in metaParameters) { - const value = metaParameters[key]; - - if (typeof value === 'string') { - metaParameters[key] = value.trim(); - } - } - } - override isOutdated(): boolean { if (this.formState.mode === FormMode.Edit && this.initialState.userId) { return this.usersResource.isOutdated(this.initialState.userId) || this.usersMetaParametersResource.isOutdated(this.initialState.userId); diff --git a/webapp/packages/plugin-connections/src/ConnectionForm/Options/ConnectionFormOptionsPart.ts b/webapp/packages/plugin-connections/src/ConnectionForm/Options/ConnectionFormOptionsPart.ts index aa37be1975..bcfe464f2a 100644 --- a/webapp/packages/plugin-connections/src/ConnectionForm/Options/ConnectionFormOptionsPart.ts +++ b/webapp/packages/plugin-connections/src/ConnectionForm/Options/ConnectionFormOptionsPart.ts @@ -32,7 +32,7 @@ import { parseJdbcUri } from '@dbeaver/jdbc-uri-parser'; import { getDefaultConfigurationType } from './getDefaultConfigurationType.js'; import { getConnectionName } from './getConnectionName.js'; -import type { IConnectionFormOptionsState } from './IConnectionFormOptionsState.js'; +import { CONNECTION_FORM_OPTIONS_SCHEMA, type IConnectionFormOptionsState } from './IConnectionFormOptionsState.js'; import type { IConnectionFormState } from '../IConnectionFormState.js'; import { ConnectionAuthenticationDialogLoader } from '../../ConnectionAuthentication/ConnectionAuthenticationDialogLoader.js'; @@ -70,7 +70,7 @@ export class ConnectionFormOptionsPart extends FormPart