mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-20 01:36:00 +02:00
refactoring code to meet ac reqs
This commit is contained in:
parent
cc7f588dad
commit
c043f44ef9
1 changed files with 23 additions and 17 deletions
|
@ -837,6 +837,23 @@ class DomainAddUserView(DomainFormBaseView):
|
|||
)
|
||||
return None
|
||||
|
||||
# Check to see if an invite has already been sent (NOTE: we do not want to create an invite just yet.)
|
||||
try:
|
||||
invite = DomainInvitation.objects.get(email=email, domain=self.object)
|
||||
# that invitation already existed
|
||||
if invite.status == DomainInvitation.DomainInvitationStatus.RETRIEVED:
|
||||
messages.warning(
|
||||
self.request,
|
||||
f"{email} is already a manager for this domain.",
|
||||
)
|
||||
else:
|
||||
messages.warning(
|
||||
self.request,
|
||||
f"{email} has already been invited to this domain"
|
||||
)
|
||||
except DomainInvitation.DoesNotExist:
|
||||
logger.info("Domain Invitation Does Not Exist")
|
||||
|
||||
try:
|
||||
send_templated_email(
|
||||
"emails/domain_invitation.txt",
|
||||
|
@ -862,19 +879,8 @@ class DomainAddUserView(DomainFormBaseView):
|
|||
|
||||
def _make_invitation(self, email_address: str, requestor: User):
|
||||
"""Make a Domain invitation for this email and redirect with a message."""
|
||||
# Check to see if an invite has already been sent (NOTE: we do not want to create an invite just yet.)
|
||||
try:
|
||||
invite = DomainInvitation.objects.get(email=email_address, domain=self.object)
|
||||
# that invitation already existed
|
||||
if invite is not None:
|
||||
messages.warning(
|
||||
self.request,
|
||||
f"{email_address} has already been invited to this domain.",
|
||||
)
|
||||
except DomainInvitation.DoesNotExist:
|
||||
# Try to send the invitation. If it succeeds, add it to the DomainInvitation table.
|
||||
try:
|
||||
self._send_domain_invitation_email(email=email_address, requestor=requestor)
|
||||
self._send_domain_invitation_email(email=email_address, requestor=requestor, add_success=False)
|
||||
except EmailSendingError:
|
||||
messages.warning(self.request, "Could not send email invitation.")
|
||||
else:
|
||||
|
@ -921,7 +927,7 @@ class DomainAddUserView(DomainFormBaseView):
|
|||
except IntegrityError:
|
||||
# User already has the desired role! Do nothing??
|
||||
pass
|
||||
|
||||
else:
|
||||
messages.success(self.request, f"Added user {requested_email}.")
|
||||
|
||||
return redirect(self.get_success_url())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue