Skip to content

Commit

Permalink
Data development menu permission control (DataLinkDC#2286)
Browse files Browse the repository at this point in the history
* feat: use-service hooks

* feat: 数据开发页面菜单权限控制;
  • Loading branch information
yqwoe authored Sep 1, 2023
1 parent 5a6f768 commit bca2f9e
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dinky-web/src/components/RightContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 12 additions & 0 deletions dinky-web/src/hooks/useAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
43 changes: 27 additions & 16 deletions dinky-web/src/pages/DataStudio/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -222,6 +223,8 @@ const DataStudio = (props: any) => {
setIsModalUpdateTabContentOpen(false);
};

const access = useAccess();

return (
<PersistGate loading={null} persistor={persist}>
<div style={{ marginInline: -10, marginBlock: -5 }}>
Expand All @@ -233,7 +236,9 @@ const DataStudio = (props: any) => {
<Menu
mode='inline'
selectedKeys={[leftContainer.selectKey]}
items={LeftSide.map((x) => ({
items={LeftSide.filter((x) =>
AuthorizedObject({ path: x.auth, children: x, access })
).map((x) => ({
key: x.key,
label: x.label,
icon: x.icon
Expand All @@ -252,7 +257,9 @@ const DataStudio = (props: any) => {
<Menu
mode='inline'
selectedKeys={[bottomContainer.selectKey]}
items={LeftBottomSide.map((x) => ({
items={LeftBottomSide.filter((x) =>
AuthorizedObject({ path: x.auth, children: x, access })
).map((x) => ({
key: x.key,
label: x.label,
icon: x.icon
Expand Down Expand Up @@ -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)
}
Expand Down
17 changes: 17 additions & 0 deletions dinky-web/src/pages/DataStudio/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,21 @@ import { ReactNode } from 'react';

export const LeftSide = [
{
auth: '/datastudio/left/project',
key: 'menu.datastudio.project',
icon: <ConsoleSqlOutlined />,
label: l('menu.datastudio.project'),
children: <Project />
},
{
auth: '/datastudio/left/structure',
key: 'menu.datastudio.structure',
icon: <TableOutlined />,
label: l('menu.datastudio.structure'),
children: <div>structure</div>
},
{
auth: '/datastudio/left/metadata',
key: 'menu.datastudio.metadata',
icon: <DatabaseOutlined />,
label: l('menu.datastudio.metadata'),
Expand All @@ -77,34 +80,39 @@ export const LeftSide = [

export const RightSide: TabProp[] = [
{
auth: '/datastudio/right/jobConfig',
key: 'menu.datastudio.jobConfig',
icon: <SettingOutlined />,
label: l('menu.datastudio.jobConfig'),
children: <JobConfig />,
isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType
},
{
auth: '/datastudio/right/executeConfig',
key: 'menu.datastudio.executeConfig',
icon: <PlayCircleOutlined />,
label: l('menu.datastudio.executeConfig'),
children: <ExecuteConfig />,
isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType
},
{
auth: '/datastudio/right/savePoint',
key: 'menu.datastudio.savePoint',
icon: <FolderOutlined />,
label: l('menu.datastudio.savePoint'),
children: <SavePoints />,
isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType
},
{
auth: '/datastudio/right/historyVision',
key: 'menu.datastudio.historyVision',
icon: <HistoryOutlined />,
label: l('menu.datastudio.historyVision'),
children: <HistoryVersion />,
isShow: (type, subType) => type === TabsPageType.project && TabsPageSubType.flinkSql === subType
},
{
auth: '/datastudio/right/jobInfo',
key: 'menu.datastudio.jobInfo',
icon: <InfoCircleOutlined />,
label: l('menu.datastudio.jobInfo'),
Expand All @@ -115,44 +123,52 @@ export const RightSide: TabProp[] = [

export const LeftBottomSide = [
{
auth: '/datastudio/bottom/console',
key: 'menu.datastudio.console',
icon: <RightSquareOutlined />,
label: l('menu.datastudio.console'),
children: <Console />
},
{
auth: '/datastudio/bottom/result',
key: 'menu.datastudio.result',
icon: <MonitorOutlined />,
label: l('menu.datastudio.result'),
children: <Result />
},
{
auth: '/datastudio/bottom/bi',
key: 'menu.datastudio.bi',
icon: <BarChartOutlined />,
label: l('menu.datastudio.bi')
},
{
auth: '/datastudio/bottom/lineage',
key: 'menu.datastudio.lineage',
icon: <ApartmentOutlined />,
label: l('menu.datastudio.lineage')
},
{
auth: '/datastudio/bottom/process',
key: 'menu.datastudio.process',
icon: <DesktopOutlined />,
label: l('menu.datastudio.process')
},
{
auth: '/datastudio/bottom/history',
key: 'menu.datastudio.history',
icon: <CalendarOutlined />,
label: l('menu.datastudio.history')
},
{
auth: '/datastudio/bottom/table-data',
key: 'menu.datastudio.table-data',
icon: <TableOutlined />,
label: l('menu.datastudio.table-data'),
children: <TableData />
},
{
auth: '/datastudio/bottom/tool',
key: 'menu.datastudio.tool',
icon: <ToolOutlined />,
label: l('menu.datastudio.tool')
Expand Down Expand Up @@ -261,4 +277,5 @@ export type TabProp = {
label: string;
children: ReactNode;
isShow?: (type: TabsPageType, subType?: TabsPageSubType) => boolean;
auth?: string;
};
2 changes: 1 addition & 1 deletion dinky-web/src/pages/Other/Login/function.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
14 changes: 14 additions & 0 deletions script/sql/dinky-mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit bca2f9e

Please sign in to comment.