mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-28 14:52:58 +00:00
feat: refactor shared tool API to utilize ToolSerializer for create, update, and import operations
This commit is contained in:
parent
f5bc003aaf
commit
5cb7fc8d9a
|
|
@ -210,7 +210,7 @@ class ToolSerializer(serializers.Serializer):
|
|||
user_id=self.data.get('user_id'),
|
||||
input_field_list=instance.get('input_field_list', []),
|
||||
init_field_list=instance.get('init_field_list', []),
|
||||
scope=ToolScope.WORKSPACE,
|
||||
scope=instance.get('scope', ToolScope.WORKSPACE),
|
||||
folder_id=instance.get('folder_id', 'root'),
|
||||
is_active=False)
|
||||
tool.save()
|
||||
|
|
@ -371,7 +371,7 @@ class ToolSerializer(serializers.Serializer):
|
|||
|
||||
#
|
||||
@transaction.atomic
|
||||
def import_(self):
|
||||
def import_(self, scope=ToolScope.WORKSPACE):
|
||||
self.is_valid()
|
||||
|
||||
user_id = self.data.get('user_id')
|
||||
|
|
@ -389,7 +389,7 @@ class ToolSerializer(serializers.Serializer):
|
|||
user_id=user_id,
|
||||
input_field_list=tool.get('input_field_list'),
|
||||
init_field_list=tool.get('init_field_list', []),
|
||||
scope=ToolScope.WORKSPACE,
|
||||
scope=scope,
|
||||
is_active=False
|
||||
)
|
||||
tool_model.save()
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ from common.constants.permission_constants import PermissionConstants
|
|||
from common.result import result
|
||||
from tools.api.tool import ToolCreateAPI, ToolEditAPI, ToolReadAPI, ToolDeleteAPI, ToolTreeReadAPI, ToolDebugApi, \
|
||||
ToolExportAPI, ToolImportAPI, ToolPageAPI, PylintAPI, EditIconAPI
|
||||
from tools.models import ToolScope
|
||||
from tools.serializers.tool import ToolSerializer, ToolTreeSerializer
|
||||
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ class ToolView(APIView):
|
|||
def post(self, request: Request, workspace_id: str):
|
||||
return result.success(ToolSerializer.Create(
|
||||
data={'user_id': request.user.id, 'workspace_id': workspace_id}
|
||||
).insert(request.data))
|
||||
).insert({**request.data, 'scope': ToolScope.WORKSPACE}))
|
||||
|
||||
@extend_schema(
|
||||
methods=['GET'],
|
||||
|
|
@ -155,7 +156,7 @@ class ToolView(APIView):
|
|||
def post(self, request: Request, workspace_id: str):
|
||||
return result.success(ToolSerializer.Import(
|
||||
data={'workspace_id': workspace_id, 'file': request.FILES.get('file'), 'user_id': request.user.id}
|
||||
).import_())
|
||||
).import_(ToolScope.WORKSPACE))
|
||||
|
||||
class Export(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
|
|
|||
Loading…
Reference in New Issue