From 2bf7c40c7c8b2e4abfcaa0f86b36e42f337158f8 Mon Sep 17 00:00:00 2001 From: zhangx1n Date: Tue, 20 May 2025 16:26:00 +0800 Subject: [PATCH] Revert "Merge branch 'feat/plugin-install-scope-management' into deploy/dev" This reverts commit 7636bc164d7a749942bfa177f8ba7e23109c294f, reversing changes made to 2251f22f98d5cd4e7cde27d0e107d5752461d1eb. --- api/core/plugin/entities/plugin_daemon.py | 14 ---- api/services/errors/plugin.py | 5 -- api/services/feature_service.py | 30 -------- api/services/plugin/plugin_service.py | 91 ++++------------------- 4 files changed, 13 insertions(+), 127 deletions(-) delete mode 100644 api/services/errors/plugin.py diff --git a/api/core/plugin/entities/plugin_daemon.py b/api/core/plugin/entities/plugin_daemon.py index d1c05dcbe3..90086173fa 100644 --- a/api/core/plugin/entities/plugin_daemon.py +++ b/api/core/plugin/entities/plugin_daemon.py @@ -164,23 +164,9 @@ class PluginInstallTaskStartResponse(BaseModel): task_id: str = Field(description="The ID of the install task.") -class PluginVerification(BaseModel): - """ - Verification of the plugin. - """ - - class AuthorizedCategory(StrEnum): - Langgenius = "langgenius" - Partner = "partner" - Community = "community" - - authorized_category: AuthorizedCategory = Field(description="The authorized category of the plugin.") - - class PluginUploadResponse(BaseModel): unique_identifier: str = Field(description="The unique identifier of the plugin.") manifest: PluginDeclaration - verification: Optional[PluginVerification] = Field(default=None, description="Basic verification information") class PluginOAuthAuthorizationUrlResponse(BaseModel): diff --git a/api/services/errors/plugin.py b/api/services/errors/plugin.py deleted file mode 100644 index be5b144b3d..0000000000 --- a/api/services/errors/plugin.py +++ /dev/null @@ -1,5 +0,0 @@ -from services.errors.base import BaseServiceError - - -class PluginInstallationForbiddenError(BaseServiceError): - pass diff --git a/api/services/feature_service.py b/api/services/feature_service.py index 188caf3505..be85a03e80 100644 --- a/api/services/feature_service.py +++ b/api/services/feature_service.py @@ -88,26 +88,6 @@ class WebAppAuthModel(BaseModel): allow_email_password_login: bool = False -class PluginInstallationScope(StrEnum): - NONE = "none" - OFFICIAL_ONLY = "official_only" - OFFICIAL_AND_SPECIFIC_PARTNERS = "official_and_specific_partners" - ALL = "all" - - -class PluginInstallationPermissionModel(BaseModel): - # Plugin installation scope – possible values: - # none: prohibit all plugin installations - # official_only: allow only Dify official plugins - # official_and_specific_partners: allow official and specific partner plugins - # all: allow installation of all plugins - plugin_installation_scope: PluginInstallationScope = PluginInstallationScope.ALL - - # If True, restrict plugin installation to the marketplace only - # Equivalent to ForceEnablePluginVerification - restrict_to_marketplace_only: bool = False - - class FeatureModel(BaseModel): billing: BillingModel = BillingModel() education: EducationModel = EducationModel() @@ -148,7 +128,6 @@ class SystemFeatureModel(BaseModel): license: LicenseModel = LicenseModel() branding: BrandingModel = BrandingModel() webapp_auth: WebAppAuthModel = WebAppAuthModel() - plugin_installation_permission: PluginInstallationPermissionModel = PluginInstallationPermissionModel() class FeatureService: @@ -312,12 +291,3 @@ class FeatureService: features.license.workspaces.enabled = license_info["workspaces"]["enabled"] features.license.workspaces.limit = license_info["workspaces"]["limit"] features.license.workspaces.size = license_info["workspaces"]["used"] - - if "PluginInstallationPermission" in enterprise_info: - plugin_installation_info = enterprise_info["PluginInstallationPermission"] - features.plugin_installation_permission.plugin_installation_scope = plugin_installation_info[ - "pluginInstallationScope" - ] - features.plugin_installation_permission.restrict_to_marketplace_only = plugin_installation_info[ - "restrictToMarketplaceOnly" - ] diff --git a/api/services/plugin/plugin_service.py b/api/services/plugin/plugin_service.py index 124154da59..be722a59ad 100644 --- a/api/services/plugin/plugin_service.py +++ b/api/services/plugin/plugin_service.py @@ -17,13 +17,11 @@ from core.plugin.entities.plugin import ( PluginInstallation, PluginInstallationSource, ) -from core.plugin.entities.plugin_daemon import PluginInstallTask, PluginUploadResponse, PluginVerification +from core.plugin.entities.plugin_daemon import PluginInstallTask, PluginUploadResponse from core.plugin.impl.asset import PluginAssetManager from core.plugin.impl.debugging import PluginDebuggingClient from core.plugin.impl.plugin import PluginInstaller from extensions.ext_redis import redis_client -from services.errors.plugin import PluginInstallationForbiddenError -from services.feature_service import FeatureService, PluginInstallationScope logger = logging.getLogger(__name__) @@ -88,35 +86,6 @@ class PluginService: logger.exception("failed to fetch latest plugin version") return result - @staticmethod - def _check_plugin_installation_availability(plugin_verification: Optional[PluginVerification]): - """ - Check the verification of the plugin - """ - features = FeatureService.get_system_features() - - if not plugin_verification: - if features.plugin_installation_permission.restrict_to_marketplace_only: - raise PluginInstallationForbiddenError("Plugin installation is restricted to marketplace only") - return - - match features.plugin_installation_permission.plugin_installation_scope: - case PluginInstallationScope.OFFICIAL_ONLY: - if plugin_verification.authorized_category != PluginVerification.AuthorizedCategory.Langgenius: - raise PluginInstallationForbiddenError("Plugin installation is restricted to official only") - case PluginInstallationScope.OFFICIAL_AND_SPECIFIC_PARTNERS: - if plugin_verification.authorized_category not in [ - PluginVerification.AuthorizedCategory.Langgenius, - PluginVerification.AuthorizedCategory.Partner, - ]: - raise PluginInstallationForbiddenError( - "Plugin installation is restricted to official and specific partners" - ) - case PluginInstallationScope.NONE: - raise PluginInstallationForbiddenError("Installing plugins is not allowed") - case PluginInstallationScope.ALL: - pass - @staticmethod def get_debugging_key(tenant_id: str) -> str: """ @@ -230,8 +199,6 @@ class PluginService: # check if plugin pkg is already downloaded manager = PluginInstaller() - features = FeatureService.get_system_features() - try: manager.fetch_plugin_manifest(tenant_id, new_plugin_unique_identifier) # already downloaded, skip, and record install event @@ -239,14 +206,7 @@ class PluginService: except Exception: # plugin not installed, download and upload pkg pkg = download_plugin_pkg(new_plugin_unique_identifier) - response = manager.upload_pkg( - tenant_id, - pkg, - verify_signature=features.plugin_installation_permission.restrict_to_marketplace_only, - ) - - # check if the plugin is available to install - PluginService._check_plugin_installation_availability(response.verification) + manager.upload_pkg(tenant_id, pkg, verify_signature=False) return manager.upgrade_plugin( tenant_id, @@ -291,15 +251,7 @@ class PluginService: returns: plugin_unique_identifier """ manager = PluginInstaller() - features = FeatureService.get_system_features() - response = manager.upload_pkg( - tenant_id, - pkg, - verify_signature=features.plugin_installation_permission.restrict_to_marketplace_only, - ) - # check if the plugin is available to install - PluginService._check_plugin_installation_availability(response.verification) - return response + return manager.upload_pkg(tenant_id, pkg, verify_signature) @staticmethod def upload_pkg_from_github( @@ -312,17 +264,13 @@ class PluginService: pkg = download_with_size_limit( f"https://github.com/{repo}/releases/download/{version}/{package}", dify_config.PLUGIN_MAX_PACKAGE_SIZE ) - features = FeatureService.get_system_features() manager = PluginInstaller() - response = manager.upload_pkg( + return manager.upload_pkg( tenant_id, pkg, - verify_signature=features.plugin_installation_permission.restrict_to_marketplace_only, + verify_signature, ) - # check if the plugin is available to install - PluginService._check_plugin_installation_availability(response.verification) - return response @staticmethod def upload_bundle( @@ -365,33 +313,28 @@ class PluginService: ) @staticmethod - def fetch_marketplace_pkg(tenant_id: str, plugin_unique_identifier: str) -> PluginDeclaration: + def fetch_marketplace_pkg( + tenant_id: str, plugin_unique_identifier: str, verify_signature: bool = False + ) -> PluginDeclaration: """ Fetch marketplace package """ if not dify_config.MARKETPLACE_ENABLED: raise ValueError("marketplace is not enabled") - features = FeatureService.get_system_features() - manager = PluginInstaller() try: declaration = manager.fetch_plugin_manifest(tenant_id, plugin_unique_identifier) except Exception: pkg = download_plugin_pkg(plugin_unique_identifier) - response = manager.upload_pkg( - tenant_id, - pkg, - verify_signature=features.plugin_installation_permission.restrict_to_marketplace_only, - ) - # check if the plugin is available to install - PluginService._check_plugin_installation_availability(response.verification) - declaration = response.manifest + declaration = manager.upload_pkg(tenant_id, pkg, verify_signature).manifest return declaration @staticmethod - def install_from_marketplace_pkg(tenant_id: str, plugin_unique_identifiers: Sequence[str]): + def install_from_marketplace_pkg( + tenant_id: str, plugin_unique_identifiers: Sequence[str], verify_signature: bool = False + ): """ Install plugin from marketplace package files, returns installation task id @@ -401,8 +344,6 @@ class PluginService: manager = PluginInstaller() - features = FeatureService.get_system_features() - # check if already downloaded for plugin_unique_identifier in plugin_unique_identifiers: try: @@ -411,13 +352,7 @@ class PluginService: except Exception: # plugin not installed, download and upload pkg pkg = download_plugin_pkg(plugin_unique_identifier) - response = manager.upload_pkg( - tenant_id, - pkg, - verify_signature=features.plugin_installation_permission.restrict_to_marketplace_only, - ) - # check if the plugin is available to install - PluginService._check_plugin_installation_availability(response.verification) + manager.upload_pkg(tenant_id, pkg, verify_signature) return manager.install_from_identifiers( tenant_id,