Clean up guest invitations selectively after accepting (#4778)

This commit is contained in:
Adrian Gruntkowski 2024-11-06 09:56:48 +01:00 committed by GitHub
parent 1e1a4ab35b
commit c0a8aa025c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -271,7 +271,10 @@ defmodule Plausible.Teams.Invitations do
create_team_membership(team_invitation.team, team_invitation.role, user, now),
{:ok, _guest_memberships} <-
create_guest_memberships(team_membership, guest_invitations, now) do
Repo.delete!(team_invitation)
# Clean up guest invitations after accepting
guest_invitation_ids = Enum.map(guest_invitations, & &1.id)
Repo.delete_all(from gi in Teams.GuestInvitation, where: gi.id in ^guest_invitation_ids)
prune_guest_invitations(team_invitation.team)
if send_email? do
send_invitation_accepted_email(team_invitation, guest_invitations)