Skip to content

Commit c988045

Browse files
committed
feat: System role permission
1 parent 15bfe23 commit c988045

File tree

6 files changed

+185
-133
lines changed

6 files changed

+185
-133
lines changed

ui/src/router/modules/system.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const systemRouter = {
3535
permission: [
3636
new ComplexPermission(
3737
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole],
38-
[PermissionConst.ROLE_READ],
38+
[PermissionConst.ROLE_READ, PermissionConst.WORKSPACE_ROLE_READ],
3939
[EditionConst.IS_EE],
4040
'OR',
4141
),
@@ -57,7 +57,7 @@ const systemRouter = {
5757
new ComplexPermission(
5858
[RoleConst.WORKSPACE_MANAGE, RoleConst.ADMIN],
5959
[
60-
PermissionConst.WORKSPACE_READ.getWorkspacePermissionWorkspaceManageRole,
60+
PermissionConst.WORKSPACE_WORKSPACE_READ,
6161
PermissionConst.WORKSPACE_READ,
6262
],
6363
[EditionConst.IS_EE],

ui/src/utils/dynamics-api/permission-api.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/dat
22
import { hasPermission } from '@/utils/permission/index'
33
import roleSystemApi from '@/api/system/role'
44
import roleWorkspaceApi from '@/api/workspace/role'
5+
import { ComplexPermission } from '../permission/type'
56

67
// 系统管理员 API
78
const systemApiMap = {
@@ -19,11 +20,19 @@ const workspaceApiMap = {
1920

2021
export function loadPermissionApi(type: string) {
2122
if (hasPermission(EditionConst.IS_EE, 'OR')) {
22-
if (hasPermission([RoleConst.ADMIN], 'OR')) {
23-
// 加载企业版工作空间管理员 API
24-
return systemApiMap[type]
25-
} else if (hasPermission([RoleConst.WORKSPACE_MANAGE.getWorkspaceRole], 'OR')) {
23+
if (hasPermission(new ComplexPermission (
24+
[RoleConst.ADMIN],
25+
[PermissionConst.ROLE_READ],
26+
[],
27+
'OR'),'OR')) {
2628
// 加载系统管理员 API
29+
return systemApiMap[type]
30+
} if (hasPermission(new ComplexPermission (
31+
[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole],
32+
[PermissionConst.WORKSPACE_ROLE_READ.getWorkspacePermissionWorkspaceManageRole],
33+
[],
34+
'OR'),'OR' )) {
35+
// 加载企业版工作空间管理员 API
2736
return workspaceApiMap[type]
2837
}
2938
}

ui/src/utils/permission/data.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ const PermissionConst = {
7575

7676

7777
ROLE_READ: new Permission('ROLE:READ'),
78-
ROLE_CREATE: new Permission('ROLE:READ'),
79-
ROLE_EDIT: new Permission('ROLE:READ'),
80-
ROLE_DELETE: new Permission('ROLE:READ'),
81-
ROLE_ADD_MEMBER: new Permission('ROLE:READ'),
82-
ROLE_REMOVE_MEMBER: new Permission('ROLE:READ'),
78+
ROLE_CREATE: new Permission('ROLE:READ+CREATE'),
79+
ROLE_EDIT: new Permission('ROLE:READ+EDIT'),
80+
ROLE_DELETE: new Permission('ROLE:READ+DELETE'),
81+
ROLE_ADD_MEMBER: new Permission('ROLE:READ+ADD_MEMBER'),
82+
ROLE_REMOVE_MEMBER: new Permission('ROLE:READ+REMOVE_MEMBER'),
8383

8484

8585
KNOWLEDGE_READ: new Permission('KNOWLEDGE:READ'),

ui/src/views/system/role/component/Member.vue

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
@click="handleAdd"
77
v-hasPermission="
88
new ComplexPermission(
9-
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole],
10-
[PermissionConst.ROLE_ADD_MEMBER.getWorkspacePermission],
9+
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE],
10+
[PermissionConst.WORKSPACE_ROLE_ADD_MEMBER, PermissionConst.ROLE_ADD_MEMBER],
1111
[],
1212
'OR',
13-
)
14-
"
13+
)"
1514
>
1615
{{ $t('views.role.member.add') }}
1716
</el-button>
@@ -57,8 +56,8 @@
5756
@click.stop="handleDelete(row)"
5857
v-hasPermission="
5958
new ComplexPermission(
60-
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole],
61-
[PermissionConst.ROLE_REMOVE_MEMBER.getWorkspacePermission],
59+
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE],
60+
[PermissionConst.ROLE_REMOVE_MEMBER, PermissionConst.WORKSPACE_ROLE_REMOVE_MEMBER],
6261
[],
6362
'OR',
6463
)

ui/src/views/system/role/index.vue

Lines changed: 146 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
<div class="role-manage p-16-24">
33
<h2 class="mb-16">{{ $t('views.role.title') }}</h2>
44
<el-card style="--el-card-padding: 0">
5-
<div class="flex main-calc-height">
6-
<div class="role-left border-r p-16">
7-
<div class="p-8 pb-0 mb-12">
5+
<div class="flex h-full">
6+
<div class="role-left border-r">
7+
<div class="p-24 pb-0">
88
<el-input
99
v-model="filterText"
1010
:placeholder="$t('common.search')"
@@ -14,113 +14,145 @@
1414
</div>
1515
<div class="list-height-left">
1616
<el-scrollbar v-loading="loading">
17-
<div class="color-secondary lighter ml-8 mb-8">
18-
<span>{{ $t('views.role.internalRole') }}</span>
19-
</div>
20-
<common-list
21-
:data="filterInternalRole"
22-
@click="clickRole"
23-
:default-active="currentRole?.id"
24-
@mouseenter="mouseenter"
25-
@mouseleave="mouseId = ''"
26-
>
27-
<template #default="{ row }">
28-
<div class="flex-between">
29-
<span class="mr-8">{{ row.role_name }}</span>
30-
<div @click.stop v-show="mouseId === row.id">
31-
<el-dropdown :teleported="false">
32-
<el-button text>
33-
<el-icon class="color-secondary">
34-
<MoreFilled />
35-
</el-icon>
36-
</el-button>
37-
<template #dropdown>
38-
<el-dropdown-menu style="min-width: 80px">
39-
<el-dropdown-item @click.stop="createOrUpdateRole(row)" class="p-8">
40-
<el-icon><EditPen /></el-icon>
41-
{{ $t('common.rename') }}
42-
</el-dropdown-item>
43-
<el-dropdown-item @click.stop="deleteRole(row)" class="border-t p-8">
44-
<el-icon><Delete /></el-icon>
45-
{{ $t('common.delete') }}
46-
</el-dropdown-item>
47-
</el-dropdown-menu>
48-
</template>
49-
</el-dropdown>
17+
<div class="p-16">
18+
<div class="color-secondary lighter ml-8 mb-8">
19+
<span>{{ $t('views.role.internalRole') }}</span>
20+
</div>
21+
<common-list
22+
:data="filterInternalRole"
23+
@click="clickRole"
24+
:default-active="currentRole?.id"
25+
@mouseenter="mouseenter"
26+
@mouseleave="mouseId = ''"
27+
>
28+
<template #default="{ row }">
29+
<div class="flex-between">
30+
<span class="mr-8">{{ row.role_name }}</span>
31+
<div @click.stop v-show="mouseId === row.id">
32+
<el-dropdown :teleported="false">
33+
<el-button text>
34+
<el-icon class="color-secondary">
35+
<MoreFilled />
36+
</el-icon>
37+
</el-button>
38+
<template #dropdown>
39+
<el-dropdown-menu style="min-width: 80px">
40+
<el-dropdown-item @click.stop="createOrUpdateRole(row)" class="p-8"
41+
v-if="hasPermission(
42+
new ComplexPermission(
43+
[RoleConst.ADMIN],
44+
[PermissionConst.ROLE_EDIT],
45+
[],'OR'
46+
),'OR'
47+
)"
48+
>
49+
<el-icon><EditPen /></el-icon>
50+
{{ $t('common.rename') }}
51+
</el-dropdown-item>
52+
<el-dropdown-item @click.stop="deleteRole(row)" class="border-t p-8"
53+
v-if="hasPermission(
54+
new ComplexPermission(
55+
[RoleConst.ADMIN],
56+
[PermissionConst.ROLE_DELETE],
57+
[],'OR'
58+
),'OR'
59+
)"
60+
>
61+
<el-icon><Delete /></el-icon>
62+
{{ $t('common.delete') }}
63+
</el-dropdown-item>
64+
</el-dropdown-menu>
65+
</template>
66+
</el-dropdown>
67+
</div>
5068
</div>
51-
</div>
52-
</template>
53-
<template #empty>
54-
<span></span>
55-
</template>
56-
</common-list>
69+
</template>
70+
<template #empty>
71+
<span></span>
72+
</template>
73+
</common-list>
5774

58-
<div class="ml-8 border-t flex-between mb-8" style="padding-top: 12px">
59-
<span class="color-secondary lighter">{{ $t('views.role.customRole') }}</span>
60-
<el-tooltip
61-
effect="dark"
62-
:content="`${$t('common.create')}${$t('views.role.customRole')}`"
63-
placement="top"
64-
>
65-
<el-button
66-
type="primary"
67-
text
68-
@click="createOrUpdateRole()"
69-
v-hasPermission="
70-
new ComplexPermission(
71-
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE.getWorkspaceRole],
72-
[PermissionConst.ROLE_CREATE.getWorkspacePermission],
73-
[],
74-
'OR',
75-
)
76-
"
75+
<div class="ml-8 border-t flex-between mb-8" style="padding-top: 12px">
76+
<span class="color-secondary lighter">{{ $t('views.role.customRole') }}</span>
77+
<el-tooltip
78+
effect="dark"
79+
:content="`${$t('common.create')}${$t('views.role.customRole')}`"
80+
placement="top"
7781
>
78-
<el-icon :size="18"><Plus /></el-icon>
79-
</el-button>
80-
</el-tooltip>
81-
</div>
82-
<common-list
83-
:data="filterCustomRole"
84-
@click="clickRole"
85-
:default-active="currentRole?.id"
86-
@mouseenter="mouseenter"
87-
@mouseleave="mouseId = ''"
88-
>
89-
<template #default="{ row }">
90-
<div class="flex-between">
91-
<span>
92-
{{ row.role_name }}
93-
<span class="color-input-placeholder ml-4"
94-
>({{ roleTypeMap[row.type as RoleTypeEnum] }})</span
95-
>
96-
</span>
97-
<div @click.stop v-show="mouseId === row.id">
98-
<el-dropdown :teleported="false">
99-
<el-button text>
100-
<el-icon class="color-secondary">
101-
<MoreFilled />
102-
</el-icon>
103-
</el-button>
104-
<template #dropdown>
105-
<el-dropdown-menu style="min-width: 80px">
106-
<el-dropdown-item @click.stop="createOrUpdateRole(row)" class="p-8">
107-
<el-icon><EditPen /></el-icon>
108-
{{ $t('common.rename') }}
109-
</el-dropdown-item>
110-
<el-dropdown-item @click.stop="deleteRole(row)" class="border-t p-8">
111-
<el-icon><Delete /></el-icon>
112-
{{ $t('common.delete') }}
113-
</el-dropdown-item>
114-
</el-dropdown-menu>
115-
</template>
116-
</el-dropdown>
82+
<el-button
83+
type="primary"
84+
text
85+
@click="createOrUpdateRole()"
86+
v-hasPermission="
87+
new ComplexPermission(
88+
[RoleConst.ADMIN],
89+
[PermissionConst.ROLE_CREATE],
90+
[],
91+
'OR',)"
92+
>
93+
<el-icon :size="18"><Plus /></el-icon>
94+
</el-button>
95+
</el-tooltip>
96+
</div>
97+
<common-list
98+
:data="filterCustomRole"
99+
@click="clickRole"
100+
:default-active="currentRole?.id"
101+
@mouseenter="mouseenter"
102+
@mouseleave="mouseId = ''"
103+
>
104+
<template #default="{ row }">
105+
<div class="flex-between">
106+
<span>
107+
{{ row.role_name }}
108+
<span class="color-input-placeholder ml-4"
109+
>({{ roleTypeMap[row.type as RoleTypeEnum] }})</span
110+
>
111+
</span>
112+
<div @click.stop v-show="mouseId === row.id">
113+
<el-dropdown :teleported="false">
114+
<el-button text>
115+
<el-icon class="color-secondary">
116+
<MoreFilled />
117+
</el-icon>
118+
</el-button>
119+
<template #dropdown>
120+
<el-dropdown-menu style="min-width: 80px">
121+
<el-dropdown-item @click.stop="createOrUpdateRole(row)" class="p-8"
122+
v-if="hasPermission(
123+
new ComplexPermission(
124+
[RoleConst.ADMIN],
125+
[PermissionConst.ROLE_EDIT],
126+
[],'OR'
127+
),'OR'
128+
)"
129+
>
130+
<el-icon><EditPen /></el-icon>
131+
{{ $t('common.rename') }}
132+
</el-dropdown-item>
133+
<el-dropdown-item @click.stop="deleteRole(row)" class="border-t p-8"
134+
v-if="hasPermission(
135+
new ComplexPermission(
136+
[RoleConst.ADMIN],
137+
[PermissionConst.ROLE_DELETE],
138+
[],'OR'
139+
),'OR'
140+
)"
141+
>
142+
<el-icon><Delete /></el-icon>
143+
{{ $t('common.delete') }}
144+
</el-dropdown-item>
145+
</el-dropdown-menu>
146+
</template>
147+
</el-dropdown>
148+
</div>
117149
</div>
118-
</div>
119-
</template>
120-
<template #empty>
121-
<span></span>
122-
</template>
123-
</common-list>
150+
</template>
151+
<template #empty>
152+
<span></span>
153+
</template>
154+
</common-list>
155+
</div>
124156
</el-scrollbar>
125157
</div>
126158
</div>
@@ -176,6 +208,7 @@ import { MsgSuccess, MsgConfirm } from '@/utils/message'
176208
import { loadPermissionApi } from '@/utils/dynamics-api/permission-api'
177209
import { PermissionConst, RoleConst } from '@/utils/permission/data'
178210
import { ComplexPermission } from '@/utils/permission/type'
211+
import { hasPermission } from '@/utils/permission/index'
179212
180213
const filterText = ref('')
181214
const loading = ref(false)
@@ -240,14 +273,12 @@ function deleteRole(item: RoleItem) {
240273
},
241274
)
242275
.then(() => {
243-
loadPermissionApi('role')
244-
.deleteRole(item.id, loading)
245-
.then(async () => {
246-
MsgSuccess(t('common.deleteSuccess'))
247-
await getRole()
248-
currentRole.value =
249-
item.id === currentRole.value?.id ? internalRoleList.value[0] : currentRole.value
250-
})
276+
loadPermissionApi('role').deleteRole(item.id, loading).then(async () => {
277+
MsgSuccess(t('common.deleteSuccess'))
278+
await getRole()
279+
currentRole.value =
280+
item.id === currentRole.value?.id ? internalRoleList.value[0] : currentRole.value
281+
})
251282
})
252283
.catch(() => {})
253284
}
@@ -289,3 +320,4 @@ function mouseenter(row: any) {
289320
}
290321
}
291322
</style>
323+

0 commit comments

Comments
 (0)