From 8594fae4ca7b89a7c5bada84ba165c455cd12291 Mon Sep 17 00:00:00 2001 From: wanghong Date: Wed, 25 Oct 2023 17:24:56 +0800 Subject: [PATCH 1/6] fix: supply managementPermission --- packages/base/src/page/Project/List/index.tsx | 1 + packages/base/src/page/Project/index.tsx | 17 ++++++++++++++--- packages/base/src/store/user/index.ts | 9 ++++++--- packages/shared/lib/data/common.ts | 4 ++++ .../shared/lib/global/useUserInfo/index.tsx | 3 +-- packages/sqle/src/data/common.ts | 4 ---- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/packages/base/src/page/Project/List/index.tsx b/packages/base/src/page/Project/List/index.tsx index 370617cc4..2999ef77b 100644 --- a/packages/base/src/page/Project/List/index.tsx +++ b/packages/base/src/page/Project/List/index.tsx @@ -34,6 +34,7 @@ const ProjectList: React.FC = () => { const dispatch = useDispatch(); const { isAdmin, isProjectManager } = useCurrentUser(); const { updateUserInfo } = useUserInfo(); + const allowOperateProject = useCallback( (projectName: string) => isAdmin || isProjectManager(projectName), [isAdmin, isProjectManager] diff --git a/packages/base/src/page/Project/index.tsx b/packages/base/src/page/Project/index.tsx index c128aacc2..faecb527a 100644 --- a/packages/base/src/page/Project/index.tsx +++ b/packages/base/src/page/Project/index.tsx @@ -11,18 +11,29 @@ import { ModalName } from '../../data/ModalName'; import ProjectManageModal from './Modal'; import { ProjectListStyledWrapper } from './style'; import { useCurrentUser } from '@actiontech/shared/lib/global'; +import { useMemo } from 'react'; +import { ManagementPermissionsEnum } from '@actiontech/shared/lib/data/common'; const Project: React.FC = () => { const { t } = useTranslation(); - const { isAdmin } = useCurrentUser(); - + const { isAdmin, managementPermissions } = useCurrentUser(); const dispatch = useDispatch(); + const allowCreateProject = useMemo(() => { + return ( + isAdmin || + managementPermissions.some( + (v) => ManagementPermissionsEnum.Create_Project === (v?.uid ?? '') + ) + ); + }, [isAdmin, managementPermissions]); + const refreshTable = () => { EventEmitter.emit(EmitterKey.DMS_Refresh_Project_List); }; const createProject = () => { + if (!allowCreateProject) return; dispatch( updateProjectModalStatus({ modalName: ModalName.DMS_Add_Project, @@ -41,7 +52,7 @@ const Project: React.FC = () => { } extra={ - + {t('dmsProject.createProject.modalTitle')} diff --git a/packages/base/src/store/user/index.ts b/packages/base/src/store/user/index.ts index 5b18e6fe9..3f76246ee 100644 --- a/packages/base/src/store/user/index.ts +++ b/packages/base/src/store/user/index.ts @@ -6,7 +6,10 @@ import { } from '@actiontech/shared/lib/enum'; import { createSlice, PayloadAction } from '@reduxjs/toolkit'; import { IManagementPermissionResV1 } from '@actiontech/shared/lib/types/common.type'; -import { IUserBindProject } from '@actiontech/shared/lib/api/base/service/common'; +import { + IUidWithName, + IUserBindProject +} from '@actiontech/shared/lib/api/base/service/common'; type UserReduxState = { username: string; @@ -14,7 +17,7 @@ type UserReduxState = { token: string; theme: SupportTheme; bindProjects: Array; - managementPermissions: IManagementPermissionResV1[]; + managementPermissions: IUidWithName[]; uid: string; useInfoFetched: boolean; }; @@ -72,7 +75,7 @@ const user = createSlice({ state, { payload: { managementPermissions } - }: PayloadAction<{ managementPermissions: IManagementPermissionResV1[] }> + }: PayloadAction<{ managementPermissions: IUidWithName[] }> ) => { state.managementPermissions = managementPermissions; }, diff --git a/packages/shared/lib/data/common.ts b/packages/shared/lib/data/common.ts index 3b6c1bdeb..1ae7acb15 100644 --- a/packages/shared/lib/data/common.ts +++ b/packages/shared/lib/data/common.ts @@ -96,3 +96,7 @@ export const DMS_DEFAULT_WEB_TITLE = 'SQLE'; export const DEFAULT_PROJECT_ID = '700300'; export const DEFAULT_PROJECT_NAME = 'default'; export const DMS_DEFAULT_WEB_LOGO_URL = '/logo.png'; + +export enum ManagementPermissionsEnum { + Create_Project = '1' +} diff --git a/packages/shared/lib/global/useUserInfo/index.tsx b/packages/shared/lib/global/useUserInfo/index.tsx index 8abf729ad..c37dd7968 100644 --- a/packages/shared/lib/global/useUserInfo/index.tsx +++ b/packages/shared/lib/global/useUserInfo/index.tsx @@ -75,10 +75,9 @@ const useUserInfo = () => { }) ); - //todo dispatch( updateManagementPermissions({ - managementPermissions: [] + managementPermissions: data?.op_permissions ?? [] }) ); diff --git a/packages/sqle/src/data/common.ts b/packages/sqle/src/data/common.ts index 4eb25ddd7..fc5d96bb5 100644 --- a/packages/sqle/src/data/common.ts +++ b/packages/sqle/src/data/common.ts @@ -24,10 +24,6 @@ export enum LoginTypeEnum { 'sqle' = 'sqle' } -export enum ManagementPermissionsEnum { - Create_Project = 1 -} - export const SQLE_INSTANCE_SOURCE_NAME = 'SQLE'; export const SQLE_REDIRECT_KEY_PARAMS_NAME = 'target'; From 9e70743d9683d72dafca59fe4ad57509fbca0ea9 Mon Sep 17 00:00:00 2001 From: wanghong Date: Thu, 26 Oct 2023 09:10:52 +0800 Subject: [PATCH 2/6] fix: replace OpPermissionItemOpPermissionTypeEnum --- packages/base/src/page/Project/index.tsx | 6 ++++-- packages/shared/lib/data/common.ts | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/base/src/page/Project/index.tsx b/packages/base/src/page/Project/index.tsx index faecb527a..f785151a7 100644 --- a/packages/base/src/page/Project/index.tsx +++ b/packages/base/src/page/Project/index.tsx @@ -12,7 +12,7 @@ import ProjectManageModal from './Modal'; import { ProjectListStyledWrapper } from './style'; import { useCurrentUser } from '@actiontech/shared/lib/global'; import { useMemo } from 'react'; -import { ManagementPermissionsEnum } from '@actiontech/shared/lib/data/common'; +import { OpPermissionItemOpPermissionTypeEnum } from '@actiontech/shared/lib/api/base/service/common.enum'; const Project: React.FC = () => { const { t } = useTranslation(); @@ -23,7 +23,9 @@ const Project: React.FC = () => { return ( isAdmin || managementPermissions.some( - (v) => ManagementPermissionsEnum.Create_Project === (v?.uid ?? '') + (v) => + OpPermissionItemOpPermissionTypeEnum['create_project'] === + (v?.name ?? '') ) ); }, [isAdmin, managementPermissions]); diff --git a/packages/shared/lib/data/common.ts b/packages/shared/lib/data/common.ts index 1ae7acb15..3b6c1bdeb 100644 --- a/packages/shared/lib/data/common.ts +++ b/packages/shared/lib/data/common.ts @@ -96,7 +96,3 @@ export const DMS_DEFAULT_WEB_TITLE = 'SQLE'; export const DEFAULT_PROJECT_ID = '700300'; export const DEFAULT_PROJECT_NAME = 'default'; export const DMS_DEFAULT_WEB_LOGO_URL = '/logo.png'; - -export enum ManagementPermissionsEnum { - Create_Project = '1' -} From dbaf9bc97d87bdff4b5ab1798d1a843426988fe7 Mon Sep 17 00:00:00 2001 From: wanghong Date: Thu, 26 Oct 2023 11:05:52 +0800 Subject: [PATCH 3/6] fix: remove IManagementPermissionResV1 --- packages/base/src/store/user/index.ts | 1 - packages/shared/lib/types/common.type.ts | 6 ------ 2 files changed, 7 deletions(-) diff --git a/packages/base/src/store/user/index.ts b/packages/base/src/store/user/index.ts index 3f76246ee..bd24a6ee5 100644 --- a/packages/base/src/store/user/index.ts +++ b/packages/base/src/store/user/index.ts @@ -5,7 +5,6 @@ import { SystemRole } from '@actiontech/shared/lib/enum'; import { createSlice, PayloadAction } from '@reduxjs/toolkit'; -import { IManagementPermissionResV1 } from '@actiontech/shared/lib/types/common.type'; import { IUidWithName, IUserBindProject diff --git a/packages/shared/lib/types/common.type.ts b/packages/shared/lib/types/common.type.ts index c6bb9d89b..cd5976820 100644 --- a/packages/shared/lib/types/common.type.ts +++ b/packages/shared/lib/types/common.type.ts @@ -43,12 +43,6 @@ export interface IStore { [key: string]: any; } -//todo: sqle后端已删除这个定义,dms暂时还需要保留,所以在此暂存,之后再改 -export interface IManagementPermissionResV1 { - code?: number; - - desc?: string; -} interface ThemeCustom { common: { padding: number; From 905c757826afd33107349c37efbe286eb86f5e0b Mon Sep 17 00:00:00 2001 From: wanghong Date: Thu, 26 Oct 2023 13:18:32 +0800 Subject: [PATCH 4/6] fix: fix eslint problem --- packages/shared/lib/global/useCurrentUser/index.test.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/shared/lib/global/useCurrentUser/index.test.ts b/packages/shared/lib/global/useCurrentUser/index.test.ts index a2d9c42b4..837dbcea5 100644 --- a/packages/shared/lib/global/useCurrentUser/index.test.ts +++ b/packages/shared/lib/global/useCurrentUser/index.test.ts @@ -2,9 +2,8 @@ import useCurrentUser from '.'; import { renderHook } from '@testing-library/react-hooks'; import { useSelector } from 'react-redux'; import { SupportTheme, SystemRole } from '../../enum'; -import { IManagementPermissionResV1 } from '../../types/common.type'; import { useDispatch } from 'react-redux'; -import { IUserBindProject } from '../../api/base/service/common'; +import { IUidWithName, IUserBindProject } from '../../api/base/service/common'; export const mockBindProjects: IUserBindProject[] = [ { @@ -19,10 +18,10 @@ export const mockBindProjects: IUserBindProject[] = [ } ]; -export const mockManagementPermissions: IManagementPermissionResV1[] = [ +export const mockManagementPermissions: IUidWithName[] = [ { - code: 1, - desc: '创建项目' + uid: '700001', + name: '创建项目' } ]; From 9368a25038cb5e27f82a9f58c6c8f8412f1fa4ab Mon Sep 17 00:00:00 2001 From: wanghong Date: Fri, 10 Nov 2023 10:57:05 +0800 Subject: [PATCH 5/6] fix: supply OpPermissionTypeUid enum --- packages/base/src/page/Project/index.tsx | 6 ++---- packages/shared/lib/enum/index.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/base/src/page/Project/index.tsx b/packages/base/src/page/Project/index.tsx index f785151a7..2cf8c1c1d 100644 --- a/packages/base/src/page/Project/index.tsx +++ b/packages/base/src/page/Project/index.tsx @@ -12,7 +12,7 @@ import ProjectManageModal from './Modal'; import { ProjectListStyledWrapper } from './style'; import { useCurrentUser } from '@actiontech/shared/lib/global'; import { useMemo } from 'react'; -import { OpPermissionItemOpPermissionTypeEnum } from '@actiontech/shared/lib/api/base/service/common.enum'; +import { OpPermissionTypeUid } from '@actiontech/shared/lib/enum'; const Project: React.FC = () => { const { t } = useTranslation(); @@ -23,9 +23,7 @@ const Project: React.FC = () => { return ( isAdmin || managementPermissions.some( - (v) => - OpPermissionItemOpPermissionTypeEnum['create_project'] === - (v?.name ?? '') + (v) => OpPermissionTypeUid['create_project'] === (v?.uid ?? '') ) ); }, [isAdmin, managementPermissions]); diff --git a/packages/shared/lib/enum/index.ts b/packages/shared/lib/enum/index.ts index a07d1362b..b8e215ebb 100644 --- a/packages/shared/lib/enum/index.ts +++ b/packages/shared/lib/enum/index.ts @@ -42,3 +42,19 @@ export enum StorageKey { DMS_Project_Catch = 'DMS_Project_Catch', USER_UID = 'DMS_USER_UID' } + +/** + * 后端暂时无法在swagger中暴露OpPermissionType的映射,但权限对应的uid一般不会变化,因此前端先保存一份。 + */ +export enum OpPermissionTypeUid { + 'create_project' = '700001', // 创建项目;创建项目的用户自动拥有该项目管理权限 700001 + 'project_admin' = '700002', // 项目管理;拥有该权限的用户可以管理项目下的所有资源 700002 + 'create_workflow' = '700003', // 创建/编辑工单;拥有该权限的用户可以创建/编辑工单 700003 + 'audit_workflow' = '700004', // 审核/驳回工单;拥有该权限的用户可以审核/驳回工单 700004 + 'auth_db_service_data' = '700005', // 授权数据源数据权限;拥有该权限的用户可以授权数据源数据权限 700005 + 'execute_workflow' = '700006', // 上线工单;拥有该权限的用户可以上线工单 700006 + 'view_others_workflow' = '700007', // 查看其他工单权限 700007 + 'view_other_audit_plan' = '700008', // 查看其他扫描任务权限 700008 + 'save_audit_plan' = '700009', // 创建扫描任务权限;拥有该权限的用户可以创建/更新扫描任务 700009 + 'sql_query' = '700010' //SQL查询;SQL查询权限 700010 +} From f8f2b567976195dbfd22a306aeaaa20cfa1d7570 Mon Sep 17 00:00:00 2001 From: wanghong Date: Fri, 10 Nov 2023 16:27:08 +0800 Subject: [PATCH 6/6] fix: remove IManagementPermissionResV1 define --- packages/shared/lib/types/common.type.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/shared/lib/types/common.type.ts b/packages/shared/lib/types/common.type.ts index f6c941f1f..3d794a241 100644 --- a/packages/shared/lib/types/common.type.ts +++ b/packages/shared/lib/types/common.type.ts @@ -55,12 +55,6 @@ export type RouterConfigItem = RouteObject & { role?: Array; }; -//todo: sqle后端已删除这个定义,dms暂时还需要保留,所以在此暂存,之后再改 -export interface IManagementPermissionResV1 { - code?: number; - - desc?: string; -} interface ThemeCustom { // provision 重构完后移除 common: {