mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-21 02:06:03 +02:00
Conditional deletion
This commit is contained in:
parent
403bfb6433
commit
a251d1ca1a
3 changed files with 44 additions and 28 deletions
|
@ -81,7 +81,6 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td></td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -141,32 +140,34 @@
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<a
|
{% if application.status == "started" or application.status == "withdrawn" %}
|
||||||
id="button-toggle-delete-domain-alert-{{ forloop.counter }}"
|
<a
|
||||||
href="#toggle-delete-domain-alert-{{ forloop.counter }}"
|
id="button-toggle-delete-domain-alert-{{ forloop.counter }}"
|
||||||
class="usa-button--unstyled"
|
href="#toggle-delete-domain-alert-{{ forloop.counter }}"
|
||||||
aria-controls="toggle-delete-domain-alert-{{ forloop.counter }}"
|
class="usa-button--unstyled"
|
||||||
data-open-modal
|
aria-controls="toggle-delete-domain-alert-{{ forloop.counter }}"
|
||||||
>
|
data-open-modal
|
||||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24">
|
>
|
||||||
<use xlink:href="{%static 'img/sprite.svg'%}#delete"></use>
|
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24">
|
||||||
</svg>
|
<use xlink:href="{%static 'img/sprite.svg'%}#delete"></use>
|
||||||
Delete
|
</svg>
|
||||||
</a>
|
Delete
|
||||||
|
</a>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="usa-modal"
|
class="usa-modal"
|
||||||
id="toggle-delete-domain-alert-{{ forloop.counter }}"
|
id="toggle-delete-domain-alert-{{ forloop.counter }}"
|
||||||
aria-labelledby="Are you sure you want to continue?"
|
aria-labelledby="Are you sure you want to continue?"
|
||||||
aria-describedby="User will be removed"
|
aria-describedby="User will be removed"
|
||||||
data-force-action
|
data-force-action
|
||||||
>
|
>
|
||||||
<form method="POST" action="{% url "application-delete" pk=application.id %}">
|
<form method="POST" action="{% url "application-delete" pk=application.id %}">
|
||||||
{% with heading="Are you sure you want to delete "|add:application.requested_domain.name|add:"?" %}
|
{% 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 %}
|
{% 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 %}
|
{% endwith %}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -88,8 +88,9 @@ class LoggedInTests(TestWithUser):
|
||||||
site = DraftDomain.objects.create(name="igorville.gov")
|
site = DraftDomain.objects.create(name="igorville.gov")
|
||||||
application = DomainApplication.objects.create(creator=self.user, requested_domain=site)
|
application = DomainApplication.objects.create(creator=self.user, requested_domain=site)
|
||||||
response = self.client.get("/")
|
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
|
# clean up
|
||||||
application.delete()
|
application.delete()
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
|
from django.forms import ValidationError
|
||||||
|
|
||||||
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
from django.http import Http404, HttpResponse, HttpResponseRedirect
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
|
@ -576,7 +577,20 @@ class ApplicationWithdrawn(DomainApplicationPermissionWithdrawView):
|
||||||
|
|
||||||
|
|
||||||
class DomainApplicationDeleteView(DomainApplicationPermissionDeleteView):
|
class DomainApplicationDeleteView(DomainApplicationPermissionDeleteView):
|
||||||
|
"""Delete view for home that allows the end user to delete DomainApplications"""
|
||||||
object: DomainApplication # workaround for type mismatch in DeleteView
|
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):
|
def get_success_url(self):
|
||||||
return reverse("home")
|
return reverse("home")
|
Loading…
Add table
Add a link
Reference in a new issue