dbeaver/pro#6243 add permissions for executing and updating results (#3634)

* dbeaver/pro#6243 add permissions for executing and updating results

* feat: support special method for dataset execution

* fix: disable sql editor screen when permission is not granted

---------

Co-authored-by: Wroud <wrouds@gmail.com>
Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com>
This commit is contained in:
Ainur
2025-08-11 11:55:51 +02:00
committed by GitHub
co-authored by Wroud Daria Marutkina
parent d9d30a0e35
commit 7e0ad33fa4
18 changed files with 207 additions and 74 deletions
@@ -1,6 +1,6 @@
/*
* 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.
@@ -10,10 +10,11 @@ import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
import { MENU_TAB } from '@cloudbeaver/core-ui';
import { ACTION_OPEN_IN_TAB, ActionService, type IAction, KEY_BINDING_OPEN_IN_TAB, KeyBindingService, MenuService } from '@cloudbeaver/core-view';
import { DATA_CONTEXT_SQL_EDITOR_STATE, SqlDataSourceService } from '@cloudbeaver/plugin-sql-editor';
import { DATA_CONTEXT_SQL_EDITOR_STATE, ESqlDataSourceFeatures, SqlDataSourceService } from '@cloudbeaver/plugin-sql-editor';
import { DATA_CONTEXT_SQL_EDITOR_TAB } from '@cloudbeaver/plugin-sql-editor-navigation-tab';
import { SqlEditorScreenService } from './Screen/SqlEditorScreenService.js';
import { SqlEditorScreenSettingsService } from './SqlEditorScreenSettingsService.js';
@injectable()
export class PluginBootstrap extends Bootstrap {
@@ -24,6 +25,7 @@ export class PluginBootstrap extends Bootstrap {
private readonly notificationService: NotificationService,
private readonly menuService: MenuService,
private readonly sqlDataSourceService: SqlDataSourceService,
private readonly sqlEditorScreenSettingsService: SqlEditorScreenSettingsService,
) {
super();
}
@@ -33,6 +35,13 @@ export class PluginBootstrap extends Bootstrap {
id: 'sql-editor-screen',
actions: [ACTION_OPEN_IN_TAB],
contexts: [DATA_CONTEXT_SQL_EDITOR_STATE],
isActionApplicable: context => {
const state = context.get(DATA_CONTEXT_SQL_EDITOR_STATE)!;
const dataSource = this.sqlDataSourceService.get(state.editorId);
return !!dataSource?.hasFeature(ESqlDataSourceFeatures.script) && this.sqlEditorScreenSettingsService.enabled;
},
isDisabled: context => {
const state = context.get(DATA_CONTEXT_SQL_EDITOR_STATE)!;
@@ -47,6 +56,13 @@ export class PluginBootstrap extends Bootstrap {
binding: KEY_BINDING_OPEN_IN_TAB,
actions: [ACTION_OPEN_IN_TAB],
contexts: [DATA_CONTEXT_SQL_EDITOR_STATE],
isBindingApplicable: context => {
const state = context.get(DATA_CONTEXT_SQL_EDITOR_STATE)!;
const dataSource = this.sqlDataSourceService.get(state.editorId);
return !!dataSource?.hasFeature(ESqlDataSourceFeatures.script) && this.sqlEditorScreenSettingsService.enabled;
},
handler: this.openTab.bind(this),
});
@@ -1,6 +1,6 @@
/*
* 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.
@@ -10,15 +10,22 @@ import { type IScreen, ScreenService } from '@cloudbeaver/core-routing';
import type { ISqlEditorScreenParams } from './ISqlEditorScreenParams.js';
import { SqlEditorScreen } from './SqlEditorScreen.js';
import { SqlEditorScreenSettingsService } from '../SqlEditorScreenSettingsService.js';
@injectable()
export class SqlEditorScreenService {
readonly screen: IScreen<ISqlEditorScreenParams>;
constructor(private readonly screenService: ScreenService) {
constructor(
private readonly screenService: ScreenService,
sqlEditorScreenSettingsService: SqlEditorScreenSettingsService,
) {
this.screen = {
name: 'sql-editor',
routes: [{ name: 'sql-editor', path: '/sql-editor/:contextId' }],
component: SqlEditorScreen,
canDeActivate() {
return sqlEditorScreenSettingsService.enabled;
},
};
}
@@ -0,0 +1,44 @@
/*
* CloudBeaver - Cloud Database Manager
* 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.
*/
import { Dependency, injectable } from '@cloudbeaver/core-di';
import { HIGHEST_SETTINGS_LAYER } from '@cloudbeaver/core-root';
import { createSettingsOverrideResolver, SettingsProvider, SettingsProviderService, SettingsResolverService } from '@cloudbeaver/core-settings';
import { schema, schemaExtra } from '@cloudbeaver/core-utils';
const defaultSettings = schema.object({
'plugin.sql-editor-screen.enabled': schemaExtra.stringedBoolean().default(true),
});
type SqlEditorScreenSettingsSchema = typeof defaultSettings;
export type SqlEditorSettings = schema.infer<SqlEditorScreenSettingsSchema>;
@injectable()
export class SqlEditorScreenSettingsService extends Dependency {
get enabled(): boolean {
return this.settings.getValue('plugin.sql-editor-screen.enabled');
}
readonly settings: SettingsProvider<typeof defaultSettings>;
constructor(
private readonly settingsProviderService: SettingsProviderService,
private readonly settingsResolverService: SettingsResolverService,
) {
super();
this.settings = this.settingsProviderService.createSettings(defaultSettings);
this.settingsResolverService.addResolver(
HIGHEST_SETTINGS_LAYER,
createSettingsOverrideResolver<SqlEditorScreenSettingsSchema>(this.settingsResolverService, {
'plugin.sql-editor-screen.enabled': {
key: 'permission.sql.script.execution',
filter: value => !value,
},
}),
);
}
}
@@ -1,6 +1,6 @@
/*
* 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.
@@ -17,5 +17,6 @@ export const sqlEditorPagePluginManifest: PluginManifest = {
() => import('./LocaleService.js').then(m => m.LocaleService),
() => import('./Screen/SqlEditorScreenBootstrap.js').then(m => m.SqlEditorScreenBootstrap),
() => import('./Screen/SqlEditorScreenService.js').then(m => m.SqlEditorScreenService),
() => import('./SqlEditorScreenSettingsService.js').then(m => m.SqlEditorScreenSettingsService),
],
};