Consolidate checks on withdrawable and awaiting review

This commit is contained in:
zandercymatics 2024-09-19 09:47:16 -06:00
parent 732c982caa
commit 81c27330b2
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
6 changed files with 44 additions and 7 deletions

View file

@ -51,6 +51,25 @@ class DomainRequest(TimeStampedModel):
"""Returns the associated label for a given status name"""
return cls(status_name).label if status_name else None
@classmethod
def statuses_awaiting_review(cls):
"""Returns all statuses that are awaiting a review from analysts"""
return [
cls.SUBMITTED,
cls.IN_REVIEW
]
# TODO - a better approach might be to just grab the value of source?
# How??
@classmethod
def withdrawable_statuses(cls):
"""Returns all statuses that are withdrawable"""
return [
cls.SUBMITTED,
cls.IN_REVIEW,
cls.ACTION_NEEDED
]
class StateTerritoryChoices(models.TextChoices):
ALABAMA = "AL", "Alabama (AL)"
ALASKA = "AK", "Alaska (AK)"
@ -583,6 +602,14 @@ class DomainRequest(TimeStampedModel):
blank=True,
)
def is_awaiting_review(self) -> bool:
"""Checks if the current status is in submitted or in_review"""
return self.status in DomainRequest.DomainRequestStatus.statuses_awaiting_review()
def is_withdrawable(self):
"""Helper function that determines if the request can be withdrawn in its current status"""
return self.status in DomainRequest.DomainRequestStatus.withdrawable_statuses()
def get_first_status_set_date(self, status):
"""Returns the date when the domain request was first set to the given status."""
log_entry = (

View file

@ -9,4 +9,6 @@
Need to make changes?
</h2>
{% if show_withdraw_text %}
<p>If you need to change your request you have to first withdraw it. Once you withdraw the request you can edit it and submit it again. Changing your request might add to the wait time.</p>
{% endif %}

View file

@ -125,13 +125,13 @@
{% endblock status_metadata %}
{% block status_blurb %}
{% if DomainRequest.status == 'submitted' %}
<p>{% include "includes/domain_request.html" %}</p>
{% if DomainRequest.is_withdrawable %}
<p>{% include "includes/domain_request_awaiting_review.html" with show_withdraw_text=True %}</p>
{% endif %}
{% endblock status_blurb %}
{% block modify_request %}
{% if DomainRequest.status != "started" and DomainRequest.status != 'withdrawn' and DomainRequest.status != 'rejected' %}
{% if DomainRequest.is_withdrawable %}
<p><a href="{% url 'domain-request-withdraw-confirmation' pk=DomainRequest.id %}" class="usa-button usa-button--outline withdraw_outline">
Withdraw request</a>
</p>

View file

@ -2,6 +2,13 @@
{% load custom_filters %}
{% load static url_helpers %}
{% comment %} Do not show the withdraw button {% endcomment %}
{% comment %} Do not show the withdrawal text in viewonly mode {% endcomment %}
{% block status_blurb %}
{% if DomainRequest.is_awaiting_review %}
<p>{% include "includes/domain_request_awaiting_review.html" with show_withdraw_text=False %}</p>
{% endif %}
{% endblock status_blurb %}
{% comment %} Do not show action buttons in viewonly mode {% endcomment %}
{% block modify_request %}
{% endblock modify_request %}

View file

@ -2238,11 +2238,11 @@ class TestDomainRequestIncomplete(TestCase):
@less_console_noise_decorator
def test_is_organization_name_and_address_complete(self):
self.assertTrue(self.domain_request._is_organization_name_and_address_complete())
self.assertTrue(self.domain_request.is_organization_name_and_address_complete())
self.domain_request.organization_name = None
self.domain_request.address_line1 = None
self.domain_request.save()
self.assertTrue(self.domain_request._is_organization_name_and_address_complete())
self.assertTrue(self.domain_request.is_organization_name_and_address_complete())
@less_console_noise_decorator
def test_is_senior_official_complete(self):

View file

@ -750,6 +750,7 @@ class Finished(DomainRequestWizard):
class DomainRequestStatus(DomainRequestPermissionView):
template_name = "domain_request_status.html"
def has_permission(self):
"""
Override of the base has_permission class to account for portfolio permissions