mirror of
https://github.com/YFGaia/dify-plus.git
synced 2026-06-14 20:41:21 +08:00
81dbfd6748
# Conflicts: # README.md # api/.env.example # api/controllers/console/__init__.py # api/controllers/console/apikey.py # api/controllers/console/explore/completion.py # api/controllers/console/explore/workflow.py # api/controllers/service_api/app/workflow.py # api/controllers/service_api/wraps.py # api/controllers/web/workflow.py # api/core/model_runtime/model_providers/bedrock/get_bedrock_client.py # api/core/model_runtime/model_providers/bedrock/llm/llm.py # api/core/model_runtime/model_providers/openai_api_compatible/openai_api_compatible.yaml # api/core/model_runtime/model_providers/openai_api_compatible/text_embedding/text_embedding.py # api/models/model.py # api/poetry.lock # api/pyproject.toml # web/.env.example # web/Dockerfile # web/app/(commonLayout)/app/(appDetailLayout)/[appId]/layout.tsx # web/app/components/app/overview/appCard.tsx # web/app/components/base/chat/chat-with-history/chat-wrapper.tsx # web/app/components/base/chat/embedded-chatbot/index.tsx # web/app/components/base/mermaid/index.tsx # web/app/components/develop/index.tsx # web/app/components/develop/secret-key/secret-key-modal.tsx # web/app/components/explore/app-list/index.tsx # web/app/components/explore/item-operation/index.tsx # web/app/components/explore/sidebar/app-nav-item/index.tsx # web/app/components/explore/sidebar/index.tsx # web/app/components/header/account-setting/index.tsx # web/app/components/header/index.tsx # web/app/components/share/text-generation/index.tsx # web/app/components/tools/provider/detail.tsx # web/app/layout.tsx # web/package.json # web/service/base.ts # web/yarn.lock
62 lines
2.4 KiB
Python
62 lines
2.4 KiB
Python
import logging
|
|
|
|
from flask_login import current_user # type: ignore
|
|
|
|
from configs import dify_config
|
|
from extensions.ext_database import db
|
|
from models.account import Tenant, TenantAccountJoin, TenantAccountRole
|
|
from services.account_service import TenantService
|
|
from services.account_service_extend import TenantExtendService
|
|
from services.feature_service import FeatureService
|
|
|
|
|
|
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,
|
|
"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()
|
|
)
|
|
assert tenant_account_join is not None, "TenantAccountJoin not found"
|
|
tenant_info["role"] = tenant_account_join.role
|
|
|
|
# ----------------------- 二开部分Start 添加用户权限 - ----------------------
|
|
tenant_extend_service = TenantExtendService
|
|
super_admin_id = tenant_extend_service.get_super_admin_id().id
|
|
super_admin_tenant_id = tenant_extend_service.get_super_admin_tenant_id().id
|
|
tenant_info["admin_extend"] = (super_admin_id == current_user.id)
|
|
tenant_info["tenant_extend"] = (super_admin_tenant_id == tenant.id)
|
|
# ----------------------- 二开部分Stop 添加用户权限 - ----------------------
|
|
|
|
can_replace_logo = FeatureService.get_features(tenant_info["id"]).can_replace_logo
|
|
|
|
if can_replace_logo and TenantService.has_roles(tenant, [TenantAccountRole.OWNER, TenantAccountRole.ADMIN]):
|
|
base_url = dify_config.FILES_URL
|
|
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,
|
|
}
|
|
|
|
return tenant_info
|