fix: resource_permission

This commit is contained in:
wangdan-fit2cloud 2025-06-23 17:49:43 +08:00
parent 0f8fe31e52
commit add71a4bc2
4 changed files with 56 additions and 24 deletions

View File

@ -44,7 +44,12 @@ const putResourceAuthorization: (
body: any, body: any,
loading?: Ref<boolean>, loading?: Ref<boolean>,
) => Promise<Result<any>> = (workspace_id, user_id, body, loading) => { ) => Promise<Result<any>> = (workspace_id, user_id, body, loading) => {
return put(`${prefix}/${workspace_id}/user_resource_permission/user/${user_id}`, body, loading) return put(
`${prefix}/${workspace_id}/user_resource_permission/user/${user_id}`,
body,
{},
loading,
)
} }
/** /**

View File

@ -4,7 +4,7 @@
<div class="flex align-center" v-if="hasPermission(EditionConst.IS_EE, 'OR')"> <div class="flex align-center" v-if="hasPermission(EditionConst.IS_EE, 'OR')">
<!-- 企业版: 选优先级--> <!-- 企业版: 选优先级-->
<span class="lighter mr-16">{{ $t('views.resourceAuthorization.priority.label') }}</span> <span class="lighter mr-16">{{ $t('views.resourceAuthorization.priority.label') }}</span>
<el-radio-group v-model="isRole"> <el-radio-group v-model="radioRole">
<el-radio :value="true" size="large">{{ <el-radio :value="true" size="large">{{
$t('views.resourceAuthorization.priority.role') $t('views.resourceAuthorization.priority.role')
}}</el-radio> }}</el-radio>
@ -179,10 +179,16 @@ const props = defineProps({
type: String, type: String,
tableHeight: Number, tableHeight: Number,
manage: Boolean, manage: Boolean,
isRole: Boolean,
}) })
const emit = defineEmits(['update:data', 'refreshData','update:isRole'])
const radioRole = computed({
get: () => props.isRole,
set: (v:boolean) => {
emit('update:isRole', v)
const isRole = ref(false) }
})
const isKnowledge = computed(() => props.type === AuthorizationEnum.KNOWLEDGE) const isKnowledge = computed(() => props.type === AuthorizationEnum.KNOWLEDGE)
const isApplication = computed(() => props.type === AuthorizationEnum.APPLICATION) const isApplication = computed(() => props.type === AuthorizationEnum.APPLICATION)
@ -208,7 +214,7 @@ const dfsPermission = (arr: any = [], Name: string | number, e: boolean, idArr:
}) })
} }
const emit = defineEmits(['update:data', 'refreshData'])
const filterText = ref('') const filterText = ref('')

View File

@ -70,6 +70,7 @@
:tableHeight="tableHeight" :tableHeight="tableHeight"
:manage="isManage(currentType)" :manage="isManage(currentType)"
@refreshData="refreshData" @refreshData="refreshData"
v-model:isRole="item.isRole"
></PermissionSetting> ></PermissionSetting>
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
@ -98,6 +99,7 @@ import { hasPermission } from '@/utils/permission/index'
import WorkspaceApi from '@/api/workspace/workspace.ts' import WorkspaceApi from '@/api/workspace/workspace.ts'
import type { WorkspaceItem } from '@/api/type/workspace' import type { WorkspaceItem } from '@/api/type/workspace'
const PermissionSettingRef = ref()
const loading = ref(false) const loading = ref(false)
const rLoading = ref(false) const rLoading = ref(false)
const memberList = ref<any[]>([]) // const memberList = ref<any[]>([]) //
@ -115,11 +117,13 @@ const settingTags = reactive([
label: t('views.knowledge.title'), label: t('views.knowledge.title'),
value: AuthorizationEnum.KNOWLEDGE, value: AuthorizationEnum.KNOWLEDGE,
data: [] as any, data: [] as any,
isRole: false,
}, },
{ {
label: t('views.application.title'), label: t('views.application.title'),
value: AuthorizationEnum.APPLICATION, value: AuthorizationEnum.APPLICATION,
data: [] as any, data: [] as any,
isRole: false,
}, },
]) ])
@ -147,8 +151,7 @@ const flotTree = (tree: Array<any>, result: Array<any>) => {
return result return result
} }
function submitPermissions() { function submitPermissions() {
const user_resource_permission_list = settingTags const user_resource_permission_list = settingTags.map((item: any, index: number) => {
.map((item: any) => {
return flotTree(item.data, []) return flotTree(item.data, [])
.filter((v: any) => !v.isFolder) .filter((v: any) => !v.isFolder)
.map((v: any) => { .map((v: any) => {
@ -156,13 +159,11 @@ function submitPermissions() {
target_id: v.id, target_id: v.id,
auth_target_type: item.value, auth_target_type: item.value,
permission: v.permission, permission: v.permission,
auth_type: 'RESOURCE_PERMISSION_GROUP', auth_type: item.isRole ? 'ROLE' : 'RESOURCE_PERMISSION_GROUP',
} }
}) })
}) })
.reduce((pre, next) => {
return [...pre, ...next]
}, [])
AuthorizationApi.putResourceAuthorization( AuthorizationApi.putResourceAuthorization(
currentWorkspaceId.value || 'default', currentWorkspaceId.value || 'default',
currentUser.value, currentUser.value,

View File

@ -160,7 +160,23 @@
</CardBox> </CardBox>
</el-col> </el-col>
<el-col v-else :xs="24" :sm="12" :md="12" :lg="8" :xl="6" class="mb-16"> <el-col v-else :xs="24" :sm="12" :md="12" :lg="8" :xl="6" class="mb-16">
<CardBox :title="item.name" :description="item.desc" class="cursor"> <CardBox
:title="item.name"
:description="item.desc"
class="cursor"
@click.stop="openCreateDialog(item)"
:disabled="
hasPermission(
[
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
RoleConst.USER.getWorkspaceRole,
PermissionConst.TOOL_EDIT.getWorkspacePermissionWorkspaceManageRole,
PermissionConst.TOOL_EDIT.getWorkspacePermission,
],
'OR',
)
"
>
<template #icon> <template #icon>
<el-avatar <el-avatar
v-if="isAppIcon(item?.icon)" v-if="isAppIcon(item?.icon)"
@ -370,7 +386,7 @@ function openCreateDialog(data?: any) {
} }
ToolDrawertitle.value = data ? t('views.tool.editTool') : t('views.tool.createTool') ToolDrawertitle.value = data ? t('views.tool.editTool') : t('views.tool.createTool')
if (data) { if (data) {
ToolApi.getToolById(data?.id, changeStateloading).then((res) => { ToolApi.getToolById(data?.id, loading).then((res) => {
ToolFormDrawerRef.value.open(res.data) ToolFormDrawerRef.value.open(res.data)
}) })
} else { } else {
@ -411,6 +427,8 @@ async function changeState(row: any) {
} }
ToolApi.putTool(row.id, obj, changeStateloading) ToolApi.putTool(row.id, obj, changeStateloading)
.then(() => { .then(() => {
const index = toolList.value.findIndex((v) => v.id === row.id)
toolList.value[index].is_active = !row.is_active
return true return true
}) })
.catch(() => { .catch(() => {
@ -434,6 +452,8 @@ async function changeState(row: any) {
} }
ToolApi.putTool(row.id, obj, changeStateloading) ToolApi.putTool(row.id, obj, changeStateloading)
.then(() => { .then(() => {
const index = toolList.value.findIndex((v) => v.id === row.id)
toolList.value[index].is_active = !row.is_active
return true return true
}) })
.catch(() => { .catch(() => {