Merge pull request #864 from dbeaver/fix/rm-disable

fix(plugin-resource-manager-administration): CB-2066 disable rm via a…
This commit is contained in:
alex
2022-05-27 15:10:11 +02:00
committed by GitHub
19 changed files with 271 additions and 7 deletions
@@ -94,6 +94,10 @@ export class ServerConfigResource extends CachedDataResource<ServerConfig | null
return this.data?.resourceQuotas ?? {};
}
get resourceManagerEnabled() {
return this.update.resourceManagerEnabled ?? this.data?.resourceManagerEnabled ?? false;
}
isFeatureEnabled(feature: string, serverSide = false): boolean {
if (serverSide) {
return this.data?.enabledFeatures.includes(feature) || false;
@@ -117,6 +121,8 @@ export class ServerConfigResource extends CachedDataResource<ServerConfig | null
|| this.update.anonymousAccessEnabled !== this.data.anonymousAccessEnabled
|| this.update.resourceManagerEnabled !== this.data.resourceManagerEnabled
|| this.update.adminCredentialsSaveEnabled !== this.data.adminCredentialsSaveEnabled
|| this.update.publicCredentialsSaveEnabled !== this.data.publicCredentialsSaveEnabled
@@ -219,6 +225,8 @@ export class ServerConfigResource extends CachedDataResource<ServerConfig | null
this.update.adminCredentialsSaveEnabled = serverConfig.adminCredentialsSaveEnabled;
this.update.publicCredentialsSaveEnabled = serverConfig.publicCredentialsSaveEnabled;
this.update.resourceManagerEnabled = serverConfig.resourceManagerEnabled;
this.update.customConnectionsEnabled = serverConfig.supportsCustomConnections;
this.update.enabledAuthProviders = [...serverConfig.enabledAuthProviders];
this.update.enabledFeatures = [...serverConfig.enabledFeatures];
@@ -17,6 +17,8 @@ query serverConfig {
adminCredentialsSaveEnabled
publicCredentialsSaveEnabled
resourceManagerEnabled
licenseRequired
licenseValid
+4 -1
View File
@@ -1341,6 +1341,7 @@ export interface ServerConfig {
productInfo: ProductInfo;
publicCredentialsSaveEnabled?: Maybe<Scalars['Boolean']>;
redirectOnFederatedAuth?: Maybe<Scalars['Boolean']>;
resourceManagerEnabled?: Maybe<Scalars['Boolean']>;
resourceQuotas: Scalars['Object'];
rootURI: Scalars['String'];
serverURL: Scalars['String'];
@@ -1365,6 +1366,7 @@ export interface ServerConfigInput {
enabledAuthProviders?: InputMaybe<Array<Scalars['ID']>>;
enabledFeatures?: InputMaybe<Array<Scalars['ID']>>;
publicCredentialsSaveEnabled?: InputMaybe<Scalars['Boolean']>;
resourceManagerEnabled?: InputMaybe<Scalars['Boolean']>;
serverName?: InputMaybe<Scalars['String']>;
serverURL?: InputMaybe<Scalars['String']>;
sessionExpireTime?: InputMaybe<Scalars['Int']>;
@@ -2292,7 +2294,7 @@ export type ReadSessionLogQuery = { log: Array<{ time?: any; type: string; messa
export type ServerConfigQueryVariables = Exact<{ [key: string]: never }>;
export type ServerConfigQuery = { serverConfig: { name: string; version: string; workspaceId: string; serverURL: string; rootURI: string; hostName: string; productConfiguration: any; supportsCustomConnections?: boolean; supportsConnectionBrowser?: boolean; supportsWorkspaces?: boolean; sessionExpireTime?: number; anonymousAccessEnabled?: boolean; adminCredentialsSaveEnabled?: boolean; publicCredentialsSaveEnabled?: boolean; licenseRequired: boolean; licenseValid: boolean; configurationMode?: boolean; developmentMode?: boolean; redirectOnFederatedAuth?: boolean; enabledFeatures: Array<string>; enabledAuthProviders: Array<string>; resourceQuotas: any; disabledDrivers: Array<string>; supportedLanguages: Array<{ isoCode: string; displayName?: string; nativeName?: string }>; defaultNavigatorSettings: { showSystemObjects: boolean; showUtilityObjects: boolean; showOnlyEntities: boolean; mergeEntities: boolean; hideFolders: boolean; hideSchemas: boolean; hideVirtualModel: boolean }; productInfo: { id: string; version: string; latestVersionInfo?: string; name: string; description?: string; buildTime: string; releaseTime: string; licenseInfo?: string } } };
export type ServerConfigQuery = { serverConfig: { name: string; version: string; workspaceId: string; serverURL: string; rootURI: string; hostName: string; productConfiguration: any; supportsCustomConnections?: boolean; supportsConnectionBrowser?: boolean; supportsWorkspaces?: boolean; sessionExpireTime?: number; anonymousAccessEnabled?: boolean; adminCredentialsSaveEnabled?: boolean; publicCredentialsSaveEnabled?: boolean; resourceManagerEnabled?: boolean; licenseRequired: boolean; licenseValid: boolean; configurationMode?: boolean; developmentMode?: boolean; redirectOnFederatedAuth?: boolean; enabledFeatures: Array<string>; enabledAuthProviders: Array<string>; resourceQuotas: any; disabledDrivers: Array<string>; supportedLanguages: Array<{ isoCode: string; displayName?: string; nativeName?: string }>; defaultNavigatorSettings: { showSystemObjects: boolean; showUtilityObjects: boolean; showOnlyEntities: boolean; mergeEntities: boolean; hideFolders: boolean; hideSchemas: boolean; hideVirtualModel: boolean }; productInfo: { id: string; version: string; latestVersionInfo?: string; name: string; description?: string; buildTime: string; releaseTime: string; licenseInfo?: string } } };
export type SessionPermissionsQueryVariables = Exact<{ [key: string]: never }>;
@@ -3627,6 +3629,7 @@ export const ServerConfigDocument = `
anonymousAccessEnabled
adminCredentialsSaveEnabled
publicCredentialsSaveEnabled
resourceManagerEnabled
licenseRequired
licenseValid
configurationMode
@@ -126,7 +126,11 @@ export const ServerConfigurationPage: AdministrationItemContentComponent = obser
<ServerConfigurationConfigurationForm serverConfig={service.state.serverConfig} />
<ServerConfigurationNavigatorViewForm configs={service.state} />
<ServerConfigurationFeaturesForm state={service.state} configurationWizard={configurationWizard} />
<Placeholder container={service.pluginsContainer} />
<Placeholder
container={service.pluginsContainer}
configurationWizard={configurationWizard}
state={service.state}
/>
</Group>
<Placeholder
container={service.configurationContainer}
@@ -45,7 +45,7 @@ export class ServerConfigurationService {
readonly saveTask: IExecutor<IServerConfigSaveData>;
readonly validationTask: IExecutor<IServerConfigSaveData>;
readonly configurationContainer: PlaceholderContainer<IConfigurationPlaceholderProps>;
readonly pluginsContainer: PlaceholderContainer;
readonly pluginsContainer: PlaceholderContainer<IConfigurationPlaceholderProps>;
private done: boolean;
private stateLinked: boolean;
@@ -0,0 +1,17 @@
# dependencies
/node_modules
# testing
/coverage
# production
/lib
# misc
.DS_Store
.env*
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
@@ -0,0 +1,45 @@
{
"name": "@cloudbeaver/plugin-resource-manager-administration",
"sideEffects": false,
"version": "0.1.0",
"description": "",
"license": "Apache-2.0",
"main": "lib/index.js",
"module": "lib/index.js",
"types": "src/index.ts",
"scripts": {
"prebuild": "rimraf lib/*",
"build": "webpack --config ../../configs/webpack.plugin.config.js",
"postbuild": "tsc",
"lint": "eslint ./src/ --ext .ts,.tsx",
"lint-fix": "eslint ./src/ --ext .ts,.tsx --fix"
},
"peerDependencies": {
"@cloudbeaver/core-administration": "~0.1.0",
"@cloudbeaver/core-app": "~0.1.0",
"@cloudbeaver/core-authentication": "~0.1.0",
"@cloudbeaver/core-blocks": "~0.1.0",
"@cloudbeaver/core-connections": "~0.1.0",
"@cloudbeaver/core-di": "~0.1.0",
"@cloudbeaver/core-dialogs": "~0.1.0",
"@cloudbeaver/core-events": "~0.1.0",
"@cloudbeaver/core-executor": "~0.1.0",
"@cloudbeaver/core-extensions": "~0.1.0",
"@cloudbeaver/core-localization": "~0.1.0",
"@cloudbeaver/core-notifications": "~0.1.0",
"@cloudbeaver/core-plugin": "~0.1.0",
"@cloudbeaver/core-product": "~0.1.0",
"@cloudbeaver/core-root": "~0.1.0",
"@cloudbeaver/core-routing": "~0.1.0",
"@cloudbeaver/core-sdk": "~0.1.0",
"@cloudbeaver/core-settings": "~0.1.0",
"@cloudbeaver/core-theming": "~0.1.0",
"@cloudbeaver/core-ui": "~0.1.0",
"@cloudbeaver/core-utils": "~0.1.0",
"@cloudbeaver/core-view": "~0.1.0",
"react": "~17.x.x",
"mobx": "~6.x.x",
"mobx-react-lite": "~3.x.x",
"reshadow": "~0.x.x"
}
}
@@ -0,0 +1,36 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2022 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 { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { LocalizationService } from '@cloudbeaver/core-localization';
@injectable()
export class LocaleService extends Bootstrap {
constructor(private readonly localizationService: LocalizationService) {
super();
}
register(): void | Promise<void> {
this.localizationService.addProvider(this.provider.bind(this));
}
load(): void | Promise<void> { }
private async provider(locale: string) {
switch (locale) {
case 'ru':
return (await import('./locales/ru')).default;
case 'it':
return (await import('./locales/it')).default;
case 'zh':
return (await import('./locales/zh')).default;
default:
return (await import('./locales/en')).default;
}
}
}
@@ -0,0 +1,54 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2022 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 { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
import { ExecutorInterrupter, IExecutionContextProvider } from '@cloudbeaver/core-executor';
import { ServerConfigResource } from '@cloudbeaver/core-root';
import { ILoadConfigData, ServerConfigurationService } from '@cloudbeaver/plugin-administration';
import { ResourceManagerSettings } from './ResourceManagerSettings';
@injectable()
export class PluginBootstrap extends Bootstrap {
constructor(
private readonly serverConfigurationService: ServerConfigurationService,
private readonly serverConfigResource: ServerConfigResource,
private readonly notificationService: NotificationService
) {
super();
this.loadConfigHandler = this.loadConfigHandler.bind(this);
}
register(): void | Promise<void> {
this.serverConfigurationService.pluginsContainer.add(ResourceManagerSettings, 0);
this.serverConfigurationService.loadConfigTask.addHandler(this.loadConfigHandler);
}
async load(): Promise<void> { }
private async loadConfigHandler(data: ILoadConfigData, contexts: IExecutionContextProvider<ILoadConfigData>) {
if (!data.reset) {
return;
}
try {
const config = await this.serverConfigResource.load();
if (!config) {
return;
}
data.state.serverConfig.resourceManagerEnabled = config.resourceManagerEnabled;
} catch (exception) {
ExecutorInterrupter.interrupt(contexts);
this.notificationService.logException(exception as any, 'Can\'t load server configuration');
}
}
}
@@ -0,0 +1,35 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2022 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 { observer } from 'mobx-react-lite';
import styled from 'reshadow';
import { BASE_CONTAINERS_STYLES, GroupTitle, PlaceholderComponent, Switch } from '@cloudbeaver/core-blocks';
import { useTranslate } from '@cloudbeaver/core-localization';
import type { IConfigurationPlaceholderProps } from '@cloudbeaver/plugin-administration';
export const ResourceManagerSettings: PlaceholderComponent<IConfigurationPlaceholderProps> = observer(
function ResourceManagerSettings({ state }) {
const translate = useTranslate();
return styled(BASE_CONTAINERS_STYLES)(
<>
<GroupTitle>{translate('plugin_resource_manager_title')}</GroupTitle>
<Switch
name='resourceManagerEnabled'
state={state.serverConfig}
description={translate('plugin_resource_manager_administration_settings_enable_description')}
mod={['primary']}
small
autoHide
>
{translate('plugin_resource_manager_administration_settings_enable')}
</Switch>
</>
);
});
@@ -0,0 +1,3 @@
import { resourceManagerAdministrationPlugin } from './manifest';
export default resourceManagerAdministrationPlugin;
@@ -0,0 +1,4 @@
export default [
['plugin_resource_manager_administration_settings_enable', 'Enable Resource manager'],
['plugin_resource_manager_administration_settings_enable_description', 'Enable Resource manager functionality'],
];
@@ -0,0 +1,4 @@
export default [
['plugin_resource_manager_administration_settings_enable', 'Enable Resource manager'],
['plugin_resource_manager_administration_settings_enable_description', 'Enable Resource manager functionality'],
];
@@ -0,0 +1,4 @@
export default [
['plugin_resource_manager_administration_settings_enable', 'Включить Менеджер ресурсов'],
['plugin_resource_manager_administration_settings_enable_description', 'Включает функционал Менеджера ресурсов'],
];
@@ -0,0 +1,4 @@
export default [
['plugin_resource_manager_administration_settings_enable', 'Enable Resource manager'],
['plugin_resource_manager_administration_settings_enable_description', 'Enable Resource manager functionality'],
];
@@ -0,0 +1,20 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2022 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 { PluginManifest } from '@cloudbeaver/core-di';
import { LocaleService } from './LocaleService';
import { PluginBootstrap } from './PluginBootstrap';
export const resourceManagerAdministrationPlugin: PluginManifest = {
info: { name: 'Resource manager administration plugin' },
providers: [
PluginBootstrap,
LocaleService,
],
};
@@ -0,0 +1,20 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "lib",
"composite": true
},
"include": [
"src"
],
"exclude": [
"**/node_modules",
"**/.*/"
],
"references": [
{
"path": "../*"
}
]
}
@@ -10,20 +10,19 @@ import { computed, makeObservable, observable } from 'mobx';
import { AuthInfoService } from '@cloudbeaver/core-authentication';
import { injectable } from '@cloudbeaver/core-di';
import { ResourceManagerSettingsService } from './ResourceManagerSettingsService';
import { ServerConfigResource } from '@cloudbeaver/core-root';
@injectable()
export class ResourceManagerService {
get enabled() {
return !this.resourceManagerSettingsService.settings.getValue('disabled') && !!this.authInfoService.userInfo;
return this.serverConfigResource.resourceManagerEnabled && !!this.authInfoService.userInfo;
}
panelEnabled: boolean;
constructor(
private readonly resourceManagerSettingsService: ResourceManagerSettingsService,
private readonly authInfoService: AuthInfoService,
private readonly serverConfigResource: ServerConfigResource
) {
this.togglePanel = this.togglePanel.bind(this);
@@ -19,6 +19,7 @@ import localization from '@cloudbeaver/plugin-localization';
import objectViewer from '@cloudbeaver/plugin-object-viewer';
import productPlugin from '@cloudbeaver/plugin-product';
import resourceManager from '@cloudbeaver/plugin-resource-manager';
import resourceManagerAdministration from '@cloudbeaver/plugin-resource-manager-administration';
import settingsMenu from '@cloudbeaver/plugin-settings-menu';
import settingsMenuAdministration from '@cloudbeaver/plugin-settings-menu-administration';
import sqlEditor from '@cloudbeaver/plugin-sql-editor';
@@ -60,6 +61,7 @@ const PLUGINS: PluginManifest[] = [
settingsMenuAdministration,
help,
resourceManager,
resourceManagerAdministration,
sqlEditorResource,
];