fix: allow admin to update and remove members

pull/19300/head
GareArc 1 year ago
parent 1c2e8e1ce7
commit 85b4386a02
No known key found for this signature in database

@ -758,8 +758,8 @@ class TenantService:
"""Check member permission""" """Check member permission"""
perms = { perms = {
"add": [TenantAccountRole.OWNER, TenantAccountRole.ADMIN], "add": [TenantAccountRole.OWNER, TenantAccountRole.ADMIN],
"remove": [TenantAccountRole.OWNER], "remove": [TenantAccountRole.OWNER, TenantAccountRole.ADMIN],
"update": [TenantAccountRole.OWNER], "update": [TenantAccountRole.OWNER, TenantAccountRole.ADMIN],
} }
if action not in {"add", "remove", "update"}: if action not in {"add", "remove", "update"}:
raise InvalidActionError("Invalid action.") raise InvalidActionError("Invalid action.")
@ -773,6 +773,15 @@ class TenantService:
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.")
# Admin cannot remove or update other admin and the owner
if action in {"remove", "update"}:
if ta_operator.role == TenantAccountRole.ADMIN:
if member:
ta_member = TenantAccountJoin.query.filter_by(tenant_id=tenant.id, account_id=member.id).first()
if not ta_member or ta_member.role in {TenantAccountRole.OWNER, TenantAccountRole.ADMIN}:
raise NoPermissionError(f"No permission to {action} member.")
@staticmethod @staticmethod
def remove_member_from_tenant(tenant: Tenant, account: Account, operator: Account) -> None: def remove_member_from_tenant(tenant: Tenant, account: Account, operator: Account) -> None:
"""Remove member from tenant""" """Remove member from tenant"""

Loading…
Cancel
Save