feat(api): return 403 when attempting to remove last owner
Handle edge case where removing a member would leave an organization without any owners. Service layer raises ValueError for this scenario, which the API endpoint catches and converts to a forbidden response with actionable error message about transferring ownership.
This commit is contained in:
@@ -56,7 +56,10 @@ def add_organization_member(org_id):
|
||||
@full_access_required
|
||||
def remove_organization_member(org_id, user_id):
|
||||
org = OrganizationService.get_organization_by_id(org_id)
|
||||
OrganizationService.remove_member(org=org, user_id=user_id, remover_id=g.current_user.id)
|
||||
try:
|
||||
OrganizationService.remove_member(org=org, user_id=user_id, remover_id=g.current_user.id)
|
||||
except ValueError as e:
|
||||
return api_response(success=False, message=str(e), status=403, error_type="OWNER_PROTECTION")
|
||||
return api_response(message="Member removed successfully")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user