Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate user exist on remove organization user method #905

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}'")
Loading