From a251d1ca1ad2d4ec4fe9ba14f5a326728329f247 Mon Sep 17 00:00:00 2001 From: zandercymatics <141044360+zandercymatics@users.noreply.github.com> Date: Fri, 5 Jan 2024 09:54:31 -0700 Subject: [PATCH] Conditional deletion --- src/registrar/templates/home.html | 53 +++++++++++++++--------------- src/registrar/tests/test_views.py | 5 +-- src/registrar/views/application.py | 14 ++++++++ 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/src/registrar/templates/home.html b/src/registrar/templates/home.html index 3a9a5a611..33708c8f6 100644 --- a/src/registrar/templates/home.html +++ b/src/registrar/templates/home.html @@ -81,7 +81,6 @@ {% endif %} - {% endfor %} @@ -141,32 +140,34 @@ - - - Delete - + {% if application.status == "started" or application.status == "withdrawn" %} + + + Delete + -
-
- {% with heading="Are you sure you want to delete "|add:application.requested_domain.name|add:"?" %} - {% include 'includes/modal.html' with modal_heading=heading modal_description="This will remove the domain request from the .gov registrar. This action cannot be undone." modal_button=modal_button|safe %} - {% endwith %} -
-
+
+
+ {% with heading="Are you sure you want to delete "|add:application.requested_domain.name|add:"?" %} + {% include 'includes/modal.html' with modal_heading=heading modal_description="This will remove the domain request from the .gov registrar. This action cannot be undone." modal_button=modal_button|safe %} + {% endwith %} +
+
+ {% endif %} {% endfor %} diff --git a/src/registrar/tests/test_views.py b/src/registrar/tests/test_views.py index 8f812b815..246222fe7 100644 --- a/src/registrar/tests/test_views.py +++ b/src/registrar/tests/test_views.py @@ -88,8 +88,9 @@ class LoggedInTests(TestWithUser): site = DraftDomain.objects.create(name="igorville.gov") application = DomainApplication.objects.create(creator=self.user, requested_domain=site) response = self.client.get("/") - # count = 2 because it is also in screenreader content - self.assertContains(response, "igorville.gov", count=2) + + # count = 6 because it is also in screenreader content, and in the delete modal + self.assertContains(response, "igorville.gov", count=6) # clean up application.delete() diff --git a/src/registrar/views/application.py b/src/registrar/views/application.py index 63adbf3d9..5043ef245 100644 --- a/src/registrar/views/application.py +++ b/src/registrar/views/application.py @@ -1,4 +1,5 @@ import logging +from django.forms import ValidationError from django.http import Http404, HttpResponse, HttpResponseRedirect from django.shortcuts import redirect, render @@ -576,7 +577,20 @@ class ApplicationWithdrawn(DomainApplicationPermissionWithdrawView): class DomainApplicationDeleteView(DomainApplicationPermissionDeleteView): + """Delete view for home that allows the end user to delete DomainApplications""" object: DomainApplication # workaround for type mismatch in DeleteView + def has_permission(self): + """Custom override for has_permission to exclude all statuses, except WITHDRAWN and STARTED""" + has_perm = super().has_permission() + if not has_perm: + return False + + status = self.get_object().status + if status not in [DomainApplication.ApplicationStatus.WITHDRAWN, DomainApplication.ApplicationStatus.STARTED]: + return False + + return True + def get_success_url(self): return reverse("home") \ No newline at end of file