feat: block deactivating user who is tenant contact
This commit is contained in:
@@ -23,6 +23,17 @@ class Tenants(Base):
|
||||
# 国际化语言配置字段
|
||||
default_language = Column(String(10), nullable=False, default='zh', server_default='zh', index=True) # 租户默认语言
|
||||
supported_languages = Column(ARRAY(String(10)), nullable=False, default=lambda: ['zh', 'en'], server_default=text("'{zh,en}'")) # 租户支持的语言列表
|
||||
|
||||
# 租户联系信息
|
||||
contact_name = Column(String(100), nullable=True) # 联系人姓名
|
||||
contact_email = Column(String(255), nullable=True) # 联系人邮箱
|
||||
contact_phone = Column(String(50), nullable=True) # 联系人电话
|
||||
|
||||
# 租户套餐信息
|
||||
plan = Column(String(50), nullable=True) # 套餐类型
|
||||
plan_expired_at = Column(DateTime, nullable=True) # 套餐到期时间
|
||||
api_ops_rate_limit = Column(String(100), nullable=True) # API 调用频率限制
|
||||
status = Column(String(50), nullable=True, default='active') # 租户状态
|
||||
|
||||
# Relationship to users - one tenant has many users
|
||||
users = relationship("User", back_populates="tenant")
|
||||
|
||||
@@ -250,6 +250,20 @@ def deactivate_user(db: Session, user_id_to_deactivate: uuid.UUID, current_user:
|
||||
}
|
||||
)
|
||||
|
||||
# 检查是否为租户联系人
|
||||
from app.models.tenant_model import Tenants
|
||||
tenant = db.query(Tenants).filter(Tenants.id == db_user.tenant_id).first()
|
||||
if tenant and tenant.contact_email and tenant.contact_email == db_user.email:
|
||||
business_logger.warning(f"尝试停用租户联系人: {db_user.email}, tenant_id={db_user.tenant_id}")
|
||||
raise BusinessException(
|
||||
"该管理员是租户联系人,请先在租户信息中更换联系邮箱,再禁用此管理员",
|
||||
code=BizCode.FORBIDDEN,
|
||||
context={
|
||||
"user_id": str(user_id_to_deactivate),
|
||||
"tenant_id": str(db_user.tenant_id)
|
||||
}
|
||||
)
|
||||
|
||||
# 停用用户
|
||||
business_logger.debug(f"执行用户停用: {db_user.username} (ID: {user_id_to_deactivate})")
|
||||
db_user.is_active = False
|
||||
|
||||
Reference in New Issue
Block a user