From cf5d253d5f5b18dd77be1ee6a4b6b30569409045 Mon Sep 17 00:00:00 2001 From: labbomb <739955946@qq.com> Date: Mon, 14 Feb 2022 12:00:17 +0800 Subject: [PATCH] Adding Rights Management (#8368) --- .../src/layouts/content/index.tsx | 18 +++++----- .../src/layouts/content/use-dataList.ts | 21 ++++++----- dolphinscheduler-ui-next/src/router/index.ts | 14 ++++++-- .../src/router/modules/data-quality.ts | 6 ++-- .../src/router/modules/datasource.ts | 3 +- .../src/router/modules/monitor.ts | 15 +++++--- .../src/router/modules/projects.ts | 36 ++++++++++++------- .../src/router/modules/resources.ts | 33 +++++++++++------ .../src/router/modules/security.ts | 24 ++++++++----- dolphinscheduler-ui-next/src/router/routes.ts | 14 +++++--- 10 files changed, 119 insertions(+), 65 deletions(-) diff --git a/dolphinscheduler-ui-next/src/layouts/content/index.tsx b/dolphinscheduler-ui-next/src/layouts/content/index.tsx index ad0e83d6d7..9aa5602d51 100644 --- a/dolphinscheduler-ui-next/src/layouts/content/index.tsx +++ b/dolphinscheduler-ui-next/src/layouts/content/index.tsx @@ -42,16 +42,8 @@ const Content = defineComponent({ } = useDataList() const sideKeyRef = ref() - locale.value = localesStore.getLocales - onMounted(() => { - changeMenuOption(state) - changeHeaderMenuOptions(state) - getSideMenu(state) - changeUserDropdown(state) - }) - - watch(useI18n().locale, () => { + locale.value = localesStore.getLocales changeMenuOption(state) changeHeaderMenuOptions(state) getSideMenu(state) @@ -71,12 +63,18 @@ const Content = defineComponent({ getSideMenu(state) } + watch(useI18n().locale, () => { + changeMenuOption(state) + changeHeaderMenuOptions(state) + getSideMenu(state) + changeUserDropdown(state) + }) + watch( () => route.path, () => { if (route.path !== '/login') { state.isShowSide = menuStore.getShowSideStatus - route.matched[1].path.includes(':projectCode') if (route.matched[1].path === '/projects/:projectCode') { changeMenuOption(state) getSideMenu(state) diff --git a/dolphinscheduler-ui-next/src/layouts/content/use-dataList.ts b/dolphinscheduler-ui-next/src/layouts/content/use-dataList.ts index b2aa0cb40a..69c5f8485c 100644 --- a/dolphinscheduler-ui-next/src/layouts/content/use-dataList.ts +++ b/dolphinscheduler-ui-next/src/layouts/content/use-dataList.ts @@ -48,10 +48,13 @@ import { BarsOutlined } from '@vicons/antd' import { useMenuStore } from '@/store/menu/menu' +import { useUserStore } from '@/store/user/user' +import type { UserInfoRes } from '@/service/modules/users/types' export function useDataList() { const { t } = useI18n() const menuStore = useMenuStore() + const userStore = useUserStore() const renderIcon = (icon: any) => { return () => h(NIcon, null, { default: () => h(icon) }) @@ -82,14 +85,12 @@ export function useDataList() { { label: t('menu.home'), key: 'home', - icon: renderIcon(HomeOutlined), - isShowSide: false + icon: renderIcon(HomeOutlined) }, { label: t('menu.project'), key: 'projects', icon: renderIcon(ProfileOutlined), - isShowSide: false, children: [ { label: t('menu.project_overview'), @@ -136,7 +137,6 @@ export function useDataList() { label: t('menu.resources'), key: 'resource', icon: renderIcon(FolderOutlined), - isShowSide: true, children: [ { label: t('menu.file_manage'), @@ -179,7 +179,6 @@ export function useDataList() { label: t('menu.data_quality'), key: 'data-quality', icon: renderIcon(ContainerOutlined), - isShowSide: true, children: [ { label: t('menu.task_result'), @@ -197,14 +196,12 @@ export function useDataList() { label: t('menu.datasource'), key: 'datasource', icon: renderIcon(DatabaseOutlined), - isShowSide: false, children: [] }, { label: t('menu.monitor'), key: 'monitor', icon: renderIcon(DesktopOutlined), - isShowSide: true, children: [ { label: t('menu.service_manage'), @@ -246,8 +243,8 @@ export function useDataList() { label: t('menu.security'), key: 'security', icon: renderIcon(SafetyCertificateOutlined), - isShowSide: true, - children: [ + children: + (userStore.getUserInfo as UserInfoRes).userType === 'ADMIN_USER' ? [ { label: t('menu.tenant_manage'), key: `/security/tenant-manage`, @@ -288,6 +285,12 @@ export function useDataList() { key: `/security/token-manage`, icon: renderIcon(SafetyOutlined) } + ] : [ + { + label: t('menu.token_manage'), + key: `/security/token-manage`, + icon: renderIcon(SafetyOutlined) + } ] } ] diff --git a/dolphinscheduler-ui-next/src/router/index.ts b/dolphinscheduler-ui-next/src/router/index.ts index eb4c8b183a..6b3e4861cb 100644 --- a/dolphinscheduler-ui-next/src/router/index.ts +++ b/dolphinscheduler-ui-next/src/router/index.ts @@ -24,6 +24,8 @@ import { import routes from './routes' import { useMenuStore } from '@/store/menu/menu' +import { useUserStore } from '@/store/user/user' +import type { UserInfoRes } from '@/service/modules/users/types' // NProgress import NProgress from 'nprogress' @@ -36,7 +38,8 @@ const router = createRouter({ interface metaData { title?: string - showSide?: boolean + showSide?: boolean, + auth?: Array } /** @@ -50,9 +53,16 @@ router.beforeEach( ) => { NProgress.start() const menuStore = useMenuStore() + const userStore = useUserStore() const metaData: metaData = to.meta menuStore.setShowSideStatus(metaData.showSide || false) - next() + if (metaData.auth?.includes('ADMIN_USER') && (userStore.getUserInfo as UserInfoRes).userType !== 'ADMIN_USER' && menuStore.getMenuKey === 'security') { + to.fullPath = '/security/token-manage' + next({name: 'token-manage'}) + } else { + next() + } + NProgress.done() } ) diff --git a/dolphinscheduler-ui-next/src/router/modules/data-quality.ts b/dolphinscheduler-ui-next/src/router/modules/data-quality.ts index e154ccc475..67ccc0a07e 100644 --- a/dolphinscheduler-ui-next/src/router/modules/data-quality.ts +++ b/dolphinscheduler-ui-next/src/router/modules/data-quality.ts @@ -35,7 +35,8 @@ export default { component: components['data-quality-task-result'], meta: { title: '数据质量-task-result', - showSide: true + showSide: true, + auth: [] } }, { @@ -44,7 +45,8 @@ export default { component: components['data-quality-rule'], meta: { title: '数据质量-rule', - showSide: true + showSide: true, + auth: [] } } ] diff --git a/dolphinscheduler-ui-next/src/router/modules/datasource.ts b/dolphinscheduler-ui-next/src/router/modules/datasource.ts index f25e00b0fc..1c39c5db87 100644 --- a/dolphinscheduler-ui-next/src/router/modules/datasource.ts +++ b/dolphinscheduler-ui-next/src/router/modules/datasource.ts @@ -34,7 +34,8 @@ export default { component: components['datasource-list'], meta: { title: '数据源中心', - showSide: false + showSide: false, + auth: [] } } ] diff --git a/dolphinscheduler-ui-next/src/router/modules/monitor.ts b/dolphinscheduler-ui-next/src/router/modules/monitor.ts index 3d54f10c47..9a45b336df 100644 --- a/dolphinscheduler-ui-next/src/router/modules/monitor.ts +++ b/dolphinscheduler-ui-next/src/router/modules/monitor.ts @@ -35,7 +35,8 @@ export default { component: components['monitor-servers-master'], meta: { title: '服务管理-Master', - showSide: true + showSide: true, + auth: [] } }, { @@ -44,7 +45,8 @@ export default { component: components['monitor-servers-worker'], meta: { title: '服务管理-Worker', - showSide: true + showSide: true, + auth: [] } }, { @@ -53,7 +55,8 @@ export default { component: components['monitor-servers-db'], meta: { title: '服务管理-DB', - showSide: true + showSide: true, + auth: [] } }, { @@ -62,7 +65,8 @@ export default { component: components['monitor-statistics-statistics'], meta: { title: '统计管理-Statistics', - showSide: true + showSide: true, + auth: [] } }, { @@ -71,7 +75,8 @@ export default { component: components['monitor-statistics-audit-log'], meta: { title: '审计日志-AuditLog', - showSide: true + showSide: true, + auth: [] } } ] diff --git a/dolphinscheduler-ui-next/src/router/modules/projects.ts b/dolphinscheduler-ui-next/src/router/modules/projects.ts index 9c0b2a4ed6..b7f45c1270 100644 --- a/dolphinscheduler-ui-next/src/router/modules/projects.ts +++ b/dolphinscheduler-ui-next/src/router/modules/projects.ts @@ -26,8 +26,7 @@ export default { path: '/projects', name: 'projects', meta: { - title: '项目管理', - showSide: false + title: '项目管理' }, redirect: { name: 'projects-list' }, component: () => import('@/layouts/content'), @@ -38,7 +37,8 @@ export default { component: components['projects-list'], meta: { title: '项目', - showSide: false + showSide: false, + auth: [] } }, { @@ -47,7 +47,8 @@ export default { component: components['projects-overview'], meta: { title: '项目概览', - showSide: true + showSide: true, + auth: [] } }, { @@ -56,7 +57,8 @@ export default { component: components['projects-workflow-relation'], meta: { title: '工作流关系', - showSide: true + showSide: true, + auth: [] } }, { @@ -65,7 +67,8 @@ export default { component: components['projects-workflow-definition'], meta: { title: '工作流定义', - showSide: true + showSide: true, + auth: [] } }, { @@ -74,7 +77,8 @@ export default { component: components['projects-workflow-definition-timing'], meta: { title: '定时管理', - showSide: true + showSide: true, + auth: [] } }, { @@ -83,7 +87,8 @@ export default { component: components['projects-workflow-definition-create'], meta: { title: '创建工作流定义', - showSide: true + showSide: true, + auth: [] } }, { @@ -92,7 +97,8 @@ export default { component: components['projects-workflow-definition-detail'], meta: { title: '工作流定义详情', - showSide: true + showSide: true, + auth: [] } }, { @@ -101,7 +107,8 @@ export default { component: components['projects-workflow-instance'], meta: { title: '工作流实例', - showSide: true + showSide: true, + auth: [] } }, { @@ -110,7 +117,8 @@ export default { component: components['projects-workflow-instance-detail'], meta: { title: '工作流实例详情', - showSide: true + showSide: true, + auth: [] } }, { @@ -119,7 +127,8 @@ export default { component: components['projects-task-definition'], meta: { title: '任务定义', - showSide: true + showSide: true, + auth: [] } }, { @@ -128,7 +137,8 @@ export default { component: components['projects-task-instance'], meta: { title: '任务实例', - showSide: true + showSide: true, + auth: [] } } ] diff --git a/dolphinscheduler-ui-next/src/router/modules/resources.ts b/dolphinscheduler-ui-next/src/router/modules/resources.ts index e88cde526d..7ec2ab12b0 100644 --- a/dolphinscheduler-ui-next/src/router/modules/resources.ts +++ b/dolphinscheduler-ui-next/src/router/modules/resources.ts @@ -35,7 +35,8 @@ export default { component: components['resource-file'], meta: { title: '文件管理', - showSide: true + showSide: true, + auth: [] } }, { @@ -44,7 +45,8 @@ export default { component: components['resource-file-create'], meta: { title: '文件创建', - showSide: true + showSide: true, + auth: [] } }, { @@ -53,7 +55,8 @@ export default { component: components['resource-file-edit'], meta: { title: '文件编辑', - showSide: true + showSide: true, + auth: [] } }, { @@ -62,7 +65,8 @@ export default { component: components['resource-file'], meta: { title: '文件管理', - showSide: true + showSide: true, + auth: [] } }, { @@ -71,7 +75,8 @@ export default { component: components['resource-file-edit'], meta: { title: '文件详情', - showSide: true + showSide: true, + auth: [] } }, { @@ -80,7 +85,8 @@ export default { component: components['resource-file-create'], meta: { title: '文件创建', - showSide: true + showSide: true, + auth: [] } }, { @@ -89,7 +95,8 @@ export default { component: components['resource-udf-resource'], meta: { title: '资源管理', - showSide: true + showSide: true, + auth: [] } }, { @@ -98,7 +105,8 @@ export default { component: components['resource-udf-resource'], meta: { title: '资源管理', - showSide: true + showSide: true, + auth: [] } }, { @@ -107,7 +115,8 @@ export default { component: components['resource-udf-function'], meta: { title: '函数管理', - showSide: true + showSide: true, + auth: [] } }, { @@ -116,7 +125,8 @@ export default { component: components['resource-task-group-option'], meta: { title: '任务组配置', - showSide: true + showSide: true, + auth: [] } }, { @@ -125,7 +135,8 @@ export default { component: components['resource-task-group-queue'], meta: { title: '任务组队列', - showSide: true + showSide: true, + auth: [] } } ] diff --git a/dolphinscheduler-ui-next/src/router/modules/security.ts b/dolphinscheduler-ui-next/src/router/modules/security.ts index 6750b813cd..bc694a1259 100644 --- a/dolphinscheduler-ui-next/src/router/modules/security.ts +++ b/dolphinscheduler-ui-next/src/router/modules/security.ts @@ -35,7 +35,8 @@ export default { component: components['security-tenant-manage'], meta: { title: '租户管理', - showSide: true + showSide: true, + auth: ['ADMIN_USER'] } }, { @@ -44,7 +45,8 @@ export default { component: components['security-user-manage'], meta: { title: '用户管理', - showSide: true + showSide: true, + auth: ['ADMIN_USER'] } }, { @@ -53,7 +55,8 @@ export default { component: components['security-alarm-group-manage'], meta: { title: '告警组管理', - showSide: true + showSide: true, + auth: ['ADMIN_USER'] } }, { @@ -62,7 +65,8 @@ export default { component: components['security-worker-group-manage'], meta: { title: 'Worker分组管理', - showSide: true + showSide: true, + auth: ['ADMIN_USER'] } }, { @@ -71,7 +75,8 @@ export default { component: components['security-yarn-queue-manage'], meta: { title: 'Yarn队列管理', - showSide: true + showSide: true, + auth: ['ADMIN_USER'] } }, { @@ -80,7 +85,8 @@ export default { component: components['security-environment-manage'], meta: { title: '环境管理', - showSide: true + showSide: true, + auth: ['ADMIN_USER'] } }, { @@ -89,7 +95,8 @@ export default { component: components['security-token-manage'], meta: { title: '令牌管理管理', - showSide: true + showSide: true, + auth: [] } }, { @@ -98,7 +105,8 @@ export default { component: components['security-alarm-instance-manage'], meta: { title: '告警实例管理', - showSide: true + showSide: true, + auth: ['ADMIN_USER'] } } ] diff --git a/dolphinscheduler-ui-next/src/router/routes.ts b/dolphinscheduler-ui-next/src/router/routes.ts index 2c2506a8c8..a7af8f9144 100644 --- a/dolphinscheduler-ui-next/src/router/routes.ts +++ b/dolphinscheduler-ui-next/src/router/routes.ts @@ -44,7 +44,8 @@ const basePage: RouteRecordRaw[] = [ name: 'home', component: components['home'], meta: { - title: '首页' + title: '首页', + auth: [] } }, { @@ -52,7 +53,8 @@ const basePage: RouteRecordRaw[] = [ name: 'password', component: components['password'], meta: { - title: '修改密码' + title: '修改密码', + auth: [] } }, { @@ -60,7 +62,8 @@ const basePage: RouteRecordRaw[] = [ name: 'profile', component: components['profile'], meta: { - title: '用户信息' + title: '用户信息', + auth: [] } } ] @@ -80,7 +83,10 @@ const loginPage: RouteRecordRaw[] = [ { path: '/login', name: 'login', - component: components['login'] + component: components['login'], + meta: { + auth: [] + } } ]