From ffdc6f5c606b1b9ba5075b5ea680fb2576d68d7a Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Fri, 25 Oct 2024 13:22:37 +0800 Subject: [PATCH] feat: support remove single item from installation task --- api/controllers/console/workspace/plugin.py | 15 +++++++++++++++ api/core/plugin/manager/plugin.py | 10 ++++++++++ api/services/plugin/plugin_service.py | 5 +++++ 3 files changed, 30 insertions(+) diff --git a/api/controllers/console/workspace/plugin.py b/api/controllers/console/workspace/plugin.py index 16861a021a..0a8695b344 100644 --- a/api/controllers/console/workspace/plugin.py +++ b/api/controllers/console/workspace/plugin.py @@ -266,6 +266,20 @@ class PluginDeleteInstallTaskApi(Resource): return {"success": PluginService.delete_install_task(tenant_id, task_id)} +class PluginDeleteInstallTaskItemApi(Resource): + @setup_required + @login_required + @account_initialization_required + def post(self, task_id: str, identifier: str): + user = current_user + if not user.is_admin_or_owner: + raise Forbidden() + + tenant_id = user.current_tenant_id + + return {"success": PluginService.delete_install_task_item(tenant_id, task_id, identifier)} + + class PluginUninstallApi(Resource): @setup_required @login_required @@ -296,4 +310,5 @@ api.add_resource(PluginFetchManifestApi, "/workspaces/current/plugin/fetch-manif api.add_resource(PluginFetchInstallTasksApi, "/workspaces/current/plugin/tasks") api.add_resource(PluginFetchInstallTaskApi, "/workspaces/current/plugin/tasks/") api.add_resource(PluginDeleteInstallTaskApi, "/workspaces/current/plugin/tasks//delete") +api.add_resource(PluginDeleteInstallTaskItemApi, "/workspaces/current/plugin/tasks//delete/") api.add_resource(PluginUninstallApi, "/workspaces/current/plugin/uninstall") diff --git a/api/core/plugin/manager/plugin.py b/api/core/plugin/manager/plugin.py index 81aa6c1fc1..6200d5380b 100644 --- a/api/core/plugin/manager/plugin.py +++ b/api/core/plugin/manager/plugin.py @@ -103,6 +103,16 @@ class PluginInstallationManager(BasePluginManager): bool, ) + def delete_plugin_installation_task_item(self, tenant_id: str, task_id: str, identifier: str) -> bool: + """ + Delete a plugin installation task item. + """ + return self._request_with_plugin_daemon_response( + "POST", + f"plugin/{tenant_id}/management/install/tasks/{task_id}/delete/{identifier}", + bool, + ) + def fetch_plugin_manifest(self, tenant_id: str, plugin_unique_identifier: str) -> PluginDeclaration: """ Fetch a plugin manifest. diff --git a/api/services/plugin/plugin_service.py b/api/services/plugin/plugin_service.py index 95f26c3f13..16daf3f584 100644 --- a/api/services/plugin/plugin_service.py +++ b/api/services/plugin/plugin_service.py @@ -66,6 +66,11 @@ class PluginService: manager = PluginInstallationManager() return manager.delete_plugin_installation_task(tenant_id, task_id) + @staticmethod + def delete_install_task_item(tenant_id: str, task_id: str, identifier: str) -> bool: + manager = PluginInstallationManager() + return manager.delete_plugin_installation_task_item(tenant_id, task_id, identifier) + @staticmethod def upload_pkg(tenant_id: str, pkg: bytes, verify_signature: bool = False) -> PluginUploadResponse: """