Skip to content

Commit 6485d12

Browse files
feat: Support folder authorization(#3853)
1 parent 0bc635a commit 6485d12

File tree

3 files changed

+88
-369
lines changed

3 files changed

+88
-369
lines changed

ui/src/components/resource-authorization-drawer/index.vue

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,29 @@
122122
<!-- 单个资源授权提示框 -->
123123
<el-dialog
124124
v-model="singleSelectDialogVisible"
125-
:title="$t('views.system.resourceAuthorization.setting.configure')"
125+
:title="$t('views.system.resourceAuthorization.setting.effectiveResource')"
126126
destroy-on-close
127127
@close="closeSingleSelectDialog"
128+
width="500px"
128129
>
129130
<el-radio-group v-model="authAllChildren" class="radio-block">
130-
<el-radio :value="false">
131-
<p class="color-text-primary lighter">{{ $t('views.system.resourceAuthorization.setting.currentOnly') }}</p>
132-
</el-radio>
133-
<el-radio :value="true">
134-
<p class="color-text-primary lighter">{{ $t('views.system.resourceAuthorization.setting.includeAll') }}</p>
135-
</el-radio>
131+
<el-radio :value="false">
132+
<p class="color-text-primary lighter">
133+
{{ $t('views.system.resourceAuthorization.setting.currentOnly') }}
134+
</p>
135+
</el-radio>
136+
<el-radio :value="true">
137+
<p class="color-text-primary lighter">
138+
{{ $t('views.system.resourceAuthorization.setting.includeAll') }}
139+
</p>
140+
</el-radio>
136141
</el-radio-group>
137142
<template #footer>
138143
<div class="dialog-footer mt-24">
139144
<el-button @click="closeSingleSelectDialog">{{ $t('common.cancel') }}</el-button>
140-
<el-button type="primary" @click="confirmSinglePermission">{{ $t('common.confirm') }}</el-button>
145+
<el-button type="primary" @click="confirmSinglePermission">{{
146+
$t('common.confirm')
147+
}}</el-button>
141148
</div>
142149
</template>
143150
</el-dialog>
@@ -148,6 +155,7 @@
148155
:title="$t('views.system.resourceAuthorization.setting.configure')"
149156
destroy-on-close
150157
@close="closeDialog"
158+
width="500px"
151159
>
152160
<el-radio-group v-model="radioPermission" class="radio-block">
153161
<template v-for="(item, index) in getFolderPermissionOptions()" :key="index">
@@ -160,15 +168,21 @@
160168
<!-- 如果是文件夹,显示子资源选项 -->
161169
<div v-if="isFolder" class="mt-16">
162170
<el-divider />
163-
<div class="color-text-primary mb-8">{{ $t('views.system.resourceAuthorization.setting.effectiveResource') }}</div>
164-
<el-radio-group v-model="batchAuthAllChildren" class="radio-block">
165-
<el-radio :value="false">
166-
<p class="color-text-primary lighter">{{ $t('views.system.resourceAuthorization.setting.currentOnly') }}</p>
167-
</el-radio>
168-
<el-radio :value="true">
169-
<p class="color-text-primary lighter">{{ $t('views.system.resourceAuthorization.setting.includeAll') }}</p>
170-
</el-radio>
171-
</el-radio-group>
171+
<div class="color-text-primary mb-8">
172+
{{ $t('views.system.resourceAuthorization.setting.effectiveResource') }}
173+
</div>
174+
<el-radio-group v-model="batchAuthAllChildren" class="radio-block">
175+
<el-radio :value="false">
176+
<p class="color-text-primary lighter">
177+
{{ $t('views.system.resourceAuthorization.setting.currentOnly') }}
178+
</p>
179+
</el-radio>
180+
<el-radio :value="true">
181+
<p class="color-text-primary lighter">
182+
{{ $t('views.system.resourceAuthorization.setting.includeAll') }}
183+
</p>
184+
</el-radio>
185+
</el-radio-group>
172186
</div>
173187
<template #footer>
174188
<div class="dialog-footer mt-24">
@@ -211,14 +225,13 @@ const apiType = computed(() => {
211225
const folderType = computed(() => {
212226
if (route.path.includes('application')) {
213227
return 'application'
214-
}
215-
else if (route.path.includes('knowledge')) {
228+
} else if (route.path.includes('knowledge')) {
216229
return 'knowledge'
217-
}
218-
else if (route.path.includes('tool')) {
230+
} else if (route.path.includes('tool')) {
219231
return 'tool'
232+
} else {
233+
return 'application'
220234
}
221-
else {return 'application'}
222235
})
223236
224237
const permissionPrecise = computed(() => {
@@ -228,33 +241,33 @@ const permissionPrecise = computed(() => {
228241
// 取出文件夹id
229242
function getAllFolderIds(data: any) {
230243
if (!data) return []
231-
return [data.id,...(data.children?.flatMap((child: any) => getAllFolderIds(child)) || [])]
244+
return [data.id, ...(data.children?.flatMap((child: any) => getAllFolderIds(child)) || [])]
232245
}
233246
234247
const RESOURCE_PERMISSION_MAP = {
235-
application: PermissionConst.APPLICATION_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
236-
knowledge: PermissionConst.KNOWLEDGE_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
248+
application:
249+
PermissionConst.APPLICATION_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
250+
knowledge:
251+
PermissionConst.KNOWLEDGE_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
237252
tool: PermissionConst.TOOL_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
238-
}
253+
}
239254
240255
const resourceAuthorizationOfManager = computed(() => {
241256
return RESOURCE_PERMISSION_MAP[folderType.value]
242257
})
243258
244259
// 过滤没有Manage权限的文件夹ID
245260
function filterHasPermissionFolderIds(folderIds: string[]) {
246-
if (hasPermission(
247-
[
248-
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
249-
resourceAuthorizationOfManager.value
250-
],'OR'
251-
)) {
261+
if (
262+
hasPermission(
263+
[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, resourceAuthorizationOfManager.value],
264+
'OR',
265+
)
266+
) {
252267
return folderIds
268+
} else {
269+
return folderIds.filter((id) => permissionPrecise.value.folderManage(id))
253270
}
254-
else {
255-
return folderIds.filter(id => permissionPrecise.value.folderManage(id))
256-
}
257-
258271
}
259272
260273
function confirmSinglePermission() {
@@ -270,7 +283,7 @@ function confirmSinglePermission() {
270283
user_id: row.id,
271284
permission: val,
272285
include_children: authAllChildren.value,
273-
...(folderIds.length > 0 && {folder_ids: folderIds})
286+
...(folderIds.length > 0 && { folder_ids: folderIds }),
274287
},
275288
]
276289
submitPermissions(obj)
@@ -354,7 +367,7 @@ const handleSelectionChange = (val: any[]) => {
354367
355368
const dialogVisible = ref(false)
356369
const singleSelectDialogVisible = ref(false)
357-
const pendingPermissionChange = ref<{ val: any; row: any; } | null>(null)
370+
const pendingPermissionChange = ref<{ val: any; row: any } | null>(null)
358371
const radioPermission = ref('')
359372
const authAllChildren = ref(false)
360373
function openMulConfigureDialog() {
@@ -379,7 +392,7 @@ function submitDialog() {
379392
user_id: item.id,
380393
permission: radioPermission.value,
381394
include_children: batchAuthAllChildren.value,
382-
...(folderIds.length > 0 && { folder_ids: folderIds })
395+
...(folderIds.length > 0 && { folder_ids: folderIds }),
383396
}))
384397
submitPermissions(obj)
385398
closeDialog()
@@ -403,7 +416,7 @@ function closeDialog() {
403416
function permissionsHandle(val: any, row: any) {
404417
if (props.isFolder) {
405418
singleSelectDialogVisible.value = true
406-
pendingPermissionChange.value = {val, row}
419+
pendingPermissionChange.value = { val, row }
407420
return
408421
}
409422
const obj = [
@@ -415,7 +428,7 @@ function permissionsHandle(val: any, row: any) {
415428
submitPermissions(obj)
416429
}
417430
418-
function submitPermissions( obj: any) {
431+
function submitPermissions(obj: any) {
419432
const workspaceId = user.getWorkspaceId() || 'default'
420433
loadSharedApi({ type: 'resourceAuthorization', systemType: apiType.value })
421434
.putResourceAuthorization(workspaceId, targetId.value, props.type, obj, loading)
@@ -440,12 +453,13 @@ const getPermissionList = () => {
440453
loading,
441454
)
442455
.then((res: any) => {
443-
permissionData.value = res.data.records.map((item: any) => {
444-
if (props.isRootFolder && item.permission === 'NOT_AUTH') {
445-
return {...item, permission: 'VIEW'}
446-
}
447-
return item
448-
}) || []
456+
permissionData.value =
457+
res.data.records.map((item: any) => {
458+
if (props.isRootFolder && item.permission === 'NOT_AUTH') {
459+
return { ...item, permission: 'VIEW' }
460+
}
461+
return item
462+
}) || []
449463
paginationConfig.total = res.data.total || 0
450464
})
451465
}

0 commit comments

Comments
 (0)