diff --git a/dinky-web/src/components/RightContent/index.tsx b/dinky-web/src/components/RightContent/index.tsx index 28211c1cea..fe4b0b15a1 100644 --- a/dinky-web/src/components/RightContent/index.tsx +++ b/dinky-web/src/components/RightContent/index.tsx @@ -24,7 +24,7 @@ import { FullscreenExitOutlined, FullscreenOutlined, GlobalOutlined } from '@ant import { useEmotionCss } from '@ant-design/use-emotion-css'; import { SelectLang, useModel } from '@umijs/max'; import { Space, Switch, Tooltip } from 'antd'; -import React, { useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import useCookie from 'react-use-cookie'; import screenfull from 'screenfull'; import Avatar from './AvatarDropdown'; diff --git a/dinky-web/src/hooks/useAccess.tsx b/dinky-web/src/hooks/useAccess.tsx index d6bdef11c0..2b1ca10cac 100644 --- a/dinky-web/src/hooks/useAccess.tsx +++ b/dinky-web/src/hooks/useAccess.tsx @@ -65,3 +65,15 @@ export const AccessContextProvider = ({ }; export const useAccess = () => useContext(AccessContext); + +export function AuthorizedObject({ path, denied = null, children = null,access = {} }: any) { + const { isAdmin, blocks = [] } = access; + + if (isAdmin) return children; + + if (!blocks.length) return denied; + + const authority = blocks.some((block) => block.path === path); + + return authority ? children : denied; +} diff --git a/dinky-web/src/pages/DataStudio/index.tsx b/dinky-web/src/pages/DataStudio/index.tsx index a3fe3754df..7cc5945eea 100644 --- a/dinky-web/src/pages/DataStudio/index.tsx +++ b/dinky-web/src/pages/DataStudio/index.tsx @@ -15,6 +15,7 @@ * limitations under the License. */ +import { AuthorizedObject, useAccess } from '@/hooks/useAccess'; import useThemeValue from '@/hooks/useThemeValue'; import BottomContainer from '@/pages/DataStudio/BottomContainer'; import { getConsoleData } from '@/pages/DataStudio/BottomContainer/Console/service'; @@ -222,6 +223,8 @@ const DataStudio = (props: any) => { setIsModalUpdateTabContentOpen(false); }; + const access = useAccess(); + return (
@@ -233,7 +236,9 @@ const DataStudio = (props: any) => { ({ + items={LeftSide.filter((x) => + AuthorizedObject({ path: x.auth, children: x, access }) + ).map((x) => ({ key: x.key, label: x.label, icon: x.icon @@ -252,7 +257,9 @@ const DataStudio = (props: any) => { ({ + items={LeftBottomSide.filter((x) => + AuthorizedObject({ path: x.auth, children: x, access }) + ).map((x) => ({ key: x.key, label: x.label, icon: x.icon @@ -319,20 +326,24 @@ const DataStudio = (props: any) => { borderInlineStart: `1px solid ${themeValue.borderColor}`, borderBlockStart: `1px solid ${themeValue.borderColor}` }} - items={RightSide.filter((x) => { - if (!x.isShow) { - return true; - } - if (parseInt(tabs.activeKey) < 0) { - return TabsPageType.None; - } - const v = (tabs.panes as TabsItemType[]).find( - (item) => item.key === tabs.activeKey - ); - return x.isShow(v?.type ?? TabsPageType.None, v?.subType); - }).map((x) => { - return { key: x.key, label: x.label, icon: x.icon }; - })} + items={RightSide.filter((x) => + AuthorizedObject({ path: x.auth, children: x, access }) + ) + .filter((x) => { + if (!x.isShow) { + return true; + } + if (parseInt(tabs.activeKey) < 0) { + return TabsPageType.None; + } + const v = (tabs.panes as TabsItemType[]).find( + (item) => item.key === tabs.activeKey + ); + return x.isShow(v?.type ?? TabsPageType.None, v?.subType); + }) + .map((x) => { + return { key: x.key, label: x.label, icon: x.icon }; + })} onClick={(item) => updateSelectRightKey(item.key === rightContainer.selectKey ? '' : item.key) } diff --git a/dinky-web/src/pages/DataStudio/route.tsx b/dinky-web/src/pages/DataStudio/route.tsx index 9d5aebf1fb..393c6e0459 100644 --- a/dinky-web/src/pages/DataStudio/route.tsx +++ b/dinky-web/src/pages/DataStudio/route.tsx @@ -56,18 +56,21 @@ import { ReactNode } from 'react'; export const LeftSide = [ { + auth: '/datastudio/left/project', key: 'menu.datastudio.project', icon: , label: l('menu.datastudio.project'), children: }, { + auth: '/datastudio/left/structure', key: 'menu.datastudio.structure', icon: , label: l('menu.datastudio.structure'), children:
structure
}, { + auth: '/datastudio/left/metadata', key: 'menu.datastudio.metadata', icon: , label: l('menu.datastudio.metadata'), @@ -77,6 +80,7 @@ export const LeftSide = [ export const RightSide: TabProp[] = [ { + auth: '/datastudio/right/jobConfig', key: 'menu.datastudio.jobConfig', icon: , label: l('menu.datastudio.jobConfig'), @@ -84,6 +88,7 @@ export const RightSide: TabProp[] = [ isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType }, { + auth: '/datastudio/right/executeConfig', key: 'menu.datastudio.executeConfig', icon: , label: l('menu.datastudio.executeConfig'), @@ -91,6 +96,7 @@ export const RightSide: TabProp[] = [ isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType }, { + auth: '/datastudio/right/savePoint', key: 'menu.datastudio.savePoint', icon: , label: l('menu.datastudio.savePoint'), @@ -98,6 +104,7 @@ export const RightSide: TabProp[] = [ isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType }, { + auth: '/datastudio/right/historyVision', key: 'menu.datastudio.historyVision', icon: , label: l('menu.datastudio.historyVision'), @@ -105,6 +112,7 @@ export const RightSide: TabProp[] = [ isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType }, { + auth: '/datastudio/right/jobInfo', key: 'menu.datastudio.jobInfo', icon: , label: l('menu.datastudio.jobInfo'), @@ -115,44 +123,52 @@ export const RightSide: TabProp[] = [ export const LeftBottomSide = [ { + auth: '/datastudio/bottom/console', key: 'menu.datastudio.console', icon: , label: l('menu.datastudio.console'), children: }, { + auth: '/datastudio/bottom/result', key: 'menu.datastudio.result', icon: , label: l('menu.datastudio.result'), children: }, { + auth: '/datastudio/bottom/bi', key: 'menu.datastudio.bi', icon: , label: l('menu.datastudio.bi') }, { + auth: '/datastudio/bottom/lineage', key: 'menu.datastudio.lineage', icon: , label: l('menu.datastudio.lineage') }, { + auth: '/datastudio/bottom/process', key: 'menu.datastudio.process', icon: , label: l('menu.datastudio.process') }, { + auth: '/datastudio/bottom/history', key: 'menu.datastudio.history', icon: , label: l('menu.datastudio.history') }, { + auth: '/datastudio/bottom/table-data', key: 'menu.datastudio.table-data', icon: , label: l('menu.datastudio.table-data'), children: }, { + auth: '/datastudio/bottom/tool', key: 'menu.datastudio.tool', icon: , label: l('menu.datastudio.tool') @@ -261,4 +277,5 @@ export type TabProp = { label: string; children: ReactNode; isShow?: (type: TabsPageType, subType?: TabsPageSubType) => boolean; + auth?: string; }; diff --git a/dinky-web/src/pages/Other/Login/function.tsx b/dinky-web/src/pages/Other/Login/function.tsx index 5fda273a8a..d2384d0048 100644 --- a/dinky-web/src/pages/Other/Login/function.tsx +++ b/dinky-web/src/pages/Other/Login/function.tsx @@ -24,7 +24,7 @@ export const gotoRedirectUrl = () => { if (!history) return; setTimeout(() => { const urlParams = new URL(window.location.href).searchParams; - history.push(urlParams.get('redirect') || '/'); + window.location.href = urlParams.get('redirect') || '/' ; }, 10); }; diff --git a/script/sql/dinky-mysql.sql b/script/sql/dinky-mysql.sql index 58515e5d80..47e0de7a47 100644 --- a/script/sql/dinky-mysql.sql +++ b/script/sql/dinky-mysql.sql @@ -1198,6 +1198,20 @@ INSERT INTO `dinky_sys_menu` VALUES (30, 9, 'cluster-config', '/registration/clu INSERT INTO `dinky_sys_menu` VALUES (31, 12, 'instance', '/registration/alert/instance', './RegCenter/Alert/AlertInstance', null, null, 'C', 0, 15, '2023-08-11 14:06:55', '2023-08-18 17:09:39', null); INSERT INTO `dinky_sys_menu` VALUES (32, 1, '作业监控', '/home/jobOverView', 'JobOverView', 'show', 'AntCloudOutlined', 'F', 0, 2, '2023-08-15 16:52:59', '2023-08-18 17:09:39', null); INSERT INTO `dinky_sys_menu` VALUES (33, 1, '数据开发', '/home/devOverView', 'DevOverView', 'show', 'AimOutlined', 'F', 0, 3, '2023-08-15 16:54:47', '2023-08-18 17:09:39', null); +INSERT INTO `dinky_sys_menu` VALUES (34, 5, '项目列表', '/datastudio/left/project', NULL, NULL, NULL, 'F', 0, 1, '2023-09-01 18:00:39', '2023-09-02 00:51:06', NULL); +INSERT INTO `dinky_sys_menu` VALUES (35, 5, '元数据', '/datastudio/left/metadata', NULL, NULL, NULL, 'F', 0, 2, '2023-09-01 18:01:09', '2023-09-02 00:51:12', NULL); +INSERT INTO `dinky_sys_menu` VALUES (36, 5, '结构', '/datastudio/left/structure', NULL, NULL, NULL, 'F', 0, 3, '2023-09-01 18:01:30', '2023-09-02 00:51:26', NULL); +INSERT INTO `dinky_sys_menu` VALUES (37, 5, '作业配置', '/datastudio/right/jobConfig', NULL, NULL, NULL, 'F', 0, 4, '2023-09-01 18:02:15', '2023-09-02 00:51:32', NULL); +INSERT INTO `dinky_sys_menu` VALUES (38, 5, '执行配置', '/datastudio/right/executeConfig', NULL, NULL, NULL, 'F', 0, 5, '2023-09-01 18:03:08', '2023-09-02 00:51:38', NULL); +INSERT INTO `dinky_sys_menu` VALUES (39, 5, '版本历史', '/datastudio/right/historyVision', NULL, NULL, NULL, 'F', 0, 6, '2023-09-01 18:03:29', '2023-09-02 00:51:56', NULL); +INSERT INTO `dinky_sys_menu` VALUES (40, 5, '保存点', '/datastudio/right/savePoint', NULL, NULL, NULL, 'F', 0, 7, '2023-09-01 18:03:58', '2023-09-02 00:51:47', NULL); +INSERT INTO `dinky_sys_menu` VALUES (41, 5, '作业信息', '/datastudio/right/jobInfo', NULL, NULL, NULL, 'F', 0, 8, '2023-09-01 18:04:31', '2023-09-02 00:52:06', NULL); +INSERT INTO `dinky_sys_menu` VALUES (42, 5, '控制台', '/datastudio/bottom/console', NULL, NULL, NULL, 'F', 0, 9, '2023-09-01 18:04:56', '2023-09-01 18:04:56', NULL); +INSERT INTO `dinky_sys_menu` VALUES (43, 5, '结果', '/datastudio/bottom/result', NULL, NULL, NULL, 'F', 0, 10, '2023-09-01 18:05:16', '2023-09-01 18:05:16', NULL); +INSERT INTO `dinky_sys_menu` VALUES (44, 5, 'BI', '/datastudio/bottom/bi', NULL, NULL, NULL, 'F', 0, 11, '2023-09-01 18:05:43', '2023-09-01 18:05:43', NULL); +INSERT INTO `dinky_sys_menu` VALUES (45, 5, '血缘', '/datastudio/bottom/lineage', NULL, NULL, NULL, 'F', 0, 12, '2023-09-01 18:07:15', '2023-09-02 00:52:12', NULL); +INSERT INTO `dinky_sys_menu` VALUES (46, 5, '表数据监控', '/datastudio/bottom/process', NULL, NULL, NULL, 'F', 0, 13, '2023-09-01 18:07:55', '2023-09-02 00:52:21', NULL); +INSERT INTO `dinky_sys_menu` VALUES (47, 5, '小工具', '/datastudio/bottom/tool', NULL, NULL, NULL, 'F', 0, 14, '2023-09-01 18:08:18', '2023-09-01 18:08:18', NULL); COMMIT;