浏览代码

fix: add marketplace switch

Yeuoly 7 月之前
父节点
当前提交
31cca4a849

+ 1 - 0
api/.env.example

@@ -335,4 +335,5 @@ PLUGIN_REMOTE_INSTALL_HOST=localhost
 INNER_API_KEY=QaHbTe77CtuXmsfyhR7+vRjI/+XbV1AaFy691iy+kGDv2Jvy0/eAh8Y1
 INNER_API_KEY=QaHbTe77CtuXmsfyhR7+vRjI/+XbV1AaFy691iy+kGDv2Jvy0/eAh8Y1
 
 
 # Marketplace configuration
 # Marketplace configuration
+MARKETPLACE_ENABLED=true
 MARKETPLACE_API_URL=https://marketplace.dify.ai
 MARKETPLACE_API_URL=https://marketplace.dify.ai

+ 5 - 0
api/configs/feature/__init__.py

@@ -143,6 +143,11 @@ class MarketplaceConfig(BaseSettings):
     Configuration for marketplace
     Configuration for marketplace
     """
     """
 
 
+    MARKETPLACE_ENABLED: bool = Field(
+        description="Enable or disable marketplace",
+        default=True,
+    )
+
     MARKETPLACE_API_URL: HttpUrl = Field(
     MARKETPLACE_API_URL: HttpUrl = Field(
         description="Marketplace API URL",
         description="Marketplace API URL",
         default="https://marketplace.dify.ai",
         default="https://marketplace.dify.ai",

+ 15 - 0
api/controllers/console/workspace/plugin.py

@@ -248,6 +248,20 @@ class PluginFetchInstallTaskApi(Resource):
         return jsonable_encoder({"task": PluginService.fetch_install_task(tenant_id, task_id)})
         return jsonable_encoder({"task": PluginService.fetch_install_task(tenant_id, task_id)})
 
 
 
 
+class PluginDeleteInstallTaskApi(Resource):
+    @setup_required
+    @login_required
+    @account_initialization_required
+    def post(self, task_id: 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(tenant_id, task_id)}
+
+
 class PluginUninstallApi(Resource):
 class PluginUninstallApi(Resource):
     @setup_required
     @setup_required
     @login_required
     @login_required
@@ -277,4 +291,5 @@ api.add_resource(PluginInstallFromMarketplaceApi, "/workspaces/current/plugin/in
 api.add_resource(PluginFetchManifestApi, "/workspaces/current/plugin/fetch-manifest")
 api.add_resource(PluginFetchManifestApi, "/workspaces/current/plugin/fetch-manifest")
 api.add_resource(PluginFetchInstallTasksApi, "/workspaces/current/plugin/tasks")
 api.add_resource(PluginFetchInstallTasksApi, "/workspaces/current/plugin/tasks")
 api.add_resource(PluginFetchInstallTaskApi, "/workspaces/current/plugin/tasks/<task_id>")
 api.add_resource(PluginFetchInstallTaskApi, "/workspaces/current/plugin/tasks/<task_id>")
+api.add_resource(PluginDeleteInstallTaskApi, "/workspaces/current/plugin/tasks/<task_id>/delete")
 api.add_resource(PluginUninstallApi, "/workspaces/current/plugin/uninstall")
 api.add_resource(PluginUninstallApi, "/workspaces/current/plugin/uninstall")

+ 10 - 0
api/core/plugin/manager/plugin.py

@@ -93,6 +93,16 @@ class PluginInstallationManager(BasePluginManager):
             PluginInstallTask,
             PluginInstallTask,
         )
         )
 
 
+    def delete_plugin_installation_task(self, tenant_id: str, task_id: str) -> bool:
+        """
+        Delete a plugin installation task.
+        """
+        return self._request_with_plugin_daemon_response(
+            "POST",
+            f"plugin/{tenant_id}/management/install/tasks/{task_id}/delete",
+            bool,
+        )
+
     def fetch_plugin_manifest(self, tenant_id: str, plugin_unique_identifier: str) -> PluginDeclaration:
     def fetch_plugin_manifest(self, tenant_id: str, plugin_unique_identifier: str) -> PluginDeclaration:
         """
         """
         Fetch a plugin manifest.
         Fetch a plugin manifest.

+ 4 - 0
api/services/feature_service.py

@@ -42,6 +42,7 @@ class SystemFeatureModel(BaseModel):
     sso_enforced_for_web: bool = False
     sso_enforced_for_web: bool = False
     sso_enforced_for_web_protocol: str = ""
     sso_enforced_for_web_protocol: str = ""
     enable_web_sso_switch_component: bool = False
     enable_web_sso_switch_component: bool = False
+    enable_marketplace: bool = True
 
 
 
 
 class FeatureService:
 class FeatureService:
@@ -64,6 +65,9 @@ class FeatureService:
             system_features.enable_web_sso_switch_component = True
             system_features.enable_web_sso_switch_component = True
             cls._fulfill_params_from_enterprise(system_features)
             cls._fulfill_params_from_enterprise(system_features)
 
 
+        if dify_config.MARKETPLACE_ENABLED:
+            system_features.enable_marketplace = True
+
         return system_features
         return system_features
 
 
     @classmethod
     @classmethod

+ 5 - 0
api/services/plugin/plugin_service.py

@@ -61,6 +61,11 @@ class PluginService:
         return manager.fetch_plugin_installation_task(tenant_id, task_id)
         return manager.fetch_plugin_installation_task(tenant_id, task_id)
 
 
     @staticmethod
     @staticmethod
+    def delete_install_task(tenant_id: str, task_id: str) -> bool:
+        manager = PluginInstallationManager()
+        return manager.delete_plugin_installation_task(tenant_id, task_id)
+
+    @staticmethod
     def upload_pkg(tenant_id: str, pkg: bytes, verify_signature: bool = False) -> str:
     def upload_pkg(tenant_id: str, pkg: bytes, verify_signature: bool = False) -> str:
         """
         """
         Upload plugin package files
         Upload plugin package files