Skip to content

Commit 2eef411

Browse files
perf: Setting menu permission
1 parent e257c3b commit 2eef411

5 files changed

Lines changed: 45 additions & 13 deletions

File tree

backend/apps/system/api/workspace.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,10 @@ async def pager(
7777
keyword: Optional[str] = Query(None, description="搜索关键字(可选)"),
7878
oid: Optional[int] = Query(None, description="空间ID(仅admin用户生效)"),
7979
):
80+
if not current_user.isAdmin and current_user.weight == 0:
81+
raise HTTPException("no permission to execute")
8082
if current_user.isAdmin:
81-
workspace_id = oid
83+
workspace_id = oid if oid else current_user.oid
8284
else:
8385
workspace_id = current_user.oid
8486
pagination = PaginationParams(page=pageNum, size=pageSize)

frontend/src/components/layout/Menu.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { computed } from 'vue'
33
import { ElMenu } from 'element-plus-secondary'
44
import { useRoute, useRouter } from 'vue-router'
55
import MenuItem from './MenuItem.vue'
6-
6+
import { useUserStore } from '@/stores/user'
7+
const userStore = useUserStore()
78
const router = useRouter()
89
defineProps({
910
collapse: Boolean,
@@ -16,7 +17,6 @@ const activeMenu = computed(() => route.path)
1617
const arr = route.path.split('/')
1718
return arr[arr.length - 1]
1819
}) */
19-
2020
const showSysmenu = computed(() => {
2121
return route.path.includes('/system')
2222
})
@@ -25,20 +25,21 @@ const routerList = computed(() => {
2525
if (showSysmenu.value) {
2626
return router.getRoutes().filter((route) => route.path.includes('/system') && !route.redirect)
2727
}
28-
29-
return router.getRoutes().filter((route) => {
28+
const list = router.getRoutes().filter((route) => {
3029
return (
3130
!route.path.includes('canvas') &&
3231
!route.path.includes('member') &&
3332
!route.path.includes('permission') &&
3433
!route.path.includes('preview') &&
3534
route.path !== '/login' &&
3635
!route.path.includes('/system') &&
37-
(route.path.includes('set') || !route.redirect) &&
36+
((route.path.includes('set') && userStore.isSpaceAdmin) || !route.redirect) &&
3837
route.path !== '/:pathMatch(.*)*' &&
3938
!route.path.includes('dsTable')
4039
)
4140
})
41+
42+
return list
4243
})
4344
</script>
4445

frontend/src/components/layout/Person.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defineProps({
2525
const name = computed(() => userStore.getName)
2626
const account = computed(() => userStore.getAccount)
2727
const currentLanguage = computed(() => userStore.getLanguage)
28-
const isAdmin = computed(() => userStore.getUid === '1')
28+
const isAdmin = computed(() => userStore.isAdmin)
2929
const dialogVisible = ref(false)
3030
3131
const languageList = [

frontend/src/stores/user.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface UserState {
1616
language: string
1717
exp: number
1818
time: number
19+
weight: number
1920
[key: string]: string | number
2021
}
2122

@@ -30,6 +31,7 @@ export const UserStore = defineStore('user', {
3031
language: 'zh-CN',
3132
exp: 0,
3233
time: 0,
34+
weight: 0,
3335
}
3436
},
3537
getters: {
@@ -57,6 +59,15 @@ export const UserStore = defineStore('user', {
5759
getTime(): number {
5860
return this.time
5961
},
62+
isAdmin(): boolean {
63+
return this.uid === '1'
64+
},
65+
getWeight(): number {
66+
return this.weight
67+
},
68+
isSpaceAdmin(): boolean {
69+
return this.uid === '1' || !!this.weight
70+
},
6071
},
6172
actions: {
6273
async login(formData: { username: string; password: string }) {
@@ -72,12 +83,12 @@ export const UserStore = defineStore('user', {
7283
const res: any = await AuthApi.info()
7384
const res_data = res || {}
7485

75-
const keys = ['uid', 'account', 'name', 'oid', 'language', 'exp', 'time'] as const
86+
const keys = ['uid', 'account', 'name', 'oid', 'language', 'exp', 'time', 'weight'] as const
7687

7788
keys.forEach((key) => {
7889
const dkey = key === 'uid' ? 'id' : key
7990
const value = res_data[dkey]
80-
if (key === 'exp' || key === 'time') {
91+
if (key === 'exp' || key === 'time' || key === 'weight') {
8192
this[key] = Number(value)
8293
} else {
8394
this[key] = String(value)
@@ -126,8 +137,22 @@ export const UserStore = defineStore('user', {
126137
locale.value = language */
127138
// locale.setLang(language)
128139
},
140+
setWeight(weight: number) {
141+
wsCache.set('user.weight', weight)
142+
this.weight = weight
143+
},
129144
clear() {
130-
const keys: string[] = ['token', 'uid', 'account', 'name', 'oid', 'language', 'exp', 'time']
145+
const keys: string[] = [
146+
'token',
147+
'uid',
148+
'account',
149+
'name',
150+
'oid',
151+
'language',
152+
'exp',
153+
'time',
154+
'weight',
155+
]
131156
keys.forEach((key) => wsCache.delete('user.' + key))
132157
this.$reset()
133158
},

frontend/src/views/system/member/index.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<script lang="ts" setup>
22
import { ref, computed, onMounted, reactive } from 'vue'
3-
import { uwsOption, workspaceUserList, workspaceUwsDelete, workspaceCreate } from '@/api/workspace'
3+
import {
4+
uwsOption,
5+
workspaceUserList,
6+
workspaceUwsDelete,
7+
workspaceUwsCreate,
8+
} from '@/api/workspace'
49
import icon_add_outlined from '@/assets/svg/icon_add_outlined.svg'
510
import icon_searchOutline_outlined from '@/assets/svg/icon_search-outline_outlined.svg'
611
import EmptyBackground from '@/views/dashboard/common/EmptyBackground.vue'
@@ -142,9 +147,8 @@ const closeField = () => {
142147
}
143148
144149
const saveField = () => {
145-
workspaceCreate({
150+
workspaceUwsCreate({
146151
uid_list: [userInfo.value.id],
147-
weight: 0,
148152
}).then(() => {
149153
ElMessage({
150154
type: 'success',

0 commit comments

Comments
 (0)