mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
feat(plugin-authentication-administration): CB-1421 add default provider
if there is one provider, set it as default
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { runInAction } from 'mobx';
|
||||
import { computed, makeObservable, runInAction } from 'mobx';
|
||||
|
||||
import { injectable } from '@cloudbeaver/core-di';
|
||||
import { ServerConfigResource } from '@cloudbeaver/core-root';
|
||||
@@ -30,6 +30,10 @@ export type AuthProviderConfiguration = BaseAuthProviderConfiguration;
|
||||
|
||||
@injectable()
|
||||
export class AuthProvidersResource extends CachedMapResource<string, AuthProvider> {
|
||||
get configurable(): AuthProvider[] {
|
||||
return this.values.filter(provider => provider.configurable);
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly authSettingsService: AuthSettingsService,
|
||||
private readonly graphQLService: GraphQLService,
|
||||
@@ -43,6 +47,10 @@ export class AuthProvidersResource extends CachedMapResource<string, AuthProvide
|
||||
|
||||
this.authConfigurationsResource.onItemAdd.addHandler(this.updateConfigurations.bind(this));
|
||||
this.authConfigurationsResource.onItemDelete.addHandler(this.deleteConfigurations.bind(this));
|
||||
|
||||
makeObservable(this, {
|
||||
configurable: computed,
|
||||
});
|
||||
}
|
||||
|
||||
getEnabledProviders(): AuthProvider[] {
|
||||
|
||||
@@ -194,7 +194,7 @@ export const Combobox: ComboboxType = observer(function Combobox({
|
||||
}, [value, state, name, menu, context, onSelect]);
|
||||
|
||||
const matchItems = useCallback((input?: boolean) => {
|
||||
if (!searchValue) {
|
||||
if (searchValue === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -49,7 +49,6 @@ export const AuthConfigurationOptions: TabContainerPanelComponent<IAuthConfigura
|
||||
|
||||
const { categories, isUncategorizedExists } = useObjectPropertyCategories(parameters.data ?? emptyArray);
|
||||
|
||||
const identityProviders = providers.resource.values.filter(provider => provider.configurable);
|
||||
const edit = state.mode === 'edit';
|
||||
|
||||
return styled(style)(
|
||||
@@ -59,7 +58,7 @@ export const AuthConfigurationOptions: TabContainerPanelComponent<IAuthConfigura
|
||||
<Combobox
|
||||
name='providerId'
|
||||
state={state.config}
|
||||
items={identityProviders}
|
||||
items={providers.resource.configurable}
|
||||
keySelector={provider => provider.id}
|
||||
valueSelector={provider => provider.label}
|
||||
placeholder={translate('administration_identity_providers_choose_provider_placeholder')}
|
||||
|
||||
+14
-3
@@ -6,14 +6,14 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { AuthConfigurationsResource } from '@cloudbeaver/core-authentication';
|
||||
import { AuthConfigurationsResource, AuthProvidersResource } from '@cloudbeaver/core-authentication';
|
||||
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
|
||||
import type { IExecutionContextProvider } from '@cloudbeaver/core-executor';
|
||||
import { getUniqueName } from '@cloudbeaver/core-utils';
|
||||
|
||||
import { AuthConfigurationFormService } from '../AuthConfigurationFormService';
|
||||
import { authConfigurationContext } from '../Contexts/authConfigurationContext';
|
||||
import type { IAuthConfigurationFormFillConfigData, IAuthConfigurationFormSubmitData } from '../IAuthConfigurationFormProps';
|
||||
import type { IAuthConfigurationFormFillConfigData, IAuthConfigurationFormState, IAuthConfigurationFormSubmitData } from '../IAuthConfigurationFormProps';
|
||||
import { AuthConfigurationOptions } from './AuthConfigurationOptions';
|
||||
|
||||
@injectable()
|
||||
@@ -21,6 +21,7 @@ export class AuthConfigurationOptionsTabService extends Bootstrap {
|
||||
constructor(
|
||||
private readonly authConfigurationFormService: AuthConfigurationFormService,
|
||||
private readonly authConfigurationsResource: AuthConfigurationsResource,
|
||||
private readonly authProvidersResource: AuthProvidersResource,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -130,7 +131,16 @@ export class AuthConfigurationOptionsTabService extends Bootstrap {
|
||||
}
|
||||
}
|
||||
|
||||
private fillConfig(
|
||||
private async setDefaults(state: IAuthConfigurationFormState) {
|
||||
if (state.mode === 'create') {
|
||||
await this.authProvidersResource.loadAll();
|
||||
if (this.authProvidersResource.configurable.length === 1 && !state.config.providerId) {
|
||||
state.config.providerId = this.authProvidersResource.configurable[0].id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async fillConfig(
|
||||
{ state, updated }: IAuthConfigurationFormFillConfigData,
|
||||
contexts: IExecutionContextProvider<IAuthConfigurationFormFillConfigData>
|
||||
) {
|
||||
@@ -139,6 +149,7 @@ export class AuthConfigurationOptionsTabService extends Bootstrap {
|
||||
}
|
||||
|
||||
if (!state.info) {
|
||||
await this.setDefaults(state);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user