mirror of https://github.com/langgenius/dify.git
chore: use TenantAccountRole instead of TenantAccountJoinRole (#15514)
Co-authored-by: 刘江波 <jiangbo721@163.com>
This commit is contained in:
parent
545e5cbcd6
commit
0415cc209d
|
@ -5,7 +5,6 @@ from .account import (
|
||||||
InvitationCode,
|
InvitationCode,
|
||||||
Tenant,
|
Tenant,
|
||||||
TenantAccountJoin,
|
TenantAccountJoin,
|
||||||
TenantAccountJoinRole,
|
|
||||||
TenantAccountRole,
|
TenantAccountRole,
|
||||||
TenantStatus,
|
TenantStatus,
|
||||||
)
|
)
|
||||||
|
@ -156,7 +155,6 @@ __all__ = [
|
||||||
"TagBinding",
|
"TagBinding",
|
||||||
"Tenant",
|
"Tenant",
|
||||||
"TenantAccountJoin",
|
"TenantAccountJoin",
|
||||||
"TenantAccountJoinRole",
|
|
||||||
"TenantAccountRole",
|
"TenantAccountRole",
|
||||||
"TenantDefaultModel",
|
"TenantDefaultModel",
|
||||||
"TenantPreferredModelProvider",
|
"TenantPreferredModelProvider",
|
||||||
|
|
|
@ -220,13 +220,6 @@ class Tenant(db.Model): # type: ignore[name-defined]
|
||||||
self.custom_config = json.dumps(value)
|
self.custom_config = json.dumps(value)
|
||||||
|
|
||||||
|
|
||||||
class TenantAccountJoinRole(enum.Enum):
|
|
||||||
OWNER = "owner"
|
|
||||||
ADMIN = "admin"
|
|
||||||
NORMAL = "normal"
|
|
||||||
DATASET_OPERATOR = "dataset_operator"
|
|
||||||
|
|
||||||
|
|
||||||
class TenantAccountJoin(db.Model): # type: ignore[name-defined]
|
class TenantAccountJoin(db.Model): # type: ignore[name-defined]
|
||||||
__tablename__ = "tenant_account_joins"
|
__tablename__ = "tenant_account_joins"
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
@ -28,7 +28,6 @@ from models.account import (
|
||||||
AccountStatus,
|
AccountStatus,
|
||||||
Tenant,
|
Tenant,
|
||||||
TenantAccountJoin,
|
TenantAccountJoin,
|
||||||
TenantAccountJoinRole,
|
|
||||||
TenantAccountRole,
|
TenantAccountRole,
|
||||||
TenantStatus,
|
TenantStatus,
|
||||||
)
|
)
|
||||||
|
@ -625,8 +624,8 @@ class TenantService:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def create_tenant_member(tenant: Tenant, account: Account, role: str = "normal") -> TenantAccountJoin:
|
def create_tenant_member(tenant: Tenant, account: Account, role: str = "normal") -> TenantAccountJoin:
|
||||||
"""Create tenant member"""
|
"""Create tenant member"""
|
||||||
if role == TenantAccountJoinRole.OWNER.value:
|
if role == TenantAccountRole.OWNER.value:
|
||||||
if TenantService.has_roles(tenant, [TenantAccountJoinRole.OWNER]):
|
if TenantService.has_roles(tenant, [TenantAccountRole.OWNER]):
|
||||||
logging.error(f"Tenant {tenant.id} has already an owner.")
|
logging.error(f"Tenant {tenant.id} has already an owner.")
|
||||||
raise Exception("Tenant already has an owner.")
|
raise Exception("Tenant already has an owner.")
|
||||||
|
|
||||||
|
@ -734,10 +733,10 @@ class TenantService:
|
||||||
return updated_accounts
|
return updated_accounts
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def has_roles(tenant: Tenant, roles: list[TenantAccountJoinRole]) -> bool:
|
def has_roles(tenant: Tenant, roles: list[TenantAccountRole]) -> bool:
|
||||||
"""Check if user has any of the given roles for a tenant"""
|
"""Check if user has any of the given roles for a tenant"""
|
||||||
if not all(isinstance(role, TenantAccountJoinRole) for role in roles):
|
if not all(isinstance(role, TenantAccountRole) for role in roles):
|
||||||
raise ValueError("all roles must be TenantAccountJoinRole")
|
raise ValueError("all roles must be TenantAccountRole")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
db.session.query(TenantAccountJoin)
|
db.session.query(TenantAccountJoin)
|
||||||
|
@ -749,7 +748,7 @@ class TenantService:
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_user_role(account: Account, tenant: Tenant) -> Optional[TenantAccountJoinRole]:
|
def get_user_role(account: Account, tenant: Tenant) -> Optional[TenantAccountRole]:
|
||||||
"""Get the role of the current account for a given tenant"""
|
"""Get the role of the current account for a given tenant"""
|
||||||
join = (
|
join = (
|
||||||
db.session.query(TenantAccountJoin)
|
db.session.query(TenantAccountJoin)
|
||||||
|
|
|
@ -2,7 +2,7 @@ from flask_login import current_user # type: ignore
|
||||||
|
|
||||||
from configs import dify_config
|
from configs import dify_config
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
from models.account import Tenant, TenantAccountJoin, TenantAccountJoinRole
|
from models.account import Tenant, TenantAccountJoin, TenantAccountRole
|
||||||
from services.account_service import TenantService
|
from services.account_service import TenantService
|
||||||
from services.feature_service import FeatureService
|
from services.feature_service import FeatureService
|
||||||
|
|
||||||
|
@ -33,9 +33,7 @@ class WorkspaceService:
|
||||||
|
|
||||||
can_replace_logo = FeatureService.get_features(tenant_info["id"]).can_replace_logo
|
can_replace_logo = FeatureService.get_features(tenant_info["id"]).can_replace_logo
|
||||||
|
|
||||||
if can_replace_logo and TenantService.has_roles(
|
if can_replace_logo and TenantService.has_roles(tenant, [TenantAccountRole.OWNER, TenantAccountRole.ADMIN]):
|
||||||
tenant, [TenantAccountJoinRole.OWNER, TenantAccountJoinRole.ADMIN]
|
|
||||||
):
|
|
||||||
base_url = dify_config.FILES_URL
|
base_url = dify_config.FILES_URL
|
||||||
replace_webapp_logo = (
|
replace_webapp_logo = (
|
||||||
f"{base_url}/files/workspaces/{tenant.id}/webapp-logo"
|
f"{base_url}/files/workspaces/{tenant.id}/webapp-logo"
|
||||||
|
|
Loading…
Reference in New Issue