Optimize permission

This commit is contained in:
2024-01-24 16:10:16 +08:00
parent 983d8e0923
commit d6eaf81900
12 changed files with 95 additions and 64 deletions

View File

@@ -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 && (
<>
<Permission operationCode={['system:tool:add:base']}>
{' '}
(
<a style={{ color: COLOR_PRODUCTION }} onClick={handleOnAddBtnClick}>
</a>
)
</>
</Permission>
)}
</>
),
@@ -142,15 +143,17 @@ const Base = () => {
<>
<AntdSpace size={'middle'}>
{!record.compiled && !Object.keys(hasEdited).length && (
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnCompileBtnClick(record)}
>
</a>
<Permission operationCode={['system:tool:modify:base']}>
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnCompileBtnClick(record)}
>
</a>
</Permission>
)}
{hasEdited[record.id] && (
<Permission operationCode={'system:tool:modify:base'}>
<Permission operationCode={['system:tool:modify:base']}>
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnSaveBtnClick(record)}
@@ -160,7 +163,7 @@ const Base = () => {
</Permission>
)}
{!Object.keys(hasEdited).length && (
<Permission operationCode={'system:tool:modify:base'}>
<Permission operationCode={['system:tool:modify:base']}>
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnEditBtnClick(record)}
@@ -169,7 +172,7 @@ const Base = () => {
</a>
</Permission>
)}
<Permission operationCode={'system:tool:delete:base'}>
<Permission operationCode={['system:tool:delete:base']}>
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnDeleteBtnClick(record)}
@@ -652,14 +655,14 @@ const Base = () => {
<>
{!Object.keys(hasEdited).length && (
<>
<Permission operationCode={['system:tool:modify:base']}>
{' '}
(
<a style={{ color: COLOR_PRODUCTION }} onClick={handleOnAddFile}>
</a>
)
</>
</Permission>
)}
</>
),
@@ -669,16 +672,21 @@ const Base = () => {
render: (_, record) => (
<>
<AntdSpace size={'middle'}>
<Permission operationCode={'system:tool:modify:category'}>
<Permission
operationCode={[
'system:tool:query:base',
'system:tool:modify:base'
]}
>
<a
onClick={handleOnEditFile(record.name)}
style={{ color: COLOR_PRODUCTION }}
>
{hasPermission('system:tool:modify:base') ? '编辑' : '查看'}
</a>
</Permission>
{!Object.keys(hasEdited).length && (
<Permission operationCode={'system:tool:modify:category'}>
<Permission operationCode={['system:tool:modify:base']}>
<a
onClick={handleOnRenameFile(record.name)}
style={{ color: COLOR_PRODUCTION }}
@@ -688,7 +696,7 @@ const Base = () => {
</Permission>
)}
{!Object.keys(hasEdited).length && (
<Permission operationCode={'system:tool:delete:category'}>
<Permission operationCode={['system:tool:delete:base']}>
<a
onClick={handleOnDeleteFile(record.name)}
style={{ color: COLOR_PRODUCTION }}
@@ -880,6 +888,9 @@ const Base = () => {
}
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')
}
/>
<div className={'close-editor-btn'} onClick={handleOnCloseBtnClick}>
<Icon component={IconOxygenClose} />

View File

@@ -73,11 +73,15 @@ const Category = () => {
{
title: (
<>
(
<a style={{ color: COLOR_PRODUCTION }} onClick={handleOnAddBtnClick}>
</a>
)
<Permission operationCode={['system:tool:add:category']}>
{' '}
(
<a style={{ color: COLOR_PRODUCTION }} onClick={handleOnAddBtnClick}>
</a>
)
</Permission>
</>
),
dataIndex: 'enable',
@@ -86,7 +90,7 @@ const Category = () => {
render: (_, record) => (
<>
<AntdSpace size={'middle'}>
<Permission operationCode={'system:tool:modify:category'}>
<Permission operationCode={['system:tool:modify:category']}>
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnEditBtnClick(record)}
@@ -94,7 +98,7 @@ const Category = () => {
</a>
</Permission>
<Permission operationCode={'system:tool:delete:category'}>
<Permission operationCode={['system:tool:delete:category']}>
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnDeleteBtnClick(record)}

View File

@@ -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_template_update,
r_sys_tool_template_delete,
@@ -31,7 +32,6 @@ import HideScrollbar from '@/components/common/HideScrollbar'
import Card from '@/components/common/Card'
import CodeEditor from '@/components/Playground/CodeEditor'
import Permission from '@/components/common/Permission'
import { useState } from 'react'
const Template = () => {
const blocker = useBlocker(
@@ -125,14 +125,14 @@ const Template = () => {
<>
{!Object.keys(hasEdited).length && (
<>
<Permission operationCode={['system:tool:add:template']}>
{' '}
(
<a style={{ color: COLOR_PRODUCTION }} onClick={handleOnAddBtnClick}>
</a>
)
</>
</Permission>
)}
</>
),
@@ -142,7 +142,7 @@ const Template = () => {
<>
<AntdSpace size={'middle'}>
{hasEdited[record.id] && (
<Permission operationCode={'system:tool:modify:base'}>
<Permission operationCode={['system:tool:modify:template']}>
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnSaveBtnClick(record)}
@@ -152,7 +152,7 @@ const Template = () => {
</Permission>
)}
{!Object.keys(hasEdited).length && (
<Permission operationCode={'system:tool:modify:base'}>
<Permission operationCode={['system:tool:modify:template']}>
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnEditBtnClick(record)}
@@ -161,7 +161,7 @@ const Template = () => {
</a>
</Permission>
)}
<Permission operationCode={'system:tool:delete:base'}>
<Permission operationCode={['system:tool:delete:template']}>
<a
style={{ color: COLOR_PRODUCTION }}
onClick={handleOnDeleteBtnClick(record)}
@@ -498,14 +498,14 @@ const Template = () => {
<>
{!Object.keys(hasEdited).length && (
<>
<Permission operationCode={['system:tool:modify:template']}>
{' '}
(
<a style={{ color: COLOR_PRODUCTION }} onClick={handleOnAddFile}>
</a>
)
</>
</Permission>
)}
</>
),
@@ -515,16 +515,21 @@ const Template = () => {
render: (_, record) => (
<>
<AntdSpace size={'middle'}>
<Permission operationCode={'system:tool:modify:category'}>
<Permission
operationCode={[
'system:tool:query:template',
'system:tool:modify:template'
]}
>
<a
onClick={handleOnEditFile(record.name)}
style={{ color: COLOR_PRODUCTION }}
>
{hasPermission('system:tool:modify:template') ? '编辑' : '查看'}
</a>
</Permission>
{!Object.keys(hasEdited).length && (
<Permission operationCode={'system:tool:modify:category'}>
<Permission operationCode={['system:tool:modify:template']}>
<a
onClick={handleOnRenameFile(record.name)}
style={{ color: COLOR_PRODUCTION }}
@@ -534,7 +539,7 @@ const Template = () => {
</Permission>
)}
{!Object.keys(hasEdited).length && (
<Permission operationCode={'system:tool:delete:category'}>
<Permission operationCode={['system:tool:delete:template']}>
<a
onClick={handleOnDeleteFile(record.name)}
style={{ color: COLOR_PRODUCTION }}
@@ -729,6 +734,9 @@ const Template = () => {
}
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')
}
/>
<div className={'close-editor-btn'} onClick={handleOnCloseBtnClick}>
<Icon component={IconOxygenClose} />