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
|
@ -836,6 +836,23 @@ class DomainAddUserView(DomainFormBaseView):
|
||||||
exc_info=True,
|
exc_info=True,
|
||||||
)
|
)
|
||||||
return None
|
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:
|
try:
|
||||||
send_templated_email(
|
send_templated_email(
|
||||||
|
@ -859,25 +876,14 @@ class DomainAddUserView(DomainFormBaseView):
|
||||||
else:
|
else:
|
||||||
if add_success:
|
if add_success:
|
||||||
messages.success(self.request, f"{email} has been invited to this domain.")
|
messages.success(self.request, f"{email} has been invited to this domain.")
|
||||||
|
|
||||||
def _make_invitation(self, email_address: str, requestor: User):
|
def _make_invitation(self, email_address: str, requestor: User):
|
||||||
"""Make a Domain invitation for this email and redirect with a message."""
|
"""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:
|
try:
|
||||||
invite = DomainInvitation.objects.get(email=email_address, domain=self.object)
|
self._send_domain_invitation_email(email=email_address, requestor=requestor, add_success=False)
|
||||||
# that invitation already existed
|
except EmailSendingError:
|
||||||
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)
|
|
||||||
except EmailSendingError:
|
|
||||||
messages.warning(self.request, "Could not send email invitation.")
|
messages.warning(self.request, "Could not send email invitation.")
|
||||||
else:
|
else:
|
||||||
# (NOTE: only create a domainInvitation if the e-mail sends correctly)
|
# (NOTE: only create a domainInvitation if the e-mail sends correctly)
|
||||||
DomainInvitation.objects.get_or_create(email=email_address, domain=self.object)
|
DomainInvitation.objects.get_or_create(email=email_address, domain=self.object)
|
||||||
return redirect(self.get_success_url())
|
return redirect(self.get_success_url())
|
||||||
|
@ -921,8 +927,8 @@ class DomainAddUserView(DomainFormBaseView):
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
# User already has the desired role! Do nothing??
|
# User already has the desired role! Do nothing??
|
||||||
pass
|
pass
|
||||||
|
else:
|
||||||
messages.success(self.request, f"Added user {requested_email}.")
|
messages.success(self.request, f"Added user {requested_email}.")
|
||||||
|
|
||||||
return redirect(self.get_success_url())
|
return redirect(self.get_success_url())
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue