Skip to content

Commit a6105cf

Browse files
authored
fix: 1.3-beta版本,超级管理员(admin)账户无法修改分类和添加子分类,页面显示无权限操作 (#164)
1 parent 0aa5ffd commit a6105cf

File tree

7 files changed

+144
-185
lines changed

7 files changed

+144
-185
lines changed

frontend/packages/common/src/components/aoplatform/WithPermission.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { PERMISSION_DEFINITION } from '@common/const/permissions'
2+
import { $t } from '@common/locales'
13
import { Button, Tooltip, Upload } from 'antd'
24
import { ReactElement, cloneElement, useEffect, useMemo, useState } from 'react'
35
import { useGlobalContext } from '../../contexts/GlobalStateContext'
4-
import { PERMISSION_DEFINITION } from '@common/const/permissions'
5-
import { $t } from '@common/locales'
66

77
type WithPermissionProps = {
88
access?: string | string[]

frontend/packages/common/src/utils/permission.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ export const checkAccess: (access: AccessDataType, accessData: Map<string, strin
1818
if (accLevel === 'team') {
1919
accessSet = new Set(Array.from(accessSet).concat(accessData?.get('team') || []))
2020
}
21-
return accessSet!.size > 0 ? hasIntersection(neededBackendAccessArr, accessSet) : false
21+
if (!accessSet!.size) {
22+
return false
23+
}
24+
const hasAccess = hasIntersection(neededBackendAccessArr, accessSet)
25+
return hasAccess
2226
}
2327

2428
const hasIntersection = (arr1: string[], set1: Set<string>) => {

frontend/packages/core/src/App.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,15 @@ function App() {
151151
form={{ validateMessages }}
152152
>
153153
<PluginEventHubProvider>
154-
<AppAntd className="h-full" message={{ maxCount: 1 }}>
155-
<PluginSlotHubProvider>
156-
<GlobalProvider>
154+
<GlobalProvider>
155+
<AppAntd className="h-full" message={{ maxCount: 1 }}>
156+
<PluginSlotHubProvider>
157157
<BreadcrumbProvider>
158158
<RenderRoutes />
159159
</BreadcrumbProvider>
160-
</GlobalProvider>
161-
</PluginSlotHubProvider>
162-
</AppAntd>
160+
</PluginSlotHubProvider>
161+
</AppAntd>
162+
</GlobalProvider>
163163
</PluginEventHubProvider>
164164
</ConfigProvider>
165165
</StyleProvider>

frontend/packages/core/src/pages/common/ServiceCategory.tsx

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function ServiceCategory() {
2828
const { accessData } = useGlobalContext()
2929
const [loading, setLoading] = useState<boolean>(false)
3030

31-
const onDrop: TreeProps['onDrop'] = info => {
31+
const onDrop: TreeProps['onDrop'] = (info) => {
3232
const dropKey = info.node.key
3333
const dragKey = info.dragNode.key
3434
const dropPos = info.node.pos.split('-')
@@ -59,7 +59,7 @@ export default function ServiceCategory() {
5959

6060
if (!info.dropToGap) {
6161
// Drop on the content
62-
loop(data, dropKey, item => {
62+
loop(data, dropKey, (item) => {
6363
item.children = item.children || []
6464
// where to insert. New item was inserted to the start of the array in this example, but can be anywhere
6565
item.children.unshift(dragObj)
@@ -129,9 +129,9 @@ export default function ServiceCategory() {
129129
const treeData = useMemo(() => {
130130
setExpandedKeys([])
131131
const loop = (data: CategorizesType[]): DataNode[] =>
132-
data?.map(item => {
132+
data?.map((item) => {
133133
if (item.children) {
134-
setExpandedKeys(prev => [...prev, item.id])
134+
setExpandedKeys((prev) => [...prev, item.id])
135135
return {
136136
title: (
137137
<TreeWithMore stopClick={false} dropdownMenu={dropdownMenu(item as CategorizesType)}>
@@ -169,40 +169,22 @@ export default function ServiceCategory() {
169169
return !checkAccess(permission, accessData)
170170
}
171171

172-
const openModal = (
173-
type: 'addCate' | 'addChildCate' | 'renameCate' | 'delete',
174-
entity?: CategorizesType
175-
) => {
172+
const openModal = (type: 'addCate' | 'addChildCate' | 'renameCate' | 'delete', entity?: CategorizesType) => {
176173
let title: string = ''
177174
let content: string | React.ReactNode = ''
178175
switch (type) {
179-
case 'addCate':
176+
case 'addCate': {
180177
title = $t('添加分类')
181-
content = (
182-
<ServiceHubCategoryConfig WithPermission={WithPermission} ref={addRef} type={type} />
183-
)
178+
content = <ServiceHubCategoryConfig ref={addRef} type={type} />
184179
break
180+
}
185181
case 'addChildCate':
186182
title = $t('添加子分类')
187-
content = (
188-
<ServiceHubCategoryConfig
189-
WithPermission={WithPermission}
190-
ref={addChildRef}
191-
type={type}
192-
entity={entity}
193-
/>
194-
)
183+
content = <ServiceHubCategoryConfig ref={addChildRef} type={type} entity={entity} />
195184
break
196185
case 'renameCate':
197186
title = $t('重命名分类')
198-
content = (
199-
<ServiceHubCategoryConfig
200-
WithPermission={WithPermission}
201-
ref={renameRef}
202-
type={type}
203-
entity={entity}
204-
/>
205-
)
187+
content = <ServiceHubCategoryConfig ref={renameRef} type={type} entity={entity} />
206188
break
207189
case 'delete':
208190
title = $t('删除')
@@ -215,19 +197,19 @@ export default function ServiceCategory() {
215197
onOk: () => {
216198
switch (type) {
217199
case 'addCate':
218-
return addRef.current?.save().then(res => {
200+
return addRef.current?.save().then((res) => {
219201
if (res === true) getCategoryList()
220202
})
221203
case 'addChildCate':
222-
return addChildRef.current?.save().then(res => {
204+
return addChildRef.current?.save().then((res) => {
223205
if (res === true) getCategoryList()
224206
})
225207
case 'renameCate':
226-
return renameRef.current?.save().then(res => {
208+
return renameRef.current?.save().then((res) => {
227209
if (res === true) getCategoryList()
228210
})
229211
case 'delete':
230-
return deleteCate(entity!).then(res => {
212+
return deleteCate(entity!).then((res) => {
231213
if (res === true) getCategoryList()
232214
})
233215
}
@@ -249,7 +231,7 @@ export default function ServiceCategory() {
249231
method: 'DELETE',
250232
eoParams: { catalogue: entity.id }
251233
})
252-
.then(response => {
234+
.then((response) => {
253235
const { code, msg } = response
254236
if (code === STATUS_CODE.SUCCESS) {
255237
message.success(msg || $t(RESPONSE_TIPS.success))
@@ -259,14 +241,14 @@ export default function ServiceCategory() {
259241
reject(msg || $t(RESPONSE_TIPS.error))
260242
}
261243
})
262-
.catch(errorInfo => reject(errorInfo))
244+
.catch((errorInfo) => reject(errorInfo))
263245
})
264246
}
265247

266248
const sortCategories = (newData: CategorizesType[]) => {
267249
setLoading(true)
268250
fetchData<BasicResponse<null>>('catalogue/sort', { method: 'PUT', eoBody: newData })
269-
.then(response => {
251+
.then((response) => {
270252
const { code, msg } = response
271253
if (code === STATUS_CODE.SUCCESS) {
272254
getCategoryList()
@@ -288,7 +270,7 @@ export default function ServiceCategory() {
288270
fetchData<BasicResponse<{ catalogues: CategorizesType[]; tags: EntityItem[] }>>('catalogues', {
289271
method: 'GET'
290272
})
291-
.then(response => {
273+
.then((response) => {
292274
const { code, data, msg } = response
293275
if (code === STATUS_CODE.SUCCESS) {
294276
setGData(data.catalogues)
@@ -308,11 +290,7 @@ export default function ServiceCategory() {
308290

309291
return (
310292
<div className="border border-solid border-BORDER p-[20px] rounded-[10px] ">
311-
<Spin
312-
indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />}
313-
spinning={loading}
314-
className=""
315-
>
293+
<Spin indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />} spinning={loading} className="">
316294
<Tree
317295
showIcon
318296
draggable

0 commit comments

Comments
 (0)