2023-08-15 13:35:47 +08:00
|
|
|
from flask_login import current_user
|
2024-02-06 13:21:13 +08:00
|
|
|
|
2024-07-12 12:25:38 +08:00
|
|
|
from configs import dify_config
|
2024-02-06 13:21:13 +08:00
|
|
|
from extensions.ext_database import db
|
2023-12-18 16:25:37 +08:00
|
|
|
from models.account import Tenant, TenantAccountJoin, TenantAccountJoinRole
|
|
|
|
from services.account_service import TenantService
|
2024-01-12 12:34:01 +08:00
|
|
|
from services.feature_service import FeatureService
|
2023-12-18 16:25:37 +08:00
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
|
|
|
|
class WorkspaceService:
|
|
|
|
@classmethod
|
|
|
|
def get_tenant_info(cls, tenant: Tenant):
|
2023-08-15 13:35:47 +08:00
|
|
|
if not tenant:
|
|
|
|
return None
|
2023-05-15 08:51:32 +08:00
|
|
|
tenant_info = {
|
2024-08-26 13:43:57 +08:00
|
|
|
"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",
|
2023-05-15 08:51:32 +08:00
|
|
|
}
|
|
|
|
|
2023-08-15 13:35:47 +08:00
|
|
|
# Get role of user
|
2024-08-26 13:43:57 +08:00
|
|
|
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]
|
|
|
|
):
|
2024-07-12 12:25:38 +08:00
|
|
|
base_url = dify_config.FILES_URL
|
2024-08-26 13:43:57 +08:00
|
|
|
replace_webapp_logo = (
|
|
|
|
f"{base_url}/files/workspaces/{tenant.id}/webapp-logo"
|
|
|
|
if tenant.custom_config_dict.get("replace_webapp_logo")
|
|
|
|
else None
|
|
|
|
)
|
|
|
|
remove_webapp_brand = tenant.custom_config_dict.get("remove_webapp_brand", False)
|
|
|
|
|
|
|
|
tenant_info["custom_config"] = {
|
|
|
|
"remove_webapp_brand": remove_webapp_brand,
|
|
|
|
"replace_webapp_logo": replace_webapp_logo,
|
2024-02-28 15:17:49 +08:00
|
|
|
}
|
2023-12-18 16:25:37 +08:00
|
|
|
|
2023-05-15 08:51:32 +08:00
|
|
|
return tenant_info
|