Skip to content

Commit 720f89e

Browse files
committed
feat: tool model resource permission
1 parent ea7b854 commit 720f89e

File tree

7 files changed

+72
-3
lines changed

7 files changed

+72
-3
lines changed

apps/system_manage/models/workspace_user_permission.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class AuthTargetType(models.TextChoices):
2020
"""授权目标"""
2121
KNOWLEDGE = Group.KNOWLEDGE.value, '知识库'
2222
APPLICATION = Group.APPLICATION.value, '应用'
23+
TOOL = Group.TOOL.value, '工具'
24+
MODEL = Group.MODEL.value, '模型'
2325

2426

2527
class WorkspaceUserResourcePermission(models.Model):

apps/system_manage/serializers/user_resource_permission.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
from common.utils.split_model import group_by
2727
from knowledge.models import Knowledge
2828
from maxkb.conf import PROJECT_DIR
29+
from models_provider.models import Model
2930
from system_manage.models import WorkspaceUserResourcePermission, AuthTargetType
31+
from tools.models import Tool
3032

3133

3234
class PermissionSerializer(serializers.Serializer):
@@ -64,7 +66,7 @@ def is_valid(self, *, workspace_id=None, raise_exception=False):
6466
illegal_target_id_list = select_list(
6567
get_file_content(
6668
os.path.join(PROJECT_DIR, "apps", "system_manage", 'sql', 'check_member_permission_target_exists.sql')),
67-
[json.dumps(user_resource_permission_list), workspace_id, workspace_id])
69+
[json.dumps(user_resource_permission_list), workspace_id, workspace_id, workspace_id, workspace_id])
6870
if illegal_target_id_list is not None and len(illegal_target_id_list) > 0:
6971
raise AppApiException(500,
7072
_('Non-existent application|knowledge base id[') + str(illegal_target_id_list) + ']')
@@ -78,6 +80,10 @@ def get_queryset(self):
7880
return {
7981
"knowledge_query_set": QuerySet(Knowledge)
8082
.filter(workspace_id=self.data.get('workspace_id')),
83+
'tool_query_set': QuerySet(Tool)
84+
.filter(workspace_id=self.data.get('workspace_id')),
85+
'model_query_set': QuerySet(Model)
86+
.filter(workspace_id=self.data.get('workspace_id')),
8187
'application_query_set': QuerySet(Application)
8288
.filter(workspace_id=self.data.get('workspace_id')),
8389
'workspace_user_resource_permission_query_set': QuerySet(WorkspaceUserResourcePermission).filter(

apps/system_manage/sql/check_member_permission_target_exists.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ FROM
1717
'APPLICATION' AS "auth_target_type"
1818
FROM
1919
application
20+
WHERE workspace_id= %s
21+
UNION
22+
SELECT
23+
"id",
24+
'MODEL' AS "auth_target_type"
25+
FROM
26+
model
27+
WHERE workspace_id= %s
28+
UNION
29+
SELECT
30+
"id",
31+
'TOOL' AS "auth_target_type"
32+
FROM
33+
tool
2034
WHERE workspace_id= %s
2135
) "app_and_knowledge_temp"
2236
ON "app_and_knowledge_temp"."id" = static_temp."target_id" and app_and_knowledge_temp."auth_target_type"=static_temp."auth_target_type"

apps/system_manage/sql/get_user_resource_permission.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ FROM (SELECT "id",
2020
folder_id
2121
FROM application
2222
${application_query_set}
23+
UNION
24+
SELECT "id",
25+
"name",
26+
'TOOL' AS "auth_target_type",
27+
user_id,
28+
workspace_id,
29+
icon,
30+
folder_id
31+
FROM tool
32+
${tool_query_set}
33+
UNION
34+
SELECT "id",
35+
"name",
36+
'MODEL' AS "auth_target_type",
37+
user_id,
38+
workspace_id,
39+
provider as icon,
40+
'default' as folder_id
41+
FROM model
42+
${model_query_set}
2343
) app_or_knowledge
2444
LEFT JOIN (SELECT *
2545
FROM workspace_user_resource_permission

ui/src/api/system/resource-authorization.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Permission } from '@/utils/permission/type'
12
import { Result } from '@/request/Result'
23
import { get, put, post, del } from '@/request/index'
34
import type { pageRequest } from '@/api/type/common'
@@ -82,6 +83,19 @@ const getSystemFolder: (
8283
data?: any,
8384
loading?: Ref<boolean>,
8485
) => Promise<Result<Array<any>>> = (workspace_id, source, data, loading) => {
86+
if (source == 'MODEL') {
87+
return Promise.resolve(
88+
Result.success([
89+
{
90+
id: 'default',
91+
name: '根目录',
92+
desc: null,
93+
parent_id: null,
94+
children: [],
95+
},
96+
]),
97+
)
98+
}
8599
return get(`${prefix}/${workspace_id}/${source}/folder`, data, loading)
86100
}
87101

ui/src/enums/system.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ export enum AuthorizationEnum {
44
ROLE = 'ROLE',
55
KNOWLEDGE = 'KNOWLEDGE',
66
APPLICATION = 'APPLICATION',
7+
MODEL = 'MODEL',
8+
TOOL = 'TOOL',
79
}
810

911
export enum RoleTypeEnum {
1012
ADMIN = 'ADMIN',
1113
USER = 'USER',
1214
WORKSPACE_MANAGE = 'WORKSPACE_MANAGE',
13-
}
15+
}

ui/src/views/system/resource-authorization/index.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ const filterText = ref('')
110110
const activeName = ref(AuthorizationEnum.KNOWLEDGE)
111111
const tableHeight = ref(0)
112112
113-
114113
const settingTags = reactive([
115114
{
116115
label: t('views.knowledge.title'),
@@ -124,6 +123,18 @@ const settingTags = reactive([
124123
data: [] as any,
125124
isRole: false,
126125
},
126+
{
127+
label: t('views.tool.title'),
128+
value: AuthorizationEnum.TOOL,
129+
data: [] as any,
130+
isRole: false,
131+
},
132+
{
133+
label: t('views.model.title'),
134+
value: AuthorizationEnum.MODEL,
135+
data: [] as any,
136+
isRole: false,
137+
},
127138
])
128139
129140
watch(filterText, (val: any) => {

0 commit comments

Comments
 (0)