Merge pull request #837 from dbeaver/feat/rm

fix(plugin-resource-manager): CB-2019 check for the userId before rea…
This commit is contained in:
Alexey
2022-05-18 14:16:58 +03:00
committed by GitHub
7 changed files with 67 additions and 86 deletions
@@ -0,0 +1,5 @@
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M3 2C1.89543 2 1 2.89543 1 4V26C1 27.1046 1.89543 28 3 28H12.398C11.5066 26.3662 11 24.4923 11 22.5C11 16.1487 16.1487 11 22.5 11C25.8674 11 28.8968 12.4474 31 14.7539V7C31 5.89543 30.1046 5 29 5H17.0704C16.4017 5 15.7772 4.6658 15.4063 4.1094L14.5937 2.8906C14.2228 2.3342 13.5983 2 12.9296 2H3Z" fill="#88C7EA"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.5423 26H3L3 4L12.9296 4L13.7422 5.2188C14.484 6.3316 15.733 7 17.0704 7H29V13.0119C29.7322 13.5145 30.4034 14.0996 31 14.7539V7C31 5.89543 30.1046 5 29 5H17.0704C16.4017 5 15.7772 4.6658 15.4063 4.1094L14.5937 2.8906C14.2228 2.3342 13.5983 2 12.9296 2H3C1.89543 2 1 2.89543 1 4V26C1 27.1046 1.89543 28 3 28H12.398C12.0527 27.367 11.7651 26.698 11.5423 26Z" fill="#338ECC"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M22.3918 29.9387C22.4705 30.0204 22.6013 30.0204 22.68 29.9387L29.9066 22.4271C30.0289 22.3001 29.9388 22.0885 29.7625 22.0885L25.0708 22.0885L25.0708 17.0884L20.0708 17.0884L20.0708 22.0885L15.3084 22.0885C15.1321 22.0885 15.042 22.3001 15.1643 22.4271L22.3918 29.9387Z" fill="#338ECC"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -0,0 +1,5 @@
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M3 2C1.89543 2 1 2.89543 1 4V26C1 27.1046 1.89543 28 3 28H12.398C11.5066 26.3662 11 24.4923 11 22.5C11 16.1487 16.1487 11 22.5 11C25.8674 11 28.8968 12.4474 31 14.7539V7C31 5.89543 30.1046 5 29 5H17.0704C16.4017 5 15.7772 4.6658 15.4063 4.1094L14.5937 2.8906C14.2228 2.3342 13.5983 2 12.9296 2H3Z" fill="#88C7EA"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M11.5423 26H3L3 4L12.9296 4L13.7422 5.2188C14.484 6.3316 15.733 7 17.0704 7H29V13.0119C29.7322 13.5145 30.4034 14.0996 31 14.7539V7C31 5.89543 30.1046 5 29 5H17.0704C16.4017 5 15.7772 4.6658 15.4063 4.1094L14.5937 2.8906C14.2228 2.3342 13.5983 2 12.9296 2H3C1.89543 2 1 2.89543 1 4V26C1 27.1046 1.89543 28 3 28H12.398C12.0527 27.367 11.7651 26.698 11.5423 26Z" fill="#338ECC"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M22.679 15.1497C22.6003 15.0679 22.4695 15.0679 22.3908 15.1497L15.1642 22.6613C15.0419 22.7883 15.132 22.9999 15.3083 22.9999H20V28H25V22.9999H29.7624C29.9388 22.9999 30.0288 22.7883 29.9065 22.6612L22.679 15.1497Z" fill="#338ECC"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">
<title>load</title>
<g id="load" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Page-1" transform="translate(0.000000, 1.000000)">
<polygon id="Fill-1" fill="#338ECC" points="21.2878 22.6287 23.4968 22.6287 23.4968 29.6187 26.8088 29.6187 26.8088 22.6287 29.0178 22.6287 25.1538 18.7637"></polygon>
<g id="Group-7" transform="translate(0.000000, 0.619000)">
<g id="Group-6">
<path d="M3.1691,6.7196 L3.1691,22.5666 L15.4381,22.5666 C15.5501,17.4236 19.7461,13.2876 24.9151,13.2876 C26.1931,13.2876 27.4111,13.5446 28.5231,14.0026 L28.5231,6.7196 L3.1691,6.7196 Z" id="Fill-1" fill="#F6BC8D"></path>
<path d="M3.1687,22.5663 L3.1687,6.7193 L28.5237,6.7193 L28.5237,14.0033 C29.7247,14.4973 30.7997,15.2303 31.6927,16.1433 L31.6927,6.7193 C31.6927,4.9763 30.2667,3.5503 28.5237,3.5503 L15.8467,3.5503 L12.6777,0.3813 L3.1687,0.3813 C1.4257,0.3813 0.0157,1.8073 0.0157,3.5503 L-0.0003,22.5663 C-0.0003,24.3093 1.4257,25.7353 3.1687,25.7353 L15.9037,25.7353 C15.5977,24.8033 15.4267,23.8103 15.4267,22.7763 C15.4267,22.7053 15.4367,22.6363 15.4377,22.5663 L3.1687,22.5663 Z" id="Fill-3" fill="#F48400"></path>
</g>
</g>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.4 KiB

+5 -26
View File
@@ -1,26 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>save</title>
<defs>
<polygon id="path-1" points="0 31 30.354 31 30.354 0.646 0 0.646"></polygon>
</defs>
<g id="save" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Page-1" transform="translate(1.000000, 0.000000)">
<path d="M16.461,12.2871 L18.958,12.2871 L18.958,5.3021 L16.461,5.3021 L16.461,12.2871 Z M20.93,14.7841 L20.93,3.7071 L8.624,3.7071 L6.988,3.7071 L6.988,14.7841 L20.93,14.7841 Z" id="Fill-1" fill="#FFFFFF"></path>
<polygon id="Fill-2" fill="#A2E096" points="27.6467 9.464 23.4267 4.643 23.4267 17.281 4.4917 17.281 4.4917 3.707 2.7077 3.707 2.7077 28.647 27.6467 28.647"></polygon>
<g id="Group-13" transform="translate(0.000000, 0.354100)">
<g id="Group-5">
<mask id="mask-2" fill="white">
<use xlink:href="#path-1"></use>
</mask>
<g id="Clip-4"></g>
<path d="M2.7073,3.353 L4.4913,3.353 L4.4913,2.452 L6.9883,2.452 L6.9883,3.353 L8.6243,3.353 L20.9303,3.353 L20.9303,2.452 L23.4273,2.452 L23.4273,4.289 L27.6463,9.11 L27.6463,28.292 L2.7073,28.292 L2.7073,3.353 Z M3.0733,31 L27.2813,31 C28.9753,31 30.3543,29.615 30.3543,27.912 L30.3543,7.532 L23.8433,0.646 L3.0673,0.646 C1.3763,0.646 -0.0007,2.024 -0.0007,3.719 L-0.0007,27.927 C-0.0007,29.621 1.3783,31 3.0733,31 L3.0733,31 Z" id="Fill-3" fill="#4FA843" mask="url(#mask-2)"></path>
</g>
<polygon id="Fill-6" fill="#4FA843" points="23.427 16.9268 23.427 4.2888 22.608 3.3528 20.93 3.3528 20.93 14.4298 6.988 14.4298 6.988 3.3528 4.491 3.3528 4.491 16.9268"></polygon>
<polygon id="Fill-8" fill="#4FA843" points="23.427 4.2891 23.427 2.4521 20.93 2.4521 20.93 3.3531 22.608 3.3531"></polygon>
<polygon id="Fill-10" fill="#4FA843" points="4.491 3.353 6.988 3.353 6.988 2.452 4.491 2.452"></polygon>
<polygon id="Fill-12" fill="#4FA843" points="16.46 11.933 18.957 11.933 18.957 4.948 16.46 4.948"></polygon>
</g>
</g>
</g>
</svg>
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M2 1C1.44772 1 1 1.44772 1 2V30C1 30.5523 1.44772 31 2 31H30C30.5523 31 31 30.5523 31 30V9.59603C31 9.33082 30.8946 9.07646 30.7071 8.88893L23.1111 1.29289C22.9235 1.10536 22.6692 1 22.404 1H19C19.5523 1 20 1.44772 20 2V12C20 12.5523 19.5523 13 19 13H7C6.44772 13 6 12.5523 6 12V2C6 1.44772 6.44772 1 7 1H2Z" fill="#88C7EA"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M29 10.0102V29H3V3H6V12C6 12.5523 6.44772 13 7 13H19C19.5523 13 20 12.5523 20 12V3H21.9898L29 10.0102ZM18 3H8V11H18V3ZM19 1H22.404C22.6692 1 22.9235 1.10536 23.1111 1.29289L30.7071 8.88893C30.8946 9.07646 31 9.33082 31 9.59603V30C31 30.5523 30.5523 31 30 31H2C1.44772 31 1 30.5523 1 30V2C1 1.44772 1.44772 1 2 1H7H19Z" fill="#338ECC"/>
<rect x="13" y="5" width="3" height="4" fill="#338ECC"/>
</svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 920 B

@@ -7,7 +7,7 @@
*/
import { DATA_CONTEXT_NAV_NODE, EMainMenu, MainMenuService } from '@cloudbeaver/core-app';
import { AppAuthService } from '@cloudbeaver/core-authentication';
import { AuthInfoService } from '@cloudbeaver/core-authentication';
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { CommonDialogService, ConfirmationDialogDelete, DialogueStateResult } from '@cloudbeaver/core-dialogs';
import { SideBarPanelService } from '@cloudbeaver/core-ui';
@@ -25,7 +25,7 @@ export class PluginBootstrap extends Bootstrap {
private readonly resourceManagerService: ResourceManagerService,
private readonly sideBarPanelService: SideBarPanelService,
private readonly navResourceNodeService: NavResourceNodeService,
private readonly appAuthService: AppAuthService,
private readonly authInfoService: AuthInfoService,
private readonly commonDialogService: CommonDialogService,
private readonly actionService: ActionService,
private readonly menuService: MenuService,
@@ -41,7 +41,7 @@ export class PluginBootstrap extends Bootstrap {
order: 3,
type: 'checkbox',
title: 'plugin_resource_manager_title',
isHidden: () => !this.resourceManagerService.enabled || !this.appAuthService.authenticated,
isHidden: () => !this.resourceManagerService.enabled || !this.authInfoService.userInfo,
isChecked: () => this.resourceManagerService.panelEnabled,
onClick: this.resourceManagerService.togglePanel,
}
@@ -53,7 +53,7 @@ export class PluginBootstrap extends Bootstrap {
name: 'plugin_resource_manager_title',
isHidden: () => !this.resourceManagerService.enabled
|| !this.resourceManagerService.panelEnabled
|| !this.appAuthService.authenticated,
|| !this.authInfoService.userInfo,
onClose: this.resourceManagerService.togglePanel,
panel: () => ResourceManager,
});
@@ -9,6 +9,7 @@
import { makeObservable, observable } from 'mobx';
import { ITab, NavigationTabsService, NavTreeResource, NodeManagerUtils } from '@cloudbeaver/core-app';
import { UserInfoResource } from '@cloudbeaver/core-authentication';
import { injectable } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
import { WindowEventsService } from '@cloudbeaver/core-root';
@@ -44,6 +45,7 @@ export class SqlEditorTabResourceService {
private readonly resourceManagerService: ResourceManagerService,
private readonly windowEventsService: WindowEventsService,
private readonly localStorageSaveService: LocalStorageSaveService,
private readonly userInfoResource: UserInfoResource
) {
this.state = new Map();
@@ -112,38 +114,27 @@ export class SqlEditorTabResourceService {
return null;
}
private onTabResourceValueChangeHandler(data: IQueryChangeData) {
if (data.prevQuery !== data.query) {
this.updateResource(data.query);
}
}
private async updateResource(value: string) {
if (!this.resourceManagerService.enabled) {
private async onTabResourceValueChangeHandler(data: IQueryChangeData) {
const tabId = this.navigationTabsService.currentTab?.id;
if (!tabId) {
return;
}
const currentTab = this.navigationTabsService.currentTab;
if (currentTab && this.state.has(currentTab.id)) {
const state = this.state.get(currentTab.id)!;
try {
await this.navResourceNodeService.write(state.nodeId, value);
} catch (exception) {
this.notificationService.logException(exception as any, 'plugin_resource_manager_update_script_error');
}
const tab = this.getTab(tabId);
if (tab && data.prevQuery !== data.query) {
await this.updateResource(tab, data.query);
}
}
private onFocusChangeHandler(focused: boolean) {
private async onFocusChangeHandler(focused: boolean) {
if (focused) {
this.syncCurrentTab();
await this.syncCurrentTab();
}
}
private onTabSelectHandler(tab: ITab) {
private async onTabSelectHandler(tab: ITab) {
if (isSQLEditorTab(tab)) {
this.updateTabQuery(tab);
await this.updateTabQuery(tab);
}
}
@@ -166,42 +157,58 @@ export class SqlEditorTabResourceService {
});
}
private getTab(tabId: string) {
return this.sqlEditorTabService.sqlEditorTabs.find(tab => tab.id === tabId);
}
private closeTab(tabId: string) {
this.navigationTabsService.closeTab(tabId);
}
private async syncCurrentTab() {
const current = this.sqlEditorTabService.sqlEditorTabs.find(
tab => tab.id === this.navigationTabsService.currentTabId
);
const tab = this.getTab(this.navigationTabsService.currentTabId);
if (current) {
await this.updateTabQuery(current);
if (tab) {
await this.updateTabQuery(tab);
}
}
private async updateTabQuery(tab: ITab<ISqlEditorTabState>) {
if (!this.resourceManagerService.enabled) {
private handleNotFound(tab: ITab<ISqlEditorTabState>) {
this.notificationService.logInfo({
title: 'plugin_resource_manager_script_not_found_title',
message: tab.handlerState.name,
persistent: true,
});
this.unlinkTab(tab.id);
}
private async updateResource(tab: ITab<ISqlEditorTabState>, value: string) {
const state = this.state.get(tab.id);
if (!this.resourceManagerService.enabled || !state || this.userInfoResource.getId() !== tab.userId) {
return;
}
try {
const state = this.state.get(tab.id);
await this.navResourceNodeService.write(state.nodeId, value);
} catch (exception) {
this.notificationService.logException(exception as any, 'plugin_resource_manager_update_script_error');
}
}
if (!state) {
return;
}
private async updateTabQuery(tab: ITab<ISqlEditorTabState>) {
const state = this.state.get(tab.id);
if (!this.resourceManagerService.enabled || !state || this.userInfoResource.getId() !== tab.userId) {
return;
}
try {
const found = await this.navTreeResource.preloadNodeParents(state.parents, state.nodeId);
if (!found) {
this.notificationService.logInfo({
title: 'plugin_resource_manager_script_not_found_title',
message: tab.handlerState.name,
persistent: true,
});
this.unlinkTab(tab.id);
this.handleNotFound(tab);
return;
}
@@ -205,7 +205,7 @@ export const SqlEditor = observer<ISqlEditorProps>(function SqlEditor({ state, c
hidden={data.activeSegmentMode.activeSegmentMode}
onClick={() => tools.downloadScript(trimmedValue)}
>
<StaticImage icon='/icons/save.svg' />
<StaticImage icon='/icons/export.svg' />
</button>
{!data.activeSegmentMode.activeSegmentMode && (
<UploadArea
@@ -215,7 +215,7 @@ export const SqlEditor = observer<ISqlEditorProps>(function SqlEditor({ state, c
onChange={handleScriptUpload}
>
<upload>
<StaticImage icon='/icons/load.svg' />
<StaticImage icon='/icons/import.svg' />
</upload>
</UploadArea>
)}