Renewal form

This commit is contained in:
Rebecca Hsieh 2024-12-26 17:10:37 -08:00
parent 5909a7cb49
commit d84a789022
No known key found for this signature in database
9 changed files with 117 additions and 12 deletions

View file

@ -345,6 +345,11 @@ urlpatterns = [
views.DomainSecurityEmailView.as_view(),
name="domain-security-email",
),
path(
"domain/<int:pk>/renewal",
views.DomainRenewalView.as_view(),
name="domain-renewal",
),
path(
"domain/<int:pk>/users/add",
views.DomainAddUserView.as_view(),

View file

@ -44,7 +44,7 @@ class DomainFixture(DomainRequestFixture):
cls._approve_domain_requests(users)
@staticmethod
def _generate_fake_expiration_date(days_in_future=365):
def _generate_fake_expiration_date(days_in_future=40):
"""Generates a fake expiration date between 1 and 365 days in the future."""
current_date = timezone.now().date() # nosec
return current_date + timedelta(days=random.randint(1, days_in_future)) # nosec

View file

@ -1167,6 +1167,11 @@ class Domain(TimeStampedModel, DomainHelper):
threshold_date = now + timedelta(days=60)
return now < self.expiration_date <= threshold_date
###dummy method for testing for domain renewal form fail or success banner
def update_expiration(self, success=True):
return success
def state_display(self, request=None):
"""Return the display status of the domain."""
if self.is_expired() and (self.state != self.State.UNKNOWN):

View file

@ -1,5 +1,7 @@
{% extends "base.html" %}
{% load static %}
{% load static url_helpers %}
{% block title %}{{ domain.name }} | {% endblock %}
@ -53,8 +55,11 @@
{% endif %}
{% block domain_content %}
{% if request.path|endswith:"renewal"%}
<h1>Renew {{domain.name}} </h1>
{%else%}
<h1 class="break-word">Domain Overview</h1>
{% endif%}
{% endblock %} {# domain_content #}
{% endif %}
@ -62,4 +67,4 @@
</div>
</div>
</div>
{% endblock %} {# content #}
{% endblock %} {# content #}

View file

@ -50,7 +50,9 @@
{% if domain.get_state_help_text %}
<div class="padding-top-1 text-primary-darker">
{% if has_domain_renewal_flag and domain.is_expiring and is_domain_manager %}
This domain will expire soon. <a href="/not-available-yet">Renew to maintain access.</a>
This domain will expire soon.
{% url 'domain-renewal' pk=domain.id as url %}
<a href="{{ url }}">Renew to maintain access.</a>
{% elif has_domain_renewal_flag and domain.is_expiring and is_portfolio_user %}
This domain will expire soon. Contact one of the listed domain managers to renew the domain.
{% else %}

View file

@ -79,8 +79,14 @@
{% with url_name="domain-users" %}
{% include "includes/domain_sidenav_item.html" with item_text="Domain managers" %}
{% endwith %}
{% if has_domain_renewal_flag and is_domain_manager and domain.is_expiring %}
{% with url_name="domain-renewal" %}
{% include "includes/domain_sidenav_item.html" with item_text="Renewal form" %}
{% endwith %}
{% endif %}
{% endif %}
</ul>
</nav>
</div>
</div>

View file

@ -200,6 +200,7 @@ def is_domain_subpage(path):
"domain-users-add",
"domain-request-delete",
"domain-user-delete",
"domain-renewal",
"invitation-cancel",
]
return get_url_name(path) in url_names

View file

@ -14,6 +14,7 @@ from .domain import (
DomainInvitationCancelView,
DomainDeleteUserView,
PrototypeDomainDNSRecordView,
DomainRenewalView,
)
from .user_profile import UserProfileView, FinishProfileSetupView
from .health import *

View file

@ -12,7 +12,7 @@ from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin
from django.db import IntegrityError
from django.http import HttpResponseRedirect
from django.shortcuts import redirect
from django.shortcuts import redirect, render
from django.urls import reverse
from django.views.generic.edit import FormMixin
from django.conf import settings
@ -307,6 +307,90 @@ class DomainView(DomainBaseView):
self._update_session_with_domain()
class DomainRenewalView(DomainBaseView):
"""Domain detail overview page."""
template_name = "domain_renewal.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
default_emails = [DefaultEmail.PUBLIC_CONTACT_DEFAULT.value, DefaultEmail.LEGACY_DEFAULT.value]
context["hidden_security_emails"] = default_emails
security_email = self.object.get_security_email()
user = self.request.user
if security_email is None or security_email in default_emails:
context["security_email"] = None
context["user"] = user
return context
def can_access_domain_via_portfolio(self, pk):
"""Most views should not allow permission to portfolio users.
If particular views allow permissions, they will need to override
this function."""
portfolio = self.request.session.get("portfolio")
if self.request.user.has_any_domains_portfolio_permission(portfolio):
if Domain.objects.filter(id=pk).exists():
domain = Domain.objects.get(id=pk)
if domain.domain_info.portfolio == portfolio:
return True
return False
def in_editable_state(self, pk):
"""Override in_editable_state from DomainPermission
Allow detail page to be viewable"""
requested_domain = None
if Domain.objects.filter(id=pk).exists():
requested_domain = Domain.objects.get(id=pk)
# return true if the domain exists, this will allow the detail page to load
if requested_domain:
return True
return False
def _get_domain(self, request):
"""
override get_domain for this view so that domain overview
always resets the cache for the domain object
"""
self.session = request.session
self.object = self.get_object()
self._update_session_with_domain()
def post(self, request, pk):
domain = Domain.objects.filter(id=pk).first()
# Check if the checkbox is checked
is_policy_acknowledged = request.POST.get("is_policy_acknowledged", None)
if is_policy_acknowledged != "on":
print("!!! Checkbox is NOT acknowledged")
messages.error(
request, "Check the box if you read and agree to the requirements for operating a .gov domain."
)
return render(
request,
"domain_renewal.html",
{
"domain": domain,
"form": request.POST,
},
)
print("*** Checkbox is acknowledged")
if "submit_button" in request.POST:
print("*** Submit button clicked")
updated_expiration = domain.update_expiration(success=True)
print("*** Updated expiration result:", updated_expiration)
if updated_expiration is True:
messages.success(request, "This domain has been renewed for one year")
else:
messages.error(request, "This domain has not been renewed")
return HttpResponseRedirect(reverse("domain", kwargs={"pk": pk}))
class DomainOrgNameAddressView(DomainFormBaseView):
"""Organization view"""
@ -807,11 +891,7 @@ class DomainDNSSECView(DomainFormBaseView):
has_dnssec_records = self.object.dnssecdata is not None
# Create HTML for the modal button
modal_button = (
'<button type="submit" '
'class="usa-button usa-button--secondary" '
'name="disable_dnssec">Confirm</button>'
)
modal_button = '<button type="submit" ' 'name="disable_dnssec">Confirm</button>'
context["modal_button"] = modal_button
context["has_dnssec_records"] = has_dnssec_records