From e2ed65330f1dd99a797933ffcf09dd0a9269835c Mon Sep 17 00:00:00 2001 From: Aleksei Potsetsuev Date: Tue, 31 Oct 2023 11:56:10 +0100 Subject: [PATCH] CB-4112 feat: require authentication for nav-tree --- .../src/AuthenticationService.ts | 2 -- .../ElementsTree/ElementsTreeService.ts | 23 +++++++++++++++++++ .../ElementsTree/useElementsTree.ts | 10 +++++++- .../plugin-navigation-tree/src/index.ts | 1 + .../plugin-navigation-tree/src/manifest.ts | 2 ++ 5 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/ElementsTreeService.ts diff --git a/webapp/packages/plugin-authentication/src/AuthenticationService.ts b/webapp/packages/plugin-authentication/src/AuthenticationService.ts index 20ab3ebac6..c89974080a 100644 --- a/webapp/packages/plugin-authentication/src/AuthenticationService.ts +++ b/webapp/packages/plugin-authentication/src/AuthenticationService.ts @@ -214,8 +214,6 @@ export class AuthenticationService extends Bootstrap { this.authProviderService.requestAuthProvider.addHandler(this.requestAuthProviderHandler); } - load(): void {} - private async authSessionAction(data: ISessionAction | null, contexts: IExecutionContextProvider) { const action = contexts.getContext(sessionActionContext); diff --git a/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/ElementsTreeService.ts b/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/ElementsTreeService.ts new file mode 100644 index 0000000000..891de97644 --- /dev/null +++ b/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/ElementsTreeService.ts @@ -0,0 +1,23 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2023 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 { injectable } from '@cloudbeaver/core-di'; +import { Executor, type IExecutor } from '@cloudbeaver/core-executor'; + +export interface IElementsTreeLoadData { + nodeId: string; + manual: boolean; +} + +@injectable() +export class ElementsTreeService { + readonly onLoad: IExecutor; + + constructor() { + this.onLoad = new Executor(); + } +} diff --git a/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/useElementsTree.ts b/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/useElementsTree.ts index 7ef4442738..1858edc4fe 100644 --- a/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/useElementsTree.ts +++ b/webapp/packages/plugin-navigation-tree/src/NavigationTree/ElementsTree/useElementsTree.ts @@ -12,13 +12,14 @@ import { getComputed, IFolderExplorerContext, useExecutor, useObjectRef, useObse import { ConnectionInfoActiveProjectKey, ConnectionInfoResource } from '@cloudbeaver/core-connections'; import { useService } from '@cloudbeaver/core-di'; import { NotificationService } from '@cloudbeaver/core-events'; -import { ISyncExecutor, SyncExecutor } from '@cloudbeaver/core-executor'; +import { ExecutorInterrupter, ISyncExecutor, SyncExecutor } from '@cloudbeaver/core-executor'; import { type NavNode, NavNodeInfoResource, NavTreeResource, ROOT_NODE_PATH } from '@cloudbeaver/core-navigation-tree'; import { ProjectInfoResource, ProjectsService } from '@cloudbeaver/core-projects'; import { CachedMapAllKey, CachedResourceOffsetPageKey, getNextPageOffset, ResourceKeyUtils } from '@cloudbeaver/core-resource'; import type { IDNDData } from '@cloudbeaver/core-ui'; import { ILoadableState, MetadataMap, throttle } from '@cloudbeaver/core-utils'; +import { ElementsTreeService } from './ElementsTreeService'; import type { IElementsTreeAction } from './IElementsTreeAction'; import type { INavTreeNodeInfo } from './INavTreeNodeInfo'; import type { NavigationNodeRendererComponent } from './NavigationNodeComponent'; @@ -137,6 +138,7 @@ export function useElementsTree(options: IOptions): IElementsTree { const navNodeInfoResource = useService(NavNodeInfoResource); const navTreeResource = useService(NavTreeResource); const connectionInfoResource = useService(ConnectionInfoResource); + const elementsTreeService = useService(ElementsTreeService); const [localTreeNodesState] = useState( () => @@ -156,6 +158,12 @@ export function useElementsTree(options: IOptions): IElementsTree { async function handleLoadChildren(id: string, manual: boolean): Promise { try { + const context = await elementsTreeService.onLoad.execute({ nodeId: id, manual }); + + if (ExecutorInterrupter.isInterrupted(context)) { + return false; + } + return await options.loadChildren(id, manual); } catch (exception: any) { notificationService.logException(exception); diff --git a/webapp/packages/plugin-navigation-tree/src/index.ts b/webapp/packages/plugin-navigation-tree/src/index.ts index 9f2df7770f..1a763288d1 100644 --- a/webapp/packages/plugin-navigation-tree/src/index.ts +++ b/webapp/packages/plugin-navigation-tree/src/index.ts @@ -26,6 +26,7 @@ export * from './NavigationTree/ElementsTree/useElementsTree'; export * from './NavigationTree/ElementsTree/ElementsTreeTools/MENU_ELEMENTS_TREE_TOOLS'; export * from './NavigationTree/ElementsTree/ElementsTreeTools/ElementsTreeToolsMenuService'; export * from './NavigationTree/ElementsTree/elementsTreeNameFilter'; +export * from './NavigationTree/ElementsTree/ElementsTreeService'; export * from './NavigationTree/NavigationTreeBootstrap'; export * from './NavigationTree/NavigationTreeService'; export { default as ElementsTreeToolsStyles } from './NavigationTree/ElementsTree/ElementsTreeTools/ElementsTreeTools.m.css'; diff --git a/webapp/packages/plugin-navigation-tree/src/manifest.ts b/webapp/packages/plugin-navigation-tree/src/manifest.ts index a6c87d5c80..6cc907c4ec 100644 --- a/webapp/packages/plugin-navigation-tree/src/manifest.ts +++ b/webapp/packages/plugin-navigation-tree/src/manifest.ts @@ -8,6 +8,7 @@ import type { PluginManifest } from '@cloudbeaver/core-di'; import { LocaleService } from './LocaleService'; +import { ElementsTreeService } from './NavigationTree/ElementsTree/ElementsTreeService'; import { ElementsTreeToolsMenuService } from './NavigationTree/ElementsTree/ElementsTreeTools/ElementsTreeToolsMenuService'; import { ElementsTreeSettingsService } from './NavigationTree/ElementsTree/ElementsTreeTools/NavigationTreeSettings/ElementsTreeSettingsService'; import { NavigationTreeBootstrap } from './NavigationTree/NavigationTreeBootstrap'; @@ -27,5 +28,6 @@ export const navigationTreePlugin: PluginManifest = { NavNodeViewService, ElementsTreeSettingsService, NavigationTreeSettingsService, + ElementsTreeService, ], };