fix(user): filter out soft-deleted memberships and organizations

Add get_active_memberships() method to User model that filters out
soft-deleted memberships and memberships of deleted organizations.
Update all usages of organization_memberships to use this method,
ensuring consistent handling of soft-deleted records across the
codebase. Also add deleted_at filters to CA queries in SSH helpers.
This commit is contained in:
2026-04-10 00:39:44 +09:30
parent f16bb88ad2
commit 7480e9d62b
5 changed files with 30 additions and 11 deletions
+1 -1
View File
@@ -329,7 +329,7 @@ def admin_hard_delete_user(user_id):
if target.id == caller.id:
return api_response(success=False, message="Cannot delete your own account via this endpoint.", status=400, error_type="BAD_REQUEST")
target_org_ids = {m.organization_id for m in target.organization_memberships}
target_org_ids = {m.organization_id for m in target.get_active_memberships()}
admin_in_shared_org = OrganizationMember.query.filter(
OrganizationMember.user_id == caller.id,
OrganizationMember.organization_id.in_(target_org_ids),