Skip to content

Commit

Permalink
validate user exist on remove organization user method
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammad-ali-e committed Dec 18, 2024
1 parent 7fea3e1 commit 695f19b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/account_v2/authentication_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,25 @@ def remove_user_from_organization_by_user_id(
Parameters:
user_id (str): The user_id of the users to remove.
"""

organization_user = OrganizationMemberService.get_user_by_user_id(user_id)
if not organization_user:
logger.warning(
f"User removal skipped: User '{user_id}' not found in "
f"organization '{organization_id}'."
)
return

# removing user from organization
OrganizationMemberService.remove_user_by_user_id(user_id)

# removing user m2m relations , while removing user
User.objects.get(user_id=user_id).prompt_registries.clear()
User.objects.get(user_id=user_id).shared_custom_tools.clear()
User.objects.get(user_id=user_id).shared_adapters_instance.clear()

# removing user from organization cache
OrganizationMemberService.remove_user_membership_in_organization_cache(
user_id=user_id, organization_id=organization_id
)
logger.info(f"User '{user_id}' removed from organization '{organization_id}'")

0 comments on commit 695f19b

Please sign in to comment.