mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-31 10:12:51 +00:00
feat: rename tool_type to scope and update related query parameters for tool filtering
This commit is contained in:
parent
1817537269
commit
a4b6570110
|
|
@ -202,10 +202,10 @@ class ToolPageAPI(ToolReadAPI):
|
|||
required=False,
|
||||
),
|
||||
OpenApiParameter(
|
||||
name="tool_type",
|
||||
name="scope",
|
||||
description="工具类型",
|
||||
type=OpenApiTypes.STR,
|
||||
enum=["CUSTOM", "INTERNAL"],
|
||||
enum=["SHARED", "WORKSPACE"],
|
||||
location='query',
|
||||
required=True,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class ToolModelSerializer(serializers.ModelSerializer):
|
|||
class Meta:
|
||||
model = Tool
|
||||
fields = ['id', 'name', 'icon', 'desc', 'code', 'input_field_list', 'init_field_list', 'init_params',
|
||||
'scope', 'is_active', 'user_id', 'template_id', 'workspace_id', 'folder_id', 'tool_type',
|
||||
'scope', 'is_active', 'user_id', 'template_id', 'workspace_id', 'folder_id',
|
||||
'create_time', 'update_time']
|
||||
|
||||
|
||||
|
|
@ -464,7 +464,7 @@ class ToolTreeSerializer(serializers.Serializer):
|
|||
folder_id = serializers.CharField(required=True, label=_('folder id'))
|
||||
name = serializers.CharField(required=False, allow_null=True, allow_blank=True, label=_('tool name'))
|
||||
user_id = serializers.CharField(required=False, allow_null=True, allow_blank=True, label=_('user id'))
|
||||
tool_type = serializers.CharField(required=True, label=_('tool type'))
|
||||
scope = serializers.CharField(required=True, label=_('scope'))
|
||||
|
||||
def page_tool(self, current_page: int, page_size: int):
|
||||
self.is_valid(raise_exception=True)
|
||||
|
|
@ -477,25 +477,27 @@ class ToolTreeSerializer(serializers.Serializer):
|
|||
all_folders = root.get_descendants(include_self=True)
|
||||
|
||||
if self.data.get('name'):
|
||||
tools = QuerySet(Tool).filter(Q(workspace_id=self.data.get('workspace_id')) &
|
||||
Q(folder_id__in=all_folders) &
|
||||
Q(tool_type=self.data.get('tool_type')) &
|
||||
Q(user_id=self.data.get('user_id')) &
|
||||
Q(name__contains=self.data.get('name')))
|
||||
tools = QuerySet(Tool).filter(
|
||||
Q(workspace_id=self.data.get('workspace_id')) &
|
||||
Q(folder_id__in=all_folders) &
|
||||
Q(user_id=self.data.get('user_id')) &
|
||||
Q(name__contains=self.data.get('name'))
|
||||
)
|
||||
else:
|
||||
tools = QuerySet(Tool).filter(Q(workspace_id=self.data.get('workspace_id')) &
|
||||
Q(folder_id__in=all_folders) &
|
||||
Q(user_id=self.data.get('user_id')) &
|
||||
Q(tool_type=self.data.get('tool_type')))
|
||||
tools = QuerySet(Tool).filter(
|
||||
Q(workspace_id=self.data.get('workspace_id')) &
|
||||
Q(folder_id__in=all_folders) &
|
||||
Q(user_id=self.data.get('user_id'))
|
||||
)
|
||||
return page_search(current_page, page_size, tools, lambda record: ToolModelSerializer(record).data)
|
||||
|
||||
def get_query_set(self):
|
||||
tool_query_set = QuerySet(Tool)
|
||||
tool_type_query_set = QuerySet(Tool)
|
||||
tool_scope_query_set = QuerySet(Tool)
|
||||
folder_query_set = QuerySet(ToolFolder)
|
||||
workspace_id = self.data.get('workspace_id')
|
||||
user_id = self.data.get('user_id')
|
||||
tool_type = self.data.get('tool_type')
|
||||
scope = self.data.get('scope')
|
||||
desc = self.data.get('desc')
|
||||
name = self.data.get('name')
|
||||
folder_id = self.data.get('folder_id')
|
||||
|
|
@ -517,13 +519,13 @@ class ToolTreeSerializer(serializers.Serializer):
|
|||
tool_query_set = tool_query_set.filter(desc__contains=desc)
|
||||
tool_query_set = tool_query_set.order_by("-update_time")
|
||||
|
||||
if tool_type is not None:
|
||||
tool_type_query_set = tool_type_query_set.filter(tool_type=tool_type)
|
||||
if scope is not None:
|
||||
tool_scope_query_set = tool_scope_query_set.filter(scope=scope)
|
||||
|
||||
return {
|
||||
'folder_query_set': folder_query_set,
|
||||
'tool_query_set': tool_query_set,
|
||||
'tool_type_query_set': tool_type_query_set
|
||||
'tool_scope_query_set': tool_scope_query_set
|
||||
}
|
||||
|
||||
def page_tool_with_folders(self, current_page: int, page_size: int):
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from (select "id"::text,
|
|||
"user_id",
|
||||
"create_time",
|
||||
"update_time"
|
||||
from tool ${tool_type_query_set}
|
||||
from tool ${tool_scope_query_set}
|
||||
UNION
|
||||
select "id",
|
||||
"name",
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ class ToolView(APIView):
|
|||
'workspace_id': workspace_id,
|
||||
'folder_id': request.query_params.get('folder_id'),
|
||||
'name': request.query_params.get('name'),
|
||||
'tool_type': request.query_params.get('tool_type'),
|
||||
'scope': request.query_params.get('scope'),
|
||||
}
|
||||
).page_tool_with_folders(current_page, page_size))
|
||||
|
||||
|
|
|
|||
|
|
@ -248,7 +248,7 @@ function openCreateDialog(data?: any) {
|
|||
function getList() {
|
||||
const params = {
|
||||
folder_id: currentFolder.value?.id || 'root',
|
||||
tool_type: 'CUSTOM',
|
||||
scope: 'WORKSPACE',
|
||||
}
|
||||
ToolApi.getToolList('default', paginationConfig, params, loading).then((res) => {
|
||||
paginationConfig.total = res.data?.total
|
||||
|
|
|
|||
Loading…
Reference in New Issue