From e90132ad8d2ba053fa9766d2db66263b56716a01 Mon Sep 17 00:00:00 2001 From: Wroud Date: Tue, 30 Mar 2021 20:03:30 +0300 Subject: [PATCH] fix: server configuration --- .../AdministrationScreenService.ts | 5 +- .../Checkboxes/useCheckboxState.ts | 2 +- .../core-blocks/src/FormControls/Combobox.tsx | 4 +- .../src/FormControls/ComboboxNew.tsx | 4 +- .../src/FormControls/FormContext.ts | 12 +++- .../src/FormControls/InputField.tsx | 2 +- .../src/FormControls/InputFieldNew.tsx | 2 +- .../core-blocks/src/FormControls/Radio.tsx | 2 +- .../src/FormControls/RadioGroup.tsx | 2 +- .../src/FormControls/SubmittingForm.tsx | 26 ++++++--- .../core-blocks/src/FormControls/Textarea.tsx | 2 +- .../src/FormControls/TextareaNew.tsx | 2 +- .../core-blocks/src/Tabs/Tab/useTab.ts | 45 ++++++-------- webapp/packages/core-blocks/src/index.ts | 2 + .../packages/core-blocks/src/useExecutor.ts | 56 ++++++++++++++++++ .../core-blocks/src/useFormValidator.ts | 28 +++++++++ .../src/ConnectionForm/Options/Options.tsx | 2 +- webapp/packages/core-executor/src/index.ts | 1 - .../core-executor/src/useFormValidator.ts | 44 -------------- .../ServerConfigurationPage.tsx | 3 +- .../ServerConfigurationPageController.ts | 7 --- .../AuthenticationProviders.tsx | 58 +++++++++++++------ .../ServerConfigurationAdminForm.tsx | 5 -- ...verConfigurationAuthenticationBootstrap.ts | 57 ++++++------------ 24 files changed, 206 insertions(+), 167 deletions(-) create mode 100644 webapp/packages/core-blocks/src/useExecutor.ts create mode 100644 webapp/packages/core-blocks/src/useFormValidator.ts delete mode 100644 webapp/packages/core-executor/src/useFormValidator.ts diff --git a/webapp/packages/core-administration/src/AdministrationScreen/AdministrationScreenService.ts b/webapp/packages/core-administration/src/AdministrationScreen/AdministrationScreenService.ts index 7de9d17de4..4d42f05129 100644 --- a/webapp/packages/core-administration/src/AdministrationScreen/AdministrationScreenService.ts +++ b/webapp/packages/core-administration/src/AdministrationScreen/AdministrationScreenService.ts @@ -256,7 +256,7 @@ export class AdministrationScreenService { return true; } - private async isAccessProvided(state: RouterState) { + private async isAccessProvided(state: RouterState): Promise { await this.serverConfigResource.load(); if (this.isConfigurationMode) { @@ -264,8 +264,7 @@ export class AdministrationScreenService { } if (this.screenService.isActive(state.name, AdministrationScreenService.setupName)) { - this.navigateToRoot(); - return; + return false; } await this.ensurePermissions.execute(); diff --git a/webapp/packages/core-blocks/src/FormControls/Checkboxes/useCheckboxState.ts b/webapp/packages/core-blocks/src/FormControls/Checkboxes/useCheckboxState.ts index da13b42b61..a2b3396b12 100644 --- a/webapp/packages/core-blocks/src/FormControls/Checkboxes/useCheckboxState.ts +++ b/webapp/packages/core-blocks/src/FormControls/Checkboxes/useCheckboxState.ts @@ -77,7 +77,7 @@ export function useCheckboxState(options: CheckboxStateOpti } onChange?.(checked, name as TKey); - context?.onChange(checked, name); + context?.change(checked, name); refresh(count + 1); }, diff --git a/webapp/packages/core-blocks/src/FormControls/Combobox.tsx b/webapp/packages/core-blocks/src/FormControls/Combobox.tsx index 53d42610a1..182bf557e5 100644 --- a/webapp/packages/core-blocks/src/FormControls/Combobox.tsx +++ b/webapp/packages/core-blocks/src/FormControls/Combobox.tsx @@ -177,7 +177,7 @@ export const Combobox: ComboboxType = observer(function Combobox({ onSelect(null, name, value); } if (context) { - context.onChange(null, name); + context.change(null, name); } setSearchValue(''); }, @@ -195,7 +195,7 @@ export const Combobox: ComboboxType = observer(function Combobox({ onSelect(id, name, value); } if (context) { - context.onChange(id, name); + context.change(id, name); } }, [value, state, name, menu, context, onSelect] diff --git a/webapp/packages/core-blocks/src/FormControls/ComboboxNew.tsx b/webapp/packages/core-blocks/src/FormControls/ComboboxNew.tsx index 5c5c9056cc..4eaa9663e1 100644 --- a/webapp/packages/core-blocks/src/FormControls/ComboboxNew.tsx +++ b/webapp/packages/core-blocks/src/FormControls/ComboboxNew.tsx @@ -195,7 +195,7 @@ export const ComboboxNew: ComboboxType = observer(function ComboboxNew({ onSelect(null, name, value); } if (context) { - context.onChange(null, name); + context.change(null, name); } setSearchValue(''); }, @@ -213,7 +213,7 @@ export const ComboboxNew: ComboboxType = observer(function ComboboxNew({ onSelect(id, name, value); } if (context) { - context.onChange(id, name); + context.change(id, name); } setSearchValue(''); }, diff --git a/webapp/packages/core-blocks/src/FormControls/FormContext.ts b/webapp/packages/core-blocks/src/FormControls/FormContext.ts index e8c459a9ee..bb99953047 100644 --- a/webapp/packages/core-blocks/src/FormControls/FormContext.ts +++ b/webapp/packages/core-blocks/src/FormControls/FormContext.ts @@ -8,8 +8,18 @@ import { createContext } from 'react'; +import type { IExecutor } from '@cloudbeaver/core-executor'; + +type ChangeHandler = (value: string | number | boolean | null | undefined, name: string | undefined) => void; + +export interface IChangeData { + value: string | number | boolean | null | undefined; + name: string | undefined; +} + export interface IFormContext { - onChange: (value: string | number | boolean | null | undefined, name: string | undefined) => void; + changeExecutor: IExecutor; + change: ChangeHandler; } export const FormContext = createContext(null); diff --git a/webapp/packages/core-blocks/src/FormControls/InputField.tsx b/webapp/packages/core-blocks/src/FormControls/InputField.tsx index 2504899ab0..4f4eb8e869 100644 --- a/webapp/packages/core-blocks/src/FormControls/InputField.tsx +++ b/webapp/packages/core-blocks/src/FormControls/InputField.tsx @@ -72,7 +72,7 @@ export const InputField: InputFieldType = observer(function InputField({ onChange(event.target.value, name); } if (context) { - context.onChange(event.target.value, name); + context.change(event.target.value, name); } }, [state, name, context, onChange]); diff --git a/webapp/packages/core-blocks/src/FormControls/InputFieldNew.tsx b/webapp/packages/core-blocks/src/FormControls/InputFieldNew.tsx index 4a25cec7a9..bdbc6d80a1 100644 --- a/webapp/packages/core-blocks/src/FormControls/InputFieldNew.tsx +++ b/webapp/packages/core-blocks/src/FormControls/InputFieldNew.tsx @@ -92,7 +92,7 @@ export const InputFieldNew: InputFieldType = observer(function InputFieldNew({ onChange(value, name); } if (context) { - context.onChange(value, name); + context.change(value, name); } }, [state, name, context, onChange]); diff --git a/webapp/packages/core-blocks/src/FormControls/Radio.tsx b/webapp/packages/core-blocks/src/FormControls/Radio.tsx index 5778d2db31..e4243695f6 100644 --- a/webapp/packages/core-blocks/src/FormControls/Radio.tsx +++ b/webapp/packages/core-blocks/src/FormControls/Radio.tsx @@ -144,7 +144,7 @@ export const Radio: RadioType = observer(function Radio({ if (context) { context.onChange(value); } else if (formContext) { - formContext.onChange(value, name); + formContext.change(value, name); } if (onChange) { diff --git a/webapp/packages/core-blocks/src/FormControls/RadioGroup.tsx b/webapp/packages/core-blocks/src/FormControls/RadioGroup.tsx index da3f64c621..7db736b4a1 100644 --- a/webapp/packages/core-blocks/src/FormControls/RadioGroup.tsx +++ b/webapp/packages/core-blocks/src/FormControls/RadioGroup.tsx @@ -60,7 +60,7 @@ export const RadioGroup: RadioGroupType = observer(function RadioGroup({ } if (formContext) { - formContext.onChange(value, name); + formContext.change(value, name); } }, [name, state, formContext, onChange]); diff --git a/webapp/packages/core-blocks/src/FormControls/SubmittingForm.tsx b/webapp/packages/core-blocks/src/FormControls/SubmittingForm.tsx index cd29009f32..fdddb31999 100644 --- a/webapp/packages/core-blocks/src/FormControls/SubmittingForm.tsx +++ b/webapp/packages/core-blocks/src/FormControls/SubmittingForm.tsx @@ -6,9 +6,12 @@ * you may not use this file except in compliance with the License. */ -import { useCallback, forwardRef, useMemo } from 'react'; +import { useCallback, forwardRef, useState, useContext } from 'react'; -import { FormContext } from './FormContext'; +import { Executor } from '@cloudbeaver/core-executor'; + +import { useObjectRef } from '../useObjectRef'; +import { FormContext, IChangeData, IFormContext } from './FormContext'; type FormDetailedProps = Omit, HTMLFormElement>, 'onChange'> & { disabled?: boolean; @@ -25,14 +28,23 @@ export const SubmittingForm = forwardRef(fun }, ref ) { + const parentContext = useContext(FormContext); + const props = useObjectRef({ parentContext, onChange, onSubmit }); + const [changeExecutor] = useState(() => new Executor()); + const handleSubmit = useCallback((e: React.FormEvent) => { e.preventDefault(); - if (onSubmit) { - onSubmit(e); - } - }, [onSubmit]); + props.onSubmit?.(e); + }, []); - const context = useMemo(() => ({ onChange }), [onChange]); + const context = useObjectRef({ + changeExecutor, + change(value, name) { + props.onChange(value, name); + props.parentContext?.change(value, name); + changeExecutor.execute({ value, name }); + }, + }, {}); return (
diff --git a/webapp/packages/core-blocks/src/FormControls/Textarea.tsx b/webapp/packages/core-blocks/src/FormControls/Textarea.tsx index 5327edf664..31f2315fb6 100644 --- a/webapp/packages/core-blocks/src/FormControls/Textarea.tsx +++ b/webapp/packages/core-blocks/src/FormControls/Textarea.tsx @@ -68,7 +68,7 @@ export const Textarea: TextareaType = observer(function Textarea({ onChange(event.target.value, name); } if (context) { - context.onChange(event.target.value, name); + context.change(event.target.value, name); } }, [state, name, onChange]); diff --git a/webapp/packages/core-blocks/src/FormControls/TextareaNew.tsx b/webapp/packages/core-blocks/src/FormControls/TextareaNew.tsx index bc532f9446..27273f9338 100644 --- a/webapp/packages/core-blocks/src/FormControls/TextareaNew.tsx +++ b/webapp/packages/core-blocks/src/FormControls/TextareaNew.tsx @@ -93,7 +93,7 @@ export const TextareaNew: TextareaType = observer(function TextareaNew({ onChange(event.target.value, name); } if (context) { - context.onChange(event.target.value, name); + context.change(event.target.value, name); } }, [state, name, onChange]); diff --git a/webapp/packages/core-blocks/src/Tabs/Tab/useTab.ts b/webapp/packages/core-blocks/src/Tabs/Tab/useTab.ts index 43a059b9c4..b0ca5ccf02 100644 --- a/webapp/packages/core-blocks/src/Tabs/Tab/useTab.ts +++ b/webapp/packages/core-blocks/src/Tabs/Tab/useTab.ts @@ -6,11 +6,9 @@ * you may not use this file except in compliance with the License. */ -import { useContext, useEffect } from 'react'; +import { useContext } from 'react'; -import type { IExecutorHandler } from '@cloudbeaver/core-executor'; - -import { useObjectRef } from '../../useObjectRef'; +import { useExecutor } from '../../useExecutor'; import type { ITabData } from '../TabsContainer/ITabsContainer'; import { TabsContext } from '../TabsContext'; @@ -24,34 +22,25 @@ export function useTab( throw new Error('TabsContext not provided'); } - const dynamic = useObjectRef({ - tabId, - open: onOpen, - close: onClose, + useExecutor({ + executor: state.openExecutor, + handlers: [function openHandler(data) { + if (tabId !== data.tabId) { + return; + } + onOpen?.(data); + }], }); - useEffect(() => { - const openHandler: IExecutorHandler> = data => { - if (dynamic.tabId !== data.tabId) { + useExecutor({ + executor: state.closeExecutor, + handlers: [function closeHandler(data) { + if (tabId !== data.tabId) { return; } - dynamic.open?.(data); - }; - const closeHandler: IExecutorHandler> = data => { - if (dynamic.tabId !== data.tabId) { - return; - } - dynamic.close?.(data); - }; - - state.openExecutor.addHandler(openHandler); - state.closeExecutor.addHandler(closeHandler); - - return () => { - state.openExecutor.removeHandler(openHandler); - state.closeExecutor.removeHandler(closeHandler); - }; - }, [state.openExecutor, state.closeExecutor]); + onClose?.(data); + }], + }); const handleOpen = () => state.open(tabId); diff --git a/webapp/packages/core-blocks/src/index.ts b/webapp/packages/core-blocks/src/index.ts index f54bafabea..5098008ea8 100644 --- a/webapp/packages/core-blocks/src/index.ts +++ b/webapp/packages/core-blocks/src/index.ts @@ -71,7 +71,9 @@ export * from './StaticImage'; export * from './TextPlaceholder'; export * from './useClipboard'; export * from './useDataResource'; +export * from './useExecutor'; export * from './useFocus'; +export * from './useFormValidator'; export * from './useMapResource'; export * from './useObjectRef'; export * from './useStateDelay'; diff --git a/webapp/packages/core-blocks/src/useExecutor.ts b/webapp/packages/core-blocks/src/useExecutor.ts new file mode 100644 index 0000000000..af015f609a --- /dev/null +++ b/webapp/packages/core-blocks/src/useExecutor.ts @@ -0,0 +1,56 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2021 DBeaver Corp and others + * + * Licensed under the Apache License, Version 2.0. + * you may not use this file except in compliance with the License. + */ + +import { useEffect } from 'react'; + +import type { IExecutor, IExecutorHandler, IExecutorHandlersCollection } from '@cloudbeaver/core-executor'; + +import { useObjectRef } from './useObjectRef'; + +interface IUseExecutorOptions { + executor: IExecutor | IExecutorHandlersCollection; + handlers?: Array>; + postHandlers?: Array>; +} + +export function useExecutor(options: IUseExecutorOptions): void { + const props = useObjectRef(options); + + useEffect(() => { + if (!props.executor) { + return; + } + + const handlers: Array> = []; + const postHandlers: Array> = []; + + if (props.handlers) { + for (let i = 0; i < props.handlers.length; i++) { + const handler: IExecutorHandler = (data, contexts) => props.handlers?.[i](data, contexts); + props.executor.addHandler(handler); + handlers.push(handler); + } + } + if (props.postHandlers) { + for (let i = 0; i < props.postHandlers.length; i++) { + const handler: IExecutorHandler = (data, contexts) => props.postHandlers?.[i](data, contexts); + props.executor.addPostHandler(handler); + postHandlers.push(handler); + } + } + + return () => { + for (const handler of handlers) { + props.executor.removeHandler(handler); + } + for (const handler of postHandlers) { + props.executor.removePostHandler(handler); + } + }; + }, [props.executor, props.handlers?.length, props.postHandlers?.length]); +} diff --git a/webapp/packages/core-blocks/src/useFormValidator.ts b/webapp/packages/core-blocks/src/useFormValidator.ts new file mode 100644 index 0000000000..46952aa43d --- /dev/null +++ b/webapp/packages/core-blocks/src/useFormValidator.ts @@ -0,0 +1,28 @@ + +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2021 DBeaver Corp and others + * + * Licensed under the Apache License, Version 2.0. + * you may not use this file except in compliance with the License. + */ + +import type { IExecutor, IExecutorHandlersCollection } from '@cloudbeaver/core-executor'; + +import { useExecutor } from './useExecutor'; + +export function useFormValidator( + validationTask: IExecutor | IExecutorHandlersCollection, + ref: React.RefObject, + callback?: () => void +): void { + useExecutor({ + executor: validationTask, + handlers: [function validate() { + ref.current?.checkValidity(); + ref.current?.reportValidity(); + + callback?.(); + }], + }); +} diff --git a/webapp/packages/core-connections/src/ConnectionForm/Options/Options.tsx b/webapp/packages/core-connections/src/ConnectionForm/Options/Options.tsx index 3128284e90..b0dc766be4 100644 --- a/webapp/packages/core-connections/src/ConnectionForm/Options/Options.tsx +++ b/webapp/packages/core-connections/src/ConnectionForm/Options/Options.tsx @@ -26,9 +26,9 @@ import { TextareaNew, ComboboxNew, Container, + useFormValidator, } from '@cloudbeaver/core-blocks'; import { useService } from '@cloudbeaver/core-di'; -import { useFormValidator } from '@cloudbeaver/core-executor'; import { useTranslate } from '@cloudbeaver/core-localization'; import { useStyles } from '@cloudbeaver/core-theming'; diff --git a/webapp/packages/core-executor/src/index.ts b/webapp/packages/core-executor/src/index.ts index f246f6ca14..230527d799 100644 --- a/webapp/packages/core-executor/src/index.ts +++ b/webapp/packages/core-executor/src/index.ts @@ -8,4 +8,3 @@ export * from './IExecutionContext'; export * from './IExecutor'; export * from './IExecutorHandler'; export * from './IExecutorHandlersCollection'; -export * from './useFormValidator'; diff --git a/webapp/packages/core-executor/src/useFormValidator.ts b/webapp/packages/core-executor/src/useFormValidator.ts deleted file mode 100644 index 5a12697db0..0000000000 --- a/webapp/packages/core-executor/src/useFormValidator.ts +++ /dev/null @@ -1,44 +0,0 @@ - -/* - * CloudBeaver - Cloud Database Manager - * Copyright (C) 2020-2021 DBeaver Corp and others - * - * Licensed under the Apache License, Version 2.0. - * you may not use this file except in compliance with the License. - */ - -import { useEffect, useRef } from 'react'; - -import type { IExecutor } from './IExecutor'; -import type { IExecutorHandlersCollection } from './IExecutorHandlersCollection'; - -export function useFormValidator( - validationTask: IExecutor | IExecutorHandlersCollection, - ref: React.RefObject, - callback?: () => void -): void { - const callbackRef = useRef({ - callback, - ref, - }); - callbackRef.current.callback = callback; - callbackRef.current.ref = ref; - - useEffect(() => { - if (!validationTask) { - return; - } - - function validate() { - if (callbackRef.current) { - callbackRef.current.ref.current?.checkValidity(); - callbackRef.current.ref.current?.reportValidity(); - - callbackRef.current.callback?.(); - } - } - validationTask.addHandler(validate); - - return () => validationTask.removeHandler(validate); - }, [validationTask]); -} diff --git a/webapp/packages/plugin-administration/src/ConfigurationWizard/ServerConfiguration/ServerConfigurationPage.tsx b/webapp/packages/plugin-administration/src/ConfigurationWizard/ServerConfiguration/ServerConfigurationPage.tsx index ed17437595..37502ef053 100644 --- a/webapp/packages/plugin-administration/src/ConfigurationWizard/ServerConfiguration/ServerConfigurationPage.tsx +++ b/webapp/packages/plugin-administration/src/ConfigurationWizard/ServerConfiguration/ServerConfigurationPage.tsx @@ -10,9 +10,8 @@ import { observer } from 'mobx-react-lite'; import styled, { css } from 'reshadow'; import { AdministrationItemContentComponent, AdministrationTools, ADMINISTRATION_TOOLS_STYLES } from '@cloudbeaver/core-administration'; -import { BASE_CONTAINERS_STYLES, ColoredContainer, Container, Group, GroupItem, GroupTitle, IconButton, Loader, Placeholder, SubmittingForm, useFocus } from '@cloudbeaver/core-blocks'; +import { BASE_CONTAINERS_STYLES, ColoredContainer, Container, Group, GroupItem, GroupTitle, IconButton, Loader, Placeholder, SubmittingForm, useFocus, useFormValidator } from '@cloudbeaver/core-blocks'; import { useController, useService } from '@cloudbeaver/core-di'; -import { useFormValidator } from '@cloudbeaver/core-executor'; import { useTranslate } from '@cloudbeaver/core-localization'; import { useStyles } from '@cloudbeaver/core-theming'; diff --git a/webapp/packages/plugin-administration/src/ConfigurationWizard/ServerConfiguration/ServerConfigurationPageController.ts b/webapp/packages/plugin-administration/src/ConfigurationWizard/ServerConfiguration/ServerConfigurationPageController.ts index ecb94ca893..f491f1e154 100644 --- a/webapp/packages/plugin-administration/src/ConfigurationWizard/ServerConfiguration/ServerConfigurationPageController.ts +++ b/webapp/packages/plugin-administration/src/ConfigurationWizard/ServerConfiguration/ServerConfigurationPageController.ts @@ -37,13 +37,6 @@ export class ServerConfigurationPageController { change = (): void => { this.serverConfigurationService.changed(); - if (this.state.serverConfig.enabledAuthProviders?.length === 0) { - this.state.serverConfig.authenticationEnabled = false; - } - - if (!this.state.serverConfig.authenticationEnabled) { - this.state.serverConfig.anonymousAccessEnabled = true; - } if (!this.state.serverConfig.adminCredentialsSaveEnabled) { this.state.serverConfig.publicCredentialsSaveEnabled = false; diff --git a/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/AuthenticationProviders.tsx b/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/AuthenticationProviders.tsx index f2c971d052..11a8d790f0 100644 --- a/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/AuthenticationProviders.tsx +++ b/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/AuthenticationProviders.tsx @@ -7,10 +7,11 @@ */ import { observer } from 'mobx-react-lite'; +import { useContext } from 'react'; import styled from 'reshadow'; import { AuthProvidersResource, AUTH_PROVIDER_LOCAL_ID } from '@cloudbeaver/core-authentication'; -import { BASE_CONTAINERS_STYLES, Container, Group, GroupTitle, Loader, PlaceholderComponent, SwitchNew, useMapResource } from '@cloudbeaver/core-blocks'; +import { BASE_CONTAINERS_STYLES, Container, FormContext, Group, GroupTitle, Loader, PlaceholderComponent, SwitchNew, useExecutor, useMapResource } from '@cloudbeaver/core-blocks'; import { useTranslate } from '@cloudbeaver/core-localization'; import { useStyles } from '@cloudbeaver/core-theming'; import type { IConfigurationPlaceholderProps } from '@cloudbeaver/plugin-administration'; @@ -24,8 +25,33 @@ export const AuthenticationProviders: PlaceholderComponent 1; + + useExecutor({ + executor: formContext.changeExecutor, + handlers: [function switchControls() { + if (externalAuthentication) { + serverConfig.enabledAuthProviders = [...providers.resource.keys]; + serverConfig.authenticationEnabled = true; + } + + if (serverConfig.enabledAuthProviders?.length === 0) { + serverConfig.authenticationEnabled = false; + } + + if (!serverConfig.authenticationEnabled) { + serverConfig.anonymousAccessEnabled = true; + } + }], + }); return styled(styles)( @@ -42,21 +68,19 @@ export const AuthenticationProviders: PlaceholderComponent {translate('administration_configuration_wizard_configuration_anonymous_access')} - {!disabled && ( - - {translate('administration_configuration_wizard_configuration_authentication')} - - )} + + {translate('administration_configuration_wizard_configuration_authentication')} + - {() => !disabled && styled(styles)( + {() => providersSelectable && styled(styles)( <> {translate('administration_configuration_wizard_configuration_authentication_provider')} {providers.data.map(provider => provider && ( @@ -77,7 +101,7 @@ export const AuthenticationProviders: PlaceholderComponent - {configurationWizard ? ( + {configurationWizard && localExists ? ( ) : ( diff --git a/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/ServerConfigurationAdminForm.tsx b/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/ServerConfigurationAdminForm.tsx index d594cb6460..8f6694920e 100644 --- a/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/ServerConfigurationAdminForm.tsx +++ b/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/ServerConfigurationAdminForm.tsx @@ -10,7 +10,6 @@ import { observer } from 'mobx-react-lite'; import styled from 'reshadow'; -import { AUTH_PROVIDER_LOCAL_ID } from '@cloudbeaver/core-authentication'; import { BASE_CONTAINERS_STYLES, Group, GroupTitle, InputFieldNew } from '@cloudbeaver/core-blocks'; import { useTranslate } from '@cloudbeaver/core-localization'; import type { ServerConfigInput } from '@cloudbeaver/core-sdk'; @@ -26,10 +25,6 @@ export const ServerConfigurationAdminForm: React.FC = observer(function S const translate = useTranslate(); const style = useStyles(BASE_CONTAINERS_STYLES); - if (!serverConfig.enabledAuthProviders?.includes(AUTH_PROVIDER_LOCAL_ID)) { - return null; - } - return styled(style)( {translate('administration_configuration_wizard_configuration_admin')} diff --git a/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/ServerConfigurationAuthenticationBootstrap.ts b/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/ServerConfigurationAuthenticationBootstrap.ts index f5c78ebc0f..dc41afccfe 100644 --- a/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/ServerConfigurationAuthenticationBootstrap.ts +++ b/webapp/packages/plugin-authentication/src/Administration/ServerConfiguration/ServerConfigurationAuthenticationBootstrap.ts @@ -26,26 +26,18 @@ export class ServerConfigurationAuthenticationBootstrap extends Bootstrap { register(): void { this.serverConfigurationService.validationTask.addHandler(this.validateForm); - this.serverConfigurationService.prepareConfigTask.addHandler(this.prepareConfig); this.serverConfigurationService.loadConfigTask.addHandler(this.loadServerConfig); } load(): void { } private loadServerConfig: IExecutorHandler = async (data, contexts) => { - const providers = await this.authProvidersResource.loadAll(); - const disabled = providers.length === 1 && !this.authProvidersResource.has(AUTH_PROVIDER_LOCAL_ID); - - if (disabled) { - data.state.serverConfig.enabledAuthProviders = [...this.authProvidersResource.keys]; - data.state.serverConfig.authenticationEnabled = true; - } - if (!data.reload) { return; } try { + await this.authProvidersResource.loadAll(); const config = await this.serverConfigResource.load(); if (!config) { @@ -53,16 +45,17 @@ export class ServerConfigurationAuthenticationBootstrap extends Bootstrap { } if (config.configurationMode) { - data.state.serverConfig.adminName = 'cbadmin'; - data.state.serverConfig.adminPassword = ''; - - data.state.serverConfig.anonymousAccessEnabled = false; - data.state.serverConfig.authenticationEnabled = true; + if (this.authProvidersResource.has(AUTH_PROVIDER_LOCAL_ID)) { + data.state.serverConfig.adminName = 'cbadmin'; + data.state.serverConfig.adminPassword = ''; + } } else { - data.state.serverConfig.anonymousAccessEnabled = config.anonymousAccessEnabled; - data.state.serverConfig.authenticationEnabled = config.authenticationEnabled; + data.state.serverConfig.adminName = undefined; + data.state.serverConfig.adminPassword = undefined; } + data.state.serverConfig.anonymousAccessEnabled = config.anonymousAccessEnabled; + data.state.serverConfig.authenticationEnabled = config.authenticationEnabled; data.state.serverConfig.enabledAuthProviders = config.enabledAuthProviders; } catch (exception) { ExecutorInterrupter.interrupt(contexts); @@ -70,37 +63,21 @@ export class ServerConfigurationAuthenticationBootstrap extends Bootstrap { } }; - private prepareConfig: IExecutorHandler = async (data, contexts) => { - const providers = await this.authProvidersResource.loadAll(); - const disabled = providers.length === 1 && !this.authProvidersResource.has(AUTH_PROVIDER_LOCAL_ID); + private validateForm: IExecutorHandler = async (data, contexts) => { + await this.authProvidersResource.loadAll(); + const administratorPresented = data.configurationWizard && this.authProvidersResource.has(AUTH_PROVIDER_LOCAL_ID); - if (disabled) { - data.state.serverConfig.enabledAuthProviders = [...this.authProvidersResource.keys]; - data.state.serverConfig.authenticationEnabled = true; + if (!administratorPresented) { + return; } - if ( - !data.configurationWizard - || !data.state.serverConfig.enabledAuthProviders?.includes(AUTH_PROVIDER_LOCAL_ID) - ) { - data.state.serverConfig.adminName = undefined; - data.state.serverConfig.adminPassword = undefined; - } - }; - - private validateForm: IExecutorHandler = (data, contexts) => { const validation = contexts.getContext(serverConfigValidationContext); - if ( - data.configurationWizard - && data.state.serverConfig.enabledAuthProviders?.includes(AUTH_PROVIDER_LOCAL_ID) - ) { - if (!data.state.serverConfig.adminName + if (!data.state.serverConfig.adminName || data.state.serverConfig.adminName.length < 6 || !data.state.serverConfig.adminPassword - ) { - validation.invalidate(); - } + ) { + validation.invalidate(); } }; }