Cancel removed from retrieved invitations, cancel attempts on retrieved invitations errors

This commit is contained in:
David Kennedy 2024-03-21 13:57:24 -04:00
parent 357ccf0b5b
commit 1179a6a6b7
No known key found for this signature in database
GPG key ID: 6528A5386E66B96B
2 changed files with 14 additions and 0 deletions

View file

@ -133,9 +133,11 @@
<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>
{% if invitation.status == invitation.DomainInvitationStatus.INVITED %}
<form method="POST" action="{% url "invitation-delete" pk=invitation.id %}">
{% csrf_token %}<input type="submit" class="usa-button--unstyled text-no-underline" value="Cancel">
</form>
{% endif %}
</td>
</tr>
{% endfor %}

View file

@ -822,6 +822,18 @@ class DomainAddUserView(DomainFormBaseView):
class DomainInvitationDeleteView(SuccessMessageMixin, DomainInvitationPermissionDeleteView):
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):
return reverse("domain-users", kwargs={"pk": self.object.domain.id})