mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-31 06:56:33 +02:00
Merge branch 'main' into bob/2416-portfolio-admin-emails
This commit is contained in:
commit
c1c4ec01f0
27 changed files with 828 additions and 131 deletions
|
@ -212,3 +212,32 @@ def validate_portfolio_invitation(portfolio_invitation):
|
|||
"This user is already assigned to a portfolio invitation. "
|
||||
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios."
|
||||
)
|
||||
|
||||
|
||||
def cleanup_after_portfolio_member_deletion(portfolio, email, user=None):
|
||||
"""
|
||||
Cleans up after removing a portfolio member or a portfolio invitation.
|
||||
|
||||
Args:
|
||||
portfolio: portfolio
|
||||
user: passed when removing a portfolio member.
|
||||
email: passed when removing a portfolio invitation, or passed as user.email
|
||||
when removing a portfolio member.
|
||||
"""
|
||||
|
||||
DomainInvitation = apps.get_model("registrar.DomainInvitation")
|
||||
UserDomainRole = apps.get_model("registrar.UserDomainRole")
|
||||
|
||||
# Fetch domain invitations matching the criteria
|
||||
invitations = DomainInvitation.objects.filter(
|
||||
email=email, domain__domain_info__portfolio=portfolio, status=DomainInvitation.DomainInvitationStatus.INVITED
|
||||
)
|
||||
|
||||
# Call `cancel_invitation` on each invitation
|
||||
for invitation in invitations:
|
||||
invitation.cancel_invitation()
|
||||
invitation.save()
|
||||
|
||||
if user:
|
||||
# Remove user's domain roles for the current portfolio
|
||||
UserDomainRole.objects.filter(user=user, domain__domain_info__portfolio=portfolio).delete()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue