dify/api/services/workspace_service.py
takatost d069c668f8
Model Runtime (#1858)
Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
Co-authored-by: Garfield Dai <dai.hai@foxmail.com>
Co-authored-by: chenhe <guchenhe@gmail.com>
Co-authored-by: jyong <jyong@dify.ai>
Co-authored-by: Joel <iamjoel007@gmail.com>
Co-authored-by: Yeuoly <admin@srmxy.cn>
2024-01-02 23:42:00 +08:00

40 lines
1.3 KiB
Python

from flask import current_app
from flask_login import current_user
from extensions.ext_database import db
from models.account import Tenant, TenantAccountJoin, TenantAccountJoinRole
from models.provider import Provider
from services.feature_service import FeatureService
from services.account_service import TenantService
class WorkspaceService:
@classmethod
def get_tenant_info(cls, tenant: Tenant):
if not tenant:
return None
tenant_info = {
'id': tenant.id,
'name': tenant.name,
'plan': tenant.plan,
'status': tenant.status,
'created_at': tenant.created_at,
'in_trail': True,
'trial_end_reason': None,
'role': 'normal',
}
# Get role of user
tenant_account_join = db.session.query(TenantAccountJoin).filter(
TenantAccountJoin.tenant_id == tenant.id,
TenantAccountJoin.account_id == current_user.id
).first()
tenant_info['role'] = tenant_account_join.role
can_replace_logo = FeatureService.get_features(tenant_info['id']).can_replace_logo
if can_replace_logo and TenantService.has_roles(tenant, [TenantAccountJoinRole.OWNER, TenantAccountJoinRole.ADMIN]):
tenant_info['custom_config'] = tenant.custom_config_dict
return tenant_info