mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-15 05:54:11 +02:00
Merge pull request #1933 from cisagov/dk/1652-remove-delete-domain-invitation
Issue #1652: Domain invitation 'cancel' link does not display on retrieved invitations
This commit is contained in:
commit
9b9f1a5230
3 changed files with 30 additions and 0 deletions
|
@ -133,9 +133,11 @@
|
||||||
<td data-sort-value="{{ invitation.created_at|date:"U" }}" data-label="Date created">{{ invitation.created_at|date }} </td>
|
<td data-sort-value="{{ invitation.created_at|date:"U" }}" data-label="Date created">{{ invitation.created_at|date }} </td>
|
||||||
<td data-label="Status">{{ invitation.status|title }}</td>
|
<td data-label="Status">{{ invitation.status|title }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
{% if invitation.status == invitation.DomainInvitationStatus.INVITED %}
|
||||||
<form method="POST" action="{% url "invitation-delete" pk=invitation.id %}">
|
<form method="POST" action="{% url "invitation-delete" pk=invitation.id %}">
|
||||||
{% csrf_token %}<input type="submit" class="usa-button--unstyled text-no-underline" value="Cancel">
|
{% csrf_token %}<input type="submit" class="usa-button--unstyled text-no-underline" value="Cancel">
|
||||||
</form>
|
</form>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -665,6 +665,22 @@ class TestDomainManagers(TestDomainOverview):
|
||||||
with self.assertRaises(DomainInvitation.DoesNotExist):
|
with self.assertRaises(DomainInvitation.DoesNotExist):
|
||||||
DomainInvitation.objects.get(id=invitation.id)
|
DomainInvitation.objects.get(id=invitation.id)
|
||||||
|
|
||||||
|
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
|
||||||
|
)
|
||||||
|
with less_console_noise():
|
||||||
|
response = self.client.post(reverse("invitation-delete", 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()
|
||||||
|
|
||||||
def test_domain_invitation_cancel_no_permissions(self):
|
def test_domain_invitation_cancel_no_permissions(self):
|
||||||
"""Posting to the delete view as a different user should fail."""
|
"""Posting to the delete view as a different user should fail."""
|
||||||
email_address = "mayor@igorville.gov"
|
email_address = "mayor@igorville.gov"
|
||||||
|
|
|
@ -822,6 +822,18 @@ class DomainAddUserView(DomainFormBaseView):
|
||||||
class DomainInvitationDeleteView(SuccessMessageMixin, DomainInvitationPermissionDeleteView):
|
class DomainInvitationDeleteView(SuccessMessageMixin, DomainInvitationPermissionDeleteView):
|
||||||
object: DomainInvitation # workaround for type mismatch in DeleteView
|
object: DomainInvitation # workaround for type mismatch in DeleteView
|
||||||
|
|
||||||
|
def post(self, request, *args, **kwargs):
|
||||||
|
"""Override post method in order to error in the case when the
|
||||||
|
domain invitation status is RETRIEVED"""
|
||||||
|
self.object = self.get_object()
|
||||||
|
form = self.get_form()
|
||||||
|
if form.is_valid() and self.object.status == self.object.DomainInvitationStatus.INVITED:
|
||||||
|
return self.form_valid(form)
|
||||||
|
else:
|
||||||
|
# Produce an error message if the domain invatation status is RETRIEVED
|
||||||
|
messages.error(request, f"Invitation to {self.object.email} has already been retrieved.")
|
||||||
|
return HttpResponseRedirect(self.get_success_url())
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
return reverse("domain-users", kwargs={"pk": self.object.domain.id})
|
return reverse("domain-users", kwargs={"pk": self.object.domain.id})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue