feat: Application router permission

This commit is contained in:
zhangzhanwei 2025-06-25 19:04:02 +08:00 committed by zhanweizhang7
parent f6c5d6d9b7
commit bac0f79c93
6 changed files with 138 additions and 25 deletions

View File

@ -95,6 +95,46 @@ const workspace = {
],
'OR'
),
chat_user_edit: (source_id:string) =>
hasPermission(
[
RoleConst.ADMIN,
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_USER_EDIT.getWorkspacePermissionWorkspaceManageRole,
PermissionConst.APPLICATION_CHAT_USER_EDIT.getApplicationWorkspaceResourcePermission(source_id)
],
'OR'
),
chat_log_clear: (source_id:string) =>
hasPermission(
[
RoleConst.ADMIN,
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_LOG_CLEAR_POLICY.getWorkspacePermissionWorkspaceManageRole,
PermissionConst.APPLICATION_CHAT_LOG_CLEAR_POLICY.getApplicationWorkspaceResourcePermission(source_id)
],
'OR'
),
chat_log_export: (source_id:string) =>
hasPermission(
[
RoleConst.ADMIN,
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermissionWorkspaceManageRole,
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getApplicationWorkspaceResourcePermission(source_id)
],
'OR'
),
chat_log_add_knowledge: (source_id:string) =>
hasPermission(
[
RoleConst.ADMIN,
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_LOG_ADD_KNOWLEDGE.getWorkspacePermissionWorkspaceManageRole,
PermissionConst.APPLICATION_CHAT_LOG_ADD_KNOWLEDGE.getApplicationWorkspaceResourcePermission(source_id)
],
'OR'
),
}

View File

@ -1,4 +1,5 @@
import { ChatUserResourceEnum } from '@/enums/workspaceChatUser'
import { get_next_route } from '@/utils/permission'
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
@ -19,6 +20,17 @@ const ApplicationDetailRouter = {
active: 'overview',
parentPath: '/application/:id/:type',
parentName: 'ApplicationDetail',
permission: [
RoleConst.ADMIN,
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
PermissionConst.APPLICATION_OVERVIEW_READ.getWorkspacePermissionWorkspaceManageRole,
() => {
const to: any = get_next_route()
return PermissionConst.APPLICATION_OVERVIEW_READ.getApplicationWorkspaceResourcePermission(
to ? to.params.id : '',
)
}
]
},
component: () => import('@/views/application-overview/index.vue'),
},
@ -32,6 +44,17 @@ const ApplicationDetailRouter = {
active: 'setting',
parentPath: '/application/:id/:type',
parentName: 'ApplicationDetail',
permission: [
RoleConst.ADMIN,
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
PermissionConst.APPLICATION_EDIT.getWorkspacePermissionWorkspaceManageRole,
() => {
const to: any = get_next_route()
return PermissionConst.APPLICATION_EDIT.getApplicationWorkspaceResourcePermission(
to ? to.params.id : '',
)
}
]
},
component: () => import('@/views/application/ApplicationSetting.vue'),
},
@ -45,7 +68,17 @@ const ApplicationDetailRouter = {
active: 'access',
parentPath: '/application/:id/:type',
parentName: 'ApplicationDetail',
permission: [EditionConst.IS_PE, EditionConst.IS_EE],
permission: [
RoleConst.ADMIN,
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
PermissionConst.APPLICATION_ACCESS_READ.getWorkspacePermissionWorkspaceManageRole,
() => {
const to: any = get_next_route()
return PermissionConst.APPLICATION_ACCESS_READ.getApplicationWorkspaceResourcePermission(
to ? to.params.id : '',
)
}
]
},
component: () => import('@/views/application/ApplicationAccess.vue'),
},
@ -60,7 +93,17 @@ const ApplicationDetailRouter = {
parentPath: '/application/:id/:type',
parentName: 'ApplicationDetail',
resourceType: ChatUserResourceEnum.APPLICATION,
permission: [EditionConst.IS_PE, EditionConst.IS_EE],
permission: [
RoleConst.ADMIN,
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_USER_READ.getWorkspacePermissionWorkspaceManageRole,
() => {
const to: any = get_next_route()
return PermissionConst.APPLICATION_CHAT_USER_READ.getApplicationWorkspaceResourcePermission(
to ? to.params.id : '',
)
}
]
},
component: () => import('@/views/chat-user/index.vue'),
},
@ -74,6 +117,17 @@ const ApplicationDetailRouter = {
active: 'chat-log',
parentPath: '/application/:id/:type',
parentName: 'ApplicationDetail',
permission: [
RoleConst.ADMIN,
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_LOG_READ.getWorkspacePermissionWorkspaceManageRole,
() => {
const to: any = get_next_route()
return PermissionConst.APPLICATION_CHAT_LOG_READ.getApplicationWorkspaceResourcePermission(
to ? to.params.id : '',
)
}
]
},
component: () => import('@/views/chat-log/index.vue'),
},

View File

@ -1,7 +1,6 @@
import role from '@/api/system/role'
import { ChatUserResourceEnum } from '@/enums/workspaceChatUser'
import { get_next_route } from '@/utils/permission'
import { PermissionConst, EditionConst, RoleConst } from '@/utils/permission/data'
import { PermissionConst, RoleConst } from '@/utils/permission/data'
const DocumentRouter = {
path: '/knowledge/:id/:folderId',
name: 'KnowledgeDetail',

View File

@ -130,14 +130,18 @@ const PermissionConst = {
APPLICATION_OVERVIEW_API_KEY:new Permission('APPLICATION_OVERVIEW:READ+API_KEY'),
APPLICATION_OVERVIEW_PUBLIC:new Permission('APPLICATION_OVERVIEW:READ+PUBLIC_ACCESS'),
APPLICATION_CHAT_LOG:new Permission('APPLICATION_CHAT_LOG:READ'),
APPLICATION_CHAT_LOG_READ:new Permission('APPLICATION_CHAT_LOG:READ'),
APPLICATION_CHAT_LOG_ANNOTATION:new Permission('APPLICATION_CHAT_LOG:READ+ANNOTATION'),
APPLICATION_CHAT_LOG_EXPORT:new Permission('APPLICATION_CHAT_LOG:READ+EXPORT'),
APPLICATION_CHAT_LOG_POLICY:new Permission('APPLICATION_CHAT_LOG:READ+CLEAR_POLICY'),
APPLICATION_CHAT_LOG_CLEAR_POLICY:new Permission('APPLICATION_CHAT_LOG:READ+CLEAR_POLICY'),
APPLICATION_CHAT_LOG_ADD_KNOWLEDGE:new Permission('APPLICATION_CHAT_LOG:READ+ADD_KNOWLEDGE'),
APPLICATION_ACCESS_READ:new Permission('APPLICATION_ACCESS:READ'),
APPLICATION_ACCESS_EDIT:new Permission('APPLICATION_ACCESS:READ+EDIT'),
APPLICATION_CHAT_USER_READ:new Permission('CHAT_USER:READ'),
APPLICATION_CHAT_USER_EDIT:new Permission('CHAT_USER:READ+EDIT'),
SHARED_TOOL_READ:new Permission('SYSTEM_TOOL:READ'),
SHARED_TOOL_CREATE:new Permission('SYSTEM_TOOL:READ+CREATE'),
SHARED_TOOL_EDIT:new Permission('SYSTEM_TOOL:READ+EDIT'),

View File

@ -40,32 +40,20 @@
<div style="display: flex; align-items: center" class="float-right">
<el-button
@click="dialogVisible = true"
v-hasPermission="[
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
RoleConst.USER.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_LOG_POLICY.getWorkspacePermission,
]"
v-if="permissionPrecise.chat_log_clear(id)"
>
{{ $t('views.chatLog.buttons.clearStrategy') }}
</el-button>
<el-button
@click="exportLog"
v-hasPermission="[
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
RoleConst.USER.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission,
]"
v-if="permissionPrecise.chat_log_export(id)"
>
{{ $t('common.export') }}
</el-button>
<el-button
@click="openDocumentDialog"
:disabled="multipleSelection.length === 0"
v-hasPermission="[
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
RoleConst.USER.getWorkspaceRole,
PermissionConst.APPLICATION_CHAT_LOG_EXPORT.getWorkspacePermission,
]"
v-if="permissionPrecise.chat_log_add_knowledge(id)"
>{{ $t('views.chatLog.addToKnowledge') }}
</el-button>
</div>
@ -304,9 +292,19 @@ import type { FormInstance, FormRules } from 'element-plus'
import { ElTable } from 'element-plus'
import { PermissionConst, RoleConst } from '@/utils/permission/data'
import { hasPermission } from '@/utils/permission/index'
import permissionMap from '@/permission'
const route = useRoute()
const apiType = computed<'workspace'>(() => {
return 'workspace'
})
const permissionPrecise = computed(() => {
return permissionMap['application'][apiType.value]
})
const { application, chatLog, user } = useStore()
const route = useRoute()
const {
params: { id },
} = route as any

View File

@ -41,7 +41,9 @@
{{ paginationConfig.total }}
</span>
</div>
<el-button type="primary" :disabled="current?.is_auth" @click="handleSave">
<el-button type="primary" :disabled="current?.is_auth" @click="handleSave"
v-if="permissionPrecise.chat_user_edit(id)"
>
{{ t('common.save') }}
</el-button>
</div>
@ -54,10 +56,13 @@
<el-input v-if="searchType === 'name'" v-model="searchForm.name" @change="getList"
:placeholder="$t('common.inputPlaceholder')" style="width: 220px" clearable />
</div>
<div class="flex align-center">
<div class="flex align-center"
v-if="permissionPrecise.chat_user_edit(id)"
>
<div class="color-secondary mr-8">{{ $t('views.chatUser.autoAuthorization') }}</div>
<el-switch size="small" :model-value="current?.is_auth" @click="changeAuth"
:loading="loading"></el-switch>
:loading="loading"
></el-switch>
</div>
</div>
@ -108,8 +113,21 @@ import type { ChatUserGroupItem, ChatUserResourceParams, ChatUserGroupUserItem }
import { useRoute } from 'vue-router'
import { ChatUserResourceEnum } from '@/enums/workspaceChatUser'
import { MsgSuccess } from '@/utils/message'
import permissionMap from '@/permission'
const route = useRoute()
const apiType = computed<'workspace'>(() => {
return 'workspace'
})
const permissionPrecise = computed(() => {
return permissionMap['application'][apiType.value]
})
const {
params: { id },
} = route as any
const resource: ChatUserResourceParams = reactive({ resource_id: route.params.id as string, resource_type: route.meta.resourceType as ChatUserResourceEnum })
const filterText = ref('')