mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 01:09:05 +08:00
fix: db.session.query(TenantAccountJoin) (#19482)
This commit is contained in:
parent
af12cf1bf6
commit
b29087b680
@ -52,7 +52,7 @@ class Account(UserMixin, Base):
|
|||||||
@current_tenant.setter
|
@current_tenant.setter
|
||||||
def current_tenant(self, value: "Tenant"):
|
def current_tenant(self, value: "Tenant"):
|
||||||
tenant = value
|
tenant = value
|
||||||
ta = TenantAccountJoin.query.filter_by(tenant_id=tenant.id, account_id=self.id).first()
|
ta = db.session.query(TenantAccountJoin).filter_by(tenant_id=tenant.id, account_id=self.id).first()
|
||||||
if ta:
|
if ta:
|
||||||
tenant.current_role = ta.role
|
tenant.current_role = ta.role
|
||||||
else:
|
else:
|
||||||
|
@ -47,7 +47,9 @@ def mail_clean_document_notify_task():
|
|||||||
if not tenant:
|
if not tenant:
|
||||||
continue
|
continue
|
||||||
# check current owner
|
# check current owner
|
||||||
current_owner_join = TenantAccountJoin.query.filter_by(tenant_id=tenant.id, role="owner").first()
|
current_owner_join = (
|
||||||
|
db.session.query(TenantAccountJoin).filter_by(tenant_id=tenant.id, role="owner").first()
|
||||||
|
)
|
||||||
if not current_owner_join:
|
if not current_owner_join:
|
||||||
continue
|
continue
|
||||||
account = Account.query.filter(Account.id == current_owner_join.account_id).first()
|
account = Account.query.filter(Account.id == current_owner_join.account_id).first()
|
||||||
|
@ -615,7 +615,10 @@ class TenantService:
|
|||||||
):
|
):
|
||||||
"""Check if user have a workspace or not"""
|
"""Check if user have a workspace or not"""
|
||||||
available_ta = (
|
available_ta = (
|
||||||
TenantAccountJoin.query.filter_by(account_id=account.id).order_by(TenantAccountJoin.id.asc()).first()
|
db.session.query(TenantAccountJoin)
|
||||||
|
.filter_by(account_id=account.id)
|
||||||
|
.order_by(TenantAccountJoin.id.asc())
|
||||||
|
.first()
|
||||||
)
|
)
|
||||||
|
|
||||||
if available_ta:
|
if available_ta:
|
||||||
@ -669,7 +672,7 @@ class TenantService:
|
|||||||
if not tenant:
|
if not tenant:
|
||||||
raise TenantNotFoundError("Tenant not found.")
|
raise TenantNotFoundError("Tenant not found.")
|
||||||
|
|
||||||
ta = TenantAccountJoin.query.filter_by(tenant_id=tenant.id, account_id=account.id).first()
|
ta = db.session.query(TenantAccountJoin).filter_by(tenant_id=tenant.id, account_id=account.id).first()
|
||||||
if ta:
|
if ta:
|
||||||
tenant.role = ta.role
|
tenant.role = ta.role
|
||||||
else:
|
else:
|
||||||
@ -698,7 +701,7 @@ class TenantService:
|
|||||||
if not tenant_account_join:
|
if not tenant_account_join:
|
||||||
raise AccountNotLinkTenantError("Tenant not found or account is not a member of the tenant.")
|
raise AccountNotLinkTenantError("Tenant not found or account is not a member of the tenant.")
|
||||||
else:
|
else:
|
||||||
TenantAccountJoin.query.filter(
|
db.session.query(TenantAccountJoin).filter(
|
||||||
TenantAccountJoin.account_id == account.id, TenantAccountJoin.tenant_id != tenant_id
|
TenantAccountJoin.account_id == account.id, TenantAccountJoin.tenant_id != tenant_id
|
||||||
).update({"current": False})
|
).update({"current": False})
|
||||||
tenant_account_join.current = True
|
tenant_account_join.current = True
|
||||||
@ -790,7 +793,7 @@ class TenantService:
|
|||||||
if operator.id == member.id:
|
if operator.id == member.id:
|
||||||
raise CannotOperateSelfError("Cannot operate self.")
|
raise CannotOperateSelfError("Cannot operate self.")
|
||||||
|
|
||||||
ta_operator = TenantAccountJoin.query.filter_by(tenant_id=tenant.id, account_id=operator.id).first()
|
ta_operator = db.session.query(TenantAccountJoin).filter_by(tenant_id=tenant.id, account_id=operator.id).first()
|
||||||
|
|
||||||
if not ta_operator or ta_operator.role not in perms[action]:
|
if not ta_operator or ta_operator.role not in perms[action]:
|
||||||
raise NoPermissionError(f"No permission to {action} member.")
|
raise NoPermissionError(f"No permission to {action} member.")
|
||||||
@ -803,7 +806,7 @@ class TenantService:
|
|||||||
|
|
||||||
TenantService.check_member_permission(tenant, operator, account, "remove")
|
TenantService.check_member_permission(tenant, operator, account, "remove")
|
||||||
|
|
||||||
ta = TenantAccountJoin.query.filter_by(tenant_id=tenant.id, account_id=account.id).first()
|
ta = db.session.query(TenantAccountJoin).filter_by(tenant_id=tenant.id, account_id=account.id).first()
|
||||||
if not ta:
|
if not ta:
|
||||||
raise MemberNotInTenantError("Member not in tenant.")
|
raise MemberNotInTenantError("Member not in tenant.")
|
||||||
|
|
||||||
@ -815,14 +818,22 @@ class TenantService:
|
|||||||
"""Update member role"""
|
"""Update member role"""
|
||||||
TenantService.check_member_permission(tenant, operator, member, "update")
|
TenantService.check_member_permission(tenant, operator, member, "update")
|
||||||
|
|
||||||
target_member_join = TenantAccountJoin.query.filter_by(tenant_id=tenant.id, account_id=member.id).first()
|
target_member_join = (
|
||||||
|
db.session.query(TenantAccountJoin).filter_by(tenant_id=tenant.id, account_id=member.id).first()
|
||||||
|
)
|
||||||
|
|
||||||
|
if not target_member_join:
|
||||||
|
raise MemberNotInTenantError("Member not in tenant.")
|
||||||
|
|
||||||
if target_member_join.role == new_role:
|
if target_member_join.role == new_role:
|
||||||
raise RoleAlreadyAssignedError("The provided role is already assigned to the member.")
|
raise RoleAlreadyAssignedError("The provided role is already assigned to the member.")
|
||||||
|
|
||||||
if new_role == "owner":
|
if new_role == "owner":
|
||||||
# Find the current owner and change their role to 'admin'
|
# Find the current owner and change their role to 'admin'
|
||||||
current_owner_join = TenantAccountJoin.query.filter_by(tenant_id=tenant.id, role="owner").first()
|
current_owner_join = (
|
||||||
|
db.session.query(TenantAccountJoin).filter_by(tenant_id=tenant.id, role="owner").first()
|
||||||
|
)
|
||||||
|
if current_owner_join:
|
||||||
current_owner_join.role = "admin"
|
current_owner_join.role = "admin"
|
||||||
|
|
||||||
# Update the role of the target member
|
# Update the role of the target member
|
||||||
@ -962,7 +973,7 @@ class RegisterService:
|
|||||||
TenantService.switch_tenant(account, tenant.id)
|
TenantService.switch_tenant(account, tenant.id)
|
||||||
else:
|
else:
|
||||||
TenantService.check_member_permission(tenant, inviter, account, "add")
|
TenantService.check_member_permission(tenant, inviter, account, "add")
|
||||||
ta = TenantAccountJoin.query.filter_by(tenant_id=tenant.id, account_id=account.id).first()
|
ta = db.session.query(TenantAccountJoin).filter_by(tenant_id=tenant.id, account_id=account.id).first()
|
||||||
|
|
||||||
if not ta:
|
if not ta:
|
||||||
TenantService.create_tenant_member(tenant, account, role)
|
TenantService.create_tenant_member(tenant, account, role)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user