mirror of
https://github.com/langgenius/dify.git
synced 2026-08-30 17:11:50 +08:00
896e5e20c0
Co-authored-by: WH-2099 <wh2099@pm.me>
46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
"""Compatibility adapters for the workspace-list application service."""
|
|
|
|
import logging
|
|
from collections.abc import Mapping, Sequence
|
|
from typing import override
|
|
|
|
from configs import dify_config
|
|
from enums.cloud_plan import CloudPlan
|
|
from enums.deployment_edition import DeploymentEdition
|
|
from services.billing_service import BillingService
|
|
from services.feature_service import FeatureService
|
|
from services.workspace_query_service import WorkspacePlanGateway
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class LegacyWorkspacePlanGateway(WorkspacePlanGateway):
|
|
"""Preserve the current deployment-specific Billing/Feature behavior."""
|
|
|
|
@override
|
|
def resolve_many(self, workspace_ids: Sequence[str]) -> Mapping[str, str]:
|
|
ids = tuple(workspace_ids)
|
|
if not ids:
|
|
return {}
|
|
|
|
is_enterprise_only = dify_config.ENTERPRISE_ENABLED and not dify_config.BILLING_ENABLED
|
|
if is_enterprise_only:
|
|
return dict.fromkeys(ids, str(CloudPlan.SANDBOX))
|
|
|
|
is_saas = dify_config.DEPLOYMENT_EDITION == DeploymentEdition.CLOUD and dify_config.BILLING_ENABLED
|
|
bulk_plans = BillingService.get_plan_bulk(ids) if is_saas else {}
|
|
if is_saas and not bulk_plans:
|
|
logger.warning("get_plan_bulk returned empty result, falling back to legacy feature path")
|
|
|
|
resolved: dict[str, str] = {}
|
|
for workspace_id in ids:
|
|
tenant_plan = bulk_plans.get(workspace_id)
|
|
if tenant_plan:
|
|
resolved[workspace_id] = tenant_plan["plan"] or CloudPlan.SANDBOX
|
|
continue
|
|
|
|
features = FeatureService.get_features(workspace_id, exclude_vector_space=True)
|
|
resolved[workspace_id] = features.billing.subscription.plan or CloudPlan.SANDBOX
|
|
|
|
return resolved
|