Unverified Commit bca2f9e3 authored by yqwoe's avatar yqwoe Committed by GitHub

Data development menu permission control (#2286)

* feat: use-service hooks * feat: 数据开发页面菜单权限控制;
parent 5a6f768b
...@@ -24,7 +24,7 @@ import { FullscreenExitOutlined, FullscreenOutlined, GlobalOutlined } from '@ant ...@@ -24,7 +24,7 @@ import { FullscreenExitOutlined, FullscreenOutlined, GlobalOutlined } from '@ant
import { useEmotionCss } from '@ant-design/use-emotion-css'; import { useEmotionCss } from '@ant-design/use-emotion-css';
import { SelectLang, useModel } from '@umijs/max'; import { SelectLang, useModel } from '@umijs/max';
import { Space, Switch, Tooltip } from 'antd'; 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 useCookie from 'react-use-cookie';
import screenfull from 'screenfull'; import screenfull from 'screenfull';
import Avatar from './AvatarDropdown'; import Avatar from './AvatarDropdown';
......
...@@ -65,3 +65,15 @@ export const AccessContextProvider = ({ ...@@ -65,3 +65,15 @@ export const AccessContextProvider = ({
}; };
export const useAccess = () => useContext(AccessContext); 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;
}
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { AuthorizedObject, useAccess } from '@/hooks/useAccess';
import useThemeValue from '@/hooks/useThemeValue'; import useThemeValue from '@/hooks/useThemeValue';
import BottomContainer from '@/pages/DataStudio/BottomContainer'; import BottomContainer from '@/pages/DataStudio/BottomContainer';
import { getConsoleData } from '@/pages/DataStudio/BottomContainer/Console/service'; import { getConsoleData } from '@/pages/DataStudio/BottomContainer/Console/service';
...@@ -222,6 +223,8 @@ const DataStudio = (props: any) => { ...@@ -222,6 +223,8 @@ const DataStudio = (props: any) => {
setIsModalUpdateTabContentOpen(false); setIsModalUpdateTabContentOpen(false);
}; };
const access = useAccess();
return ( return (
<PersistGate loading={null} persistor={persist}> <PersistGate loading={null} persistor={persist}>
<div style={{ marginInline: -10, marginBlock: -5 }}> <div style={{ marginInline: -10, marginBlock: -5 }}>
...@@ -233,7 +236,9 @@ const DataStudio = (props: any) => { ...@@ -233,7 +236,9 @@ const DataStudio = (props: any) => {
<Menu <Menu
mode='inline' mode='inline'
selectedKeys={[leftContainer.selectKey]} selectedKeys={[leftContainer.selectKey]}
items={LeftSide.map((x) => ({ items={LeftSide.filter((x) =>
AuthorizedObject({ path: x.auth, children: x, access })
).map((x) => ({
key: x.key, key: x.key,
label: x.label, label: x.label,
icon: x.icon icon: x.icon
...@@ -252,7 +257,9 @@ const DataStudio = (props: any) => { ...@@ -252,7 +257,9 @@ const DataStudio = (props: any) => {
<Menu <Menu
mode='inline' mode='inline'
selectedKeys={[bottomContainer.selectKey]} selectedKeys={[bottomContainer.selectKey]}
items={LeftBottomSide.map((x) => ({ items={LeftBottomSide.filter((x) =>
AuthorizedObject({ path: x.auth, children: x, access })
).map((x) => ({
key: x.key, key: x.key,
label: x.label, label: x.label,
icon: x.icon icon: x.icon
...@@ -319,7 +326,10 @@ const DataStudio = (props: any) => { ...@@ -319,7 +326,10 @@ const DataStudio = (props: any) => {
borderInlineStart: `1px solid ${themeValue.borderColor}`, borderInlineStart: `1px solid ${themeValue.borderColor}`,
borderBlockStart: `1px solid ${themeValue.borderColor}` borderBlockStart: `1px solid ${themeValue.borderColor}`
}} }}
items={RightSide.filter((x) => { items={RightSide.filter((x) =>
AuthorizedObject({ path: x.auth, children: x, access })
)
.filter((x) => {
if (!x.isShow) { if (!x.isShow) {
return true; return true;
} }
...@@ -330,7 +340,8 @@ const DataStudio = (props: any) => { ...@@ -330,7 +340,8 @@ const DataStudio = (props: any) => {
(item) => item.key === tabs.activeKey (item) => item.key === tabs.activeKey
); );
return x.isShow(v?.type ?? TabsPageType.None, v?.subType); return x.isShow(v?.type ?? TabsPageType.None, v?.subType);
}).map((x) => { })
.map((x) => {
return { key: x.key, label: x.label, icon: x.icon }; return { key: x.key, label: x.label, icon: x.icon };
})} })}
onClick={(item) => onClick={(item) =>
......
...@@ -56,18 +56,21 @@ import { ReactNode } from 'react'; ...@@ -56,18 +56,21 @@ import { ReactNode } from 'react';
export const LeftSide = [ export const LeftSide = [
{ {
auth: '/datastudio/left/project',
key: 'menu.datastudio.project', key: 'menu.datastudio.project',
icon: <ConsoleSqlOutlined />, icon: <ConsoleSqlOutlined />,
label: l('menu.datastudio.project'), label: l('menu.datastudio.project'),
children: <Project /> children: <Project />
}, },
{ {
auth: '/datastudio/left/structure',
key: 'menu.datastudio.structure', key: 'menu.datastudio.structure',
icon: <TableOutlined />, icon: <TableOutlined />,
label: l('menu.datastudio.structure'), label: l('menu.datastudio.structure'),
children: <div>structure</div> children: <div>structure</div>
}, },
{ {
auth: '/datastudio/left/metadata',
key: 'menu.datastudio.metadata', key: 'menu.datastudio.metadata',
icon: <DatabaseOutlined />, icon: <DatabaseOutlined />,
label: l('menu.datastudio.metadata'), label: l('menu.datastudio.metadata'),
...@@ -77,6 +80,7 @@ export const LeftSide = [ ...@@ -77,6 +80,7 @@ export const LeftSide = [
export const RightSide: TabProp[] = [ export const RightSide: TabProp[] = [
{ {
auth: '/datastudio/right/jobConfig',
key: 'menu.datastudio.jobConfig', key: 'menu.datastudio.jobConfig',
icon: <SettingOutlined />, icon: <SettingOutlined />,
label: l('menu.datastudio.jobConfig'), label: l('menu.datastudio.jobConfig'),
...@@ -84,6 +88,7 @@ export const RightSide: TabProp[] = [ ...@@ -84,6 +88,7 @@ export const RightSide: TabProp[] = [
isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType
}, },
{ {
auth: '/datastudio/right/executeConfig',
key: 'menu.datastudio.executeConfig', key: 'menu.datastudio.executeConfig',
icon: <PlayCircleOutlined />, icon: <PlayCircleOutlined />,
label: l('menu.datastudio.executeConfig'), label: l('menu.datastudio.executeConfig'),
...@@ -91,6 +96,7 @@ export const RightSide: TabProp[] = [ ...@@ -91,6 +96,7 @@ export const RightSide: TabProp[] = [
isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType
}, },
{ {
auth: '/datastudio/right/savePoint',
key: 'menu.datastudio.savePoint', key: 'menu.datastudio.savePoint',
icon: <FolderOutlined />, icon: <FolderOutlined />,
label: l('menu.datastudio.savePoint'), label: l('menu.datastudio.savePoint'),
...@@ -98,6 +104,7 @@ export const RightSide: TabProp[] = [ ...@@ -98,6 +104,7 @@ export const RightSide: TabProp[] = [
isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType
}, },
{ {
auth: '/datastudio/right/historyVision',
key: 'menu.datastudio.historyVision', key: 'menu.datastudio.historyVision',
icon: <HistoryOutlined />, icon: <HistoryOutlined />,
label: l('menu.datastudio.historyVision'), label: l('menu.datastudio.historyVision'),
...@@ -105,6 +112,7 @@ export const RightSide: TabProp[] = [ ...@@ -105,6 +112,7 @@ export const RightSide: TabProp[] = [
isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType
}, },
{ {
auth: '/datastudio/right/jobInfo',
key: 'menu.datastudio.jobInfo', key: 'menu.datastudio.jobInfo',
icon: <InfoCircleOutlined />, icon: <InfoCircleOutlined />,
label: l('menu.datastudio.jobInfo'), label: l('menu.datastudio.jobInfo'),
...@@ -115,44 +123,52 @@ export const RightSide: TabProp[] = [ ...@@ -115,44 +123,52 @@ export const RightSide: TabProp[] = [
export const LeftBottomSide = [ export const LeftBottomSide = [
{ {
auth: '/datastudio/bottom/console',
key: 'menu.datastudio.console', key: 'menu.datastudio.console',
icon: <RightSquareOutlined />, icon: <RightSquareOutlined />,
label: l('menu.datastudio.console'), label: l('menu.datastudio.console'),
children: <Console /> children: <Console />
}, },
{ {
auth: '/datastudio/bottom/result',
key: 'menu.datastudio.result', key: 'menu.datastudio.result',
icon: <MonitorOutlined />, icon: <MonitorOutlined />,
label: l('menu.datastudio.result'), label: l('menu.datastudio.result'),
children: <Result /> children: <Result />
}, },
{ {
auth: '/datastudio/bottom/bi',
key: 'menu.datastudio.bi', key: 'menu.datastudio.bi',
icon: <BarChartOutlined />, icon: <BarChartOutlined />,
label: l('menu.datastudio.bi') label: l('menu.datastudio.bi')
}, },
{ {
auth: '/datastudio/bottom/lineage',
key: 'menu.datastudio.lineage', key: 'menu.datastudio.lineage',
icon: <ApartmentOutlined />, icon: <ApartmentOutlined />,
label: l('menu.datastudio.lineage') label: l('menu.datastudio.lineage')
}, },
{ {
auth: '/datastudio/bottom/process',
key: 'menu.datastudio.process', key: 'menu.datastudio.process',
icon: <DesktopOutlined />, icon: <DesktopOutlined />,
label: l('menu.datastudio.process') label: l('menu.datastudio.process')
}, },
{ {
auth: '/datastudio/bottom/history',
key: 'menu.datastudio.history', key: 'menu.datastudio.history',
icon: <CalendarOutlined />, icon: <CalendarOutlined />,
label: l('menu.datastudio.history') label: l('menu.datastudio.history')
}, },
{ {
auth: '/datastudio/bottom/table-data',
key: 'menu.datastudio.table-data', key: 'menu.datastudio.table-data',
icon: <TableOutlined />, icon: <TableOutlined />,
label: l('menu.datastudio.table-data'), label: l('menu.datastudio.table-data'),
children: <TableData /> children: <TableData />
}, },
{ {
auth: '/datastudio/bottom/tool',
key: 'menu.datastudio.tool', key: 'menu.datastudio.tool',
icon: <ToolOutlined />, icon: <ToolOutlined />,
label: l('menu.datastudio.tool') label: l('menu.datastudio.tool')
...@@ -261,4 +277,5 @@ export type TabProp = { ...@@ -261,4 +277,5 @@ export type TabProp = {
label: string; label: string;
children: ReactNode; children: ReactNode;
isShow?: (type: TabsPageType, subType?: TabsPageSubType) => boolean; isShow?: (type: TabsPageType, subType?: TabsPageSubType) => boolean;
auth?: string;
}; };
...@@ -24,7 +24,7 @@ export const gotoRedirectUrl = () => { ...@@ -24,7 +24,7 @@ export const gotoRedirectUrl = () => {
if (!history) return; if (!history) return;
setTimeout(() => { setTimeout(() => {
const urlParams = new URL(window.location.href).searchParams; const urlParams = new URL(window.location.href).searchParams;
history.push(urlParams.get('redirect') || '/'); window.location.href = urlParams.get('redirect') || '/' ;
}, 10); }, 10);
}; };
......
...@@ -1198,6 +1198,20 @@ INSERT INTO `dinky_sys_menu` VALUES (30, 9, 'cluster-config', '/registration/clu ...@@ -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 (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 (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 (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; COMMIT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment