workspace_service.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from extensions.ext_database import db
  2. from flask import current_app
  3. from flask_login import current_user
  4. from models.account import Tenant, TenantAccountJoin, TenantAccountJoinRole
  5. from models.provider import Provider
  6. from services.account_service import TenantService
  7. from services.feature_service import FeatureService
  8. class WorkspaceService:
  9. @classmethod
  10. def get_tenant_info(cls, tenant: Tenant):
  11. if not tenant:
  12. return None
  13. tenant_info = {
  14. 'id': tenant.id,
  15. 'name': tenant.name,
  16. 'plan': tenant.plan,
  17. 'status': tenant.status,
  18. 'created_at': tenant.created_at,
  19. 'in_trail': True,
  20. 'trial_end_reason': None,
  21. 'role': 'normal',
  22. }
  23. # Get role of user
  24. tenant_account_join = db.session.query(TenantAccountJoin).filter(
  25. TenantAccountJoin.tenant_id == tenant.id,
  26. TenantAccountJoin.account_id == current_user.id
  27. ).first()
  28. tenant_info['role'] = tenant_account_join.role
  29. can_replace_logo = FeatureService.get_features(tenant_info['id']).can_replace_logo
  30. if can_replace_logo and TenantService.has_roles(tenant, [TenantAccountJoinRole.OWNER, TenantAccountJoinRole.ADMIN]):
  31. tenant_info['custom_config'] = tenant.custom_config_dict
  32. return tenant_info