From d6eaf819003cb803723700691c1d9588c303392e Mon Sep 17 00:00:00 2001 From: FatttSnake Date: Wed, 24 Jan 2024 16:10:16 +0800 Subject: [PATCH] Optimize permission --- src/components/common/Permission.tsx | 4 +- src/pages/System/Group.tsx | 8 ++-- src/pages/System/Role.tsx | 8 ++-- src/pages/System/Settings/Base.tsx | 2 +- src/pages/System/Settings/Mail.tsx | 2 +- src/pages/System/Settings/SensitiveWord.tsx | 2 +- src/pages/System/Settings/index.tsx | 8 ++-- src/pages/System/Statistics/index.tsx | 6 +-- src/pages/System/Tools/Base.tsx | 53 +++++++++++++-------- src/pages/System/Tools/Category.tsx | 18 ++++--- src/pages/System/Tools/Template.tsx | 40 ++++++++++------ src/pages/System/User.tsx | 8 ++-- 12 files changed, 95 insertions(+), 64 deletions(-) diff --git a/src/components/common/Permission.tsx b/src/components/common/Permission.tsx index c3035b9..3a62604 100644 --- a/src/components/common/Permission.tsx +++ b/src/components/common/Permission.tsx @@ -2,13 +2,13 @@ import { PropsWithChildren } from 'react' import { hasPathPermission, hasPermission } from '@/util/auth' interface PermissionProps extends PropsWithChildren { - operationCode?: string + operationCode?: string[] path?: string } const Permission = (props: PermissionProps) => { if ( - (!props.operationCode || hasPermission(props.operationCode)) && + (!props.operationCode || props.operationCode.some(hasPermission)) && (!props.path || hasPathPermission(props.path)) ) { return props.children diff --git a/src/pages/System/Group.tsx b/src/pages/System/Group.tsx index d286e84..51ae287 100644 --- a/src/pages/System/Group.tsx +++ b/src/pages/System/Group.tsx @@ -106,7 +106,7 @@ const Group = () => { render: (value, record) => ( <> - + {value ? ( { )} - + { 编辑 - + { const toolbar = ( - + { render: (value, record) => ( <> - + {value ? ( { )} - + { 编辑 - + { const toolbar = ( - + { loading={loading} onReset={handleOnReset} onSave={handleOnSave} - modifyOperationCode={'system:settings:modify:base'} + modifyOperationCode={['system:settings:modify:base']} > { loading={loading} onReset={handleOnReset} onSave={handleOnSave} - modifyOperationCode={'system:settings:modify:mail'} + modifyOperationCode={['system:settings:modify:mail']} expand={ diff --git a/src/pages/System/Settings/SensitiveWord.tsx b/src/pages/System/Settings/SensitiveWord.tsx index f61b713..7284f54 100644 --- a/src/pages/System/Settings/SensitiveWord.tsx +++ b/src/pages/System/Settings/SensitiveWord.tsx @@ -106,7 +106,7 @@ const SensitiveWord = () => { loading={loading} onReset={handleOnReset} onSave={handleOnSave} - modifyOperationCode={'system:settings:modify:sensitive'} + modifyOperationCode={['system:settings:modify:sensitive']} > void onSave?: () => void @@ -57,15 +57,15 @@ const Settings = () => { - + - + - + diff --git a/src/pages/System/Statistics/index.tsx b/src/pages/System/Statistics/index.tsx index 1fa79ba..04077b2 100644 --- a/src/pages/System/Statistics/index.tsx +++ b/src/pages/System/Statistics/index.tsx @@ -47,15 +47,15 @@ const Statistics = () => { - + - + - + diff --git a/src/pages/System/Tools/Base.tsx b/src/pages/System/Tools/Base.tsx index d4a4907..f651653 100644 --- a/src/pages/System/Tools/Base.tsx +++ b/src/pages/System/Tools/Base.tsx @@ -8,7 +8,8 @@ import { DATABASE_SELECT_SUCCESS, DATABASE_UPDATE_SUCCESS } from '@/constants/common.constants' -import { utcToLocalTime } from '@/util/datetime.tsx' +import { utcToLocalTime } from '@/util/datetime' +import { hasPermission } from '@/util/auth' import { r_sys_tool_base_add, r_sys_tool_base_delete, @@ -125,14 +126,14 @@ const Base = () => { <> 操作 {!Object.keys(hasEdited).length && ( - <> + {' '} ( 新增 ) - + )} ), @@ -142,15 +143,17 @@ const Base = () => { <> {!record.compiled && !Object.keys(hasEdited).length && ( - - 编译 - + + + 编译 + + )} {hasEdited[record.id] && ( - + { )} {!Object.keys(hasEdited).length && ( - + { )} - + { <> 操作 {!Object.keys(hasEdited).length && ( - <> + {' '} ( 新增 ) - + )} ), @@ -669,16 +672,21 @@ const Base = () => { render: (_, record) => ( <> - + - 编辑 + {hasPermission('system:tool:modify:base') ? '编辑' : '查看'} {!Object.keys(hasEdited).length && ( - + { )} {!Object.keys(hasEdited).length && ( - + { } const handleOnChangeFileContent = (_content: string, _fileName: string, files: IFiles) => { + if (!hasPermission('system:tool:modify:base')) { + return + } setEditingFiles({ ...editingFiles, [editingBaseId]: files }) if (!hasEdited[editingBaseId]) { setHasEdited({ ...hasEdited, [editingBaseId]: true }) @@ -978,7 +989,11 @@ const Base = () => { onChangeFileContent={handleOnChangeFileContent} showFileSelector={false} tsconfig={tsconfig} - readonly={isLoading || baseDetailLoading[editingBaseId]} + readonly={ + isLoading || + baseDetailLoading[editingBaseId] || + !hasPermission('system:tool:modify:base') + } />
diff --git a/src/pages/System/Tools/Category.tsx b/src/pages/System/Tools/Category.tsx index f7dd19c..e415db3 100644 --- a/src/pages/System/Tools/Category.tsx +++ b/src/pages/System/Tools/Category.tsx @@ -73,11 +73,15 @@ const Category = () => { { title: ( <> - 操作 ( - - 新增 - - ) + 操作 + + {' '} + ( + + 新增 + + ) + ), dataIndex: 'enable', @@ -86,7 +90,7 @@ const Category = () => { render: (_, record) => ( <> - + { 编辑 - + { const blocker = useBlocker( @@ -125,14 +125,14 @@ const Template = () => { <> 操作 {!Object.keys(hasEdited).length && ( - <> + {' '} ( 新增 ) - + )} ), @@ -142,7 +142,7 @@ const Template = () => { <> {hasEdited[record.id] && ( - + { )} {!Object.keys(hasEdited).length && ( - + { )} - + { <> 操作 {!Object.keys(hasEdited).length && ( - <> + {' '} ( 新增 ) - + )} ), @@ -515,16 +515,21 @@ const Template = () => { render: (_, record) => ( <> - + - 编辑 + {hasPermission('system:tool:modify:template') ? '编辑' : '查看'} {!Object.keys(hasEdited).length && ( - + { )} {!Object.keys(hasEdited).length && ( - + { } const handleOnChangeFileContent = (_content: string, _fileName: string, files: IFiles) => { + if (!hasPermission('system:tool:modify:template')) { + return + } setEditingFiles({ ...editingFiles, [editingTemplateId]: files }) if (!hasEdited[editingTemplateId]) { setHasEdited({ ...hasEdited, [editingTemplateId]: true }) @@ -865,7 +873,11 @@ const Template = () => { onChangeFileContent={handleOnChangeFileContent} showFileSelector={false} tsconfig={tsconfig} - readonly={isLoading || templateDetailLoading[editingTemplateId]} + readonly={ + isLoading || + templateDetailLoading[editingTemplateId] || + !hasPermission('system:tool:modify:template') + } />