mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-24 03:30:50 +02:00
final ish updates
This commit is contained in:
parent
eaf9e24517
commit
ddb56913aa
4 changed files with 24 additions and 42 deletions
|
@ -77,10 +77,8 @@ class DomainInvitation(TimeStampedModel):
|
|||
|
||||
@transition(field="status", source=DomainInvitationStatus.INVITED, target=DomainInvitationStatus.CANCELED)
|
||||
def cancel_invitation(self):
|
||||
logger.info(f"Invitation for {self.domain} has been cancelled.")
|
||||
|
||||
pass
|
||||
|
||||
@transition(field="status", source=DomainInvitationStatus.CANCELED, target=DomainInvitationStatus.INVITED)
|
||||
def update_cancellation_status(self):
|
||||
pass
|
||||
|
||||
|
|
|
@ -706,32 +706,13 @@ class TestDomainManagers(TestDomainOverview):
|
|||
"""Posting to the delete view deletes an invitation."""
|
||||
email_address = "mayor@igorville.gov"
|
||||
invitation, _ = DomainInvitation.objects.get_or_create(domain=self.domain, email=email_address)
|
||||
mock_client = MockSESClient()
|
||||
with boto3_mocking.clients.handler_for("sesv2", mock_client):
|
||||
self.client.post(reverse("invitation-cancel", kwargs={"pk": invitation.id}))
|
||||
mock_client.EMAILS_SENT.clear()
|
||||
with self.assertRaises(DomainInvitation.DoesNotExist):
|
||||
DomainInvitation.objects.get(id=invitation.id)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_domain_invitation_cancel_retrieved_invitation(self):
|
||||
"""Posting to the delete view when invitation retrieved returns an error message"""
|
||||
email_address = "mayor@igorville.gov"
|
||||
invitation, _ = DomainInvitation.objects.get_or_create(
|
||||
domain=self.domain, email=email_address, status=DomainInvitation.DomainInvitationStatus.RETRIEVED
|
||||
)
|
||||
response = self.client.post(reverse("invitation-cancel", kwargs={"pk": invitation.id}), follow=True)
|
||||
# Assert that an error message is displayed to the user
|
||||
self.assertContains(response, f"Invitation to {email_address} has already been retrieved.")
|
||||
# Assert that the Cancel link is not displayed
|
||||
self.assertNotContains(response, "Cancel")
|
||||
# Assert that the DomainInvitation is not deleted
|
||||
self.assertTrue(DomainInvitation.objects.filter(id=invitation.id).exists())
|
||||
DomainInvitation.objects.filter(email=email_address).delete()
|
||||
self.client.post(reverse("invitation-cancel", kwargs={"pk": invitation.id}))
|
||||
invitation = DomainInvitation.objects.get(id=invitation.id)
|
||||
self.assertEqual(invitation.status, DomainInvitation.DomainInvitationStatus.CANCELED)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_domain_invitation_cancel_no_permissions(self):
|
||||
"""Posting to the delete view as a different user should fail."""
|
||||
"""Posting to the cancel view as a different user should fail."""
|
||||
email_address = "mayor@igorville.gov"
|
||||
invitation, _ = DomainInvitation.objects.get_or_create(domain=self.domain, email=email_address)
|
||||
|
||||
|
|
|
@ -491,7 +491,7 @@ class DomainRequestTests(TestWithUser, WebTest):
|
|||
# Review page contains all the previously entered data
|
||||
# Let's make sure the long org name is displayed
|
||||
self.assertContains(review_page, "Federal")
|
||||
self.assertContains(review_page, "executive")
|
||||
self.assertContains(review_page, "Executive")
|
||||
self.assertContains(review_page, "Testorg")
|
||||
self.assertContains(review_page, "address 1")
|
||||
self.assertContains(review_page, "address 2")
|
||||
|
|
|
@ -912,6 +912,22 @@ class DomainAddUserView(DomainFormBaseView):
|
|||
existing_org_invitation and existing_org_invitation.portfolio != requestor_org
|
||||
)
|
||||
|
||||
def _check_invite_status(self, invite, email):
|
||||
if invite.status == DomainInvitation.DomainInvitationStatus.RETRIEVED:
|
||||
messages.warning(
|
||||
self.request,
|
||||
f"{email} is already a manager for this domain.",
|
||||
)
|
||||
return False
|
||||
elif invite.status == DomainInvitation.DomainInvitationStatus.CANCELED:
|
||||
invite.update_cancellation_status()
|
||||
invite.save()
|
||||
return True
|
||||
else:
|
||||
# else if it has been sent but not accepted
|
||||
messages.warning(self.request, f"{email} has already been invited to this domain")
|
||||
return False
|
||||
|
||||
def _send_domain_invitation_email(self, email: str, requestor: User, requested_user=None, add_success=True):
|
||||
"""Performs the sending of the domain invitation email,
|
||||
does not make a domain information object
|
||||
|
@ -948,24 +964,10 @@ class DomainAddUserView(DomainFormBaseView):
|
|||
try:
|
||||
invite = DomainInvitation.objects.get(email=email, domain=self.object)
|
||||
# check if the invite has already been accepted
|
||||
if invite.status == DomainInvitation.DomainInvitationStatus.RETRIEVED:
|
||||
add_success = False
|
||||
messages.warning(
|
||||
self.request,
|
||||
f"{email} is already a manager for this domain.",
|
||||
)
|
||||
elif invite.status == DomainInvitation.DomainInvitationStatus.CANCELED:
|
||||
add_success = True
|
||||
invite.update_cancellation_status()
|
||||
else:
|
||||
add_success = False
|
||||
# else if it has been sent but not accepted
|
||||
messages.warning(self.request, f"{email} has already been invited to this domain")
|
||||
add_success = self._check_invite_status(invite, email)
|
||||
except Exception:
|
||||
logger.error("An error occured")
|
||||
|
||||
|
||||
|
||||
try:
|
||||
send_templated_email(
|
||||
"emails/domain_invitation.txt",
|
||||
|
@ -1070,6 +1072,7 @@ class DomainInvitationCancelView(SuccessMessageMixin, DomainInvitationUpdateView
|
|||
form = self.get_form()
|
||||
if form.is_valid() and self.object.status == self.object.DomainInvitationStatus.INVITED:
|
||||
self.object.cancel_invitation()
|
||||
self.object.save()
|
||||
return self.form_valid(form)
|
||||
else:
|
||||
# Produce an error message if the domain invatation status is RETRIEVED
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue