implemented new in domain model dnssec_ds_confirmed and dnssec_key_confirmed to control intial blurb msg on the add pages, cleaned up JS

This commit is contained in:
Rachid Mrad 2023-10-03 14:06:59 -04:00
parent 0725b3c244
commit faae7693c4
No known key found for this signature in database
GPG key ID: EF38E4CEC4A8F3CF
7 changed files with 115 additions and 2 deletions

View file

@ -292,7 +292,46 @@ function handleValidationClick(e) {
newForm.innerHTML = newForm.innerHTML.replace(formLabelRegex, `DS Data Record ${formNum+1}`)
// newForm.innerHTML = newForm.innerHTML.replace(formExampleRegex, `ns${formNum+1}`)
container.insertBefore(newForm, addButton)
newForm.querySelector("input").value = ""
let inputs = newForm.querySelectorAll("input");
// Reset the values of each input to blank
inputs.forEach((input) => {
input.classList.remove("usa-input--error");
if (input.type === "text" || input.type === "number" || input.type === "password") {
input.value = ""; // Set the value to an empty string
} else if (input.type === "checkbox" || input.type === "radio") {
input.checked = false; // Uncheck checkboxes and radios
}
});
let selects = newForm.querySelectorAll("select");
selects.forEach((select) => {
select.classList.remove("usa-input--error");
select.selectedIndex = 0; // Set the value to an empty string
});
let labels = newForm.querySelectorAll("label");
labels.forEach((label) => {
label.classList.remove("usa-label--error");
});
let usaFormGroups = newForm.querySelectorAll(".usa-form-group");
usaFormGroups.forEach((usaFormGroup) => {
usaFormGroup.classList.remove("usa-form-group--error");
});
let usaErrorMessages = newForm.querySelectorAll(".usa-error-message");
usaErrorMessages.forEach((usaErrorMessage) => {
let parentDiv = usaErrorMessage.closest('div');
if (parentDiv) {
parentDiv.remove(); // Remove the parent div if it exists
}
});
totalForms.setAttribute('value', `${formNum+1}`)
}

View file

@ -0,0 +1,28 @@
# Generated by Django 4.2.1 on 2023-10-03 17:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("registrar", "0033_domain_dnssec_enabled"),
]
operations = [
migrations.AddField(
model_name="domain",
name="dnssec_ds_confirmed",
field=models.BooleanField(
default=False,
help_text="Boolean indicating if DS record adding is confirmed",
),
),
migrations.AddField(
model_name="domain",
name="dnssec_key_confirmed",
field=models.BooleanField(
default=False,
help_text="Boolean indicating if Key record adding is confirmed",
),
),
]

View file

@ -711,6 +711,16 @@ class Domain(TimeStampedModel, DomainHelper):
default=False,
help_text="Boolean indicating if dnssec is enabled",
)
dnssec_ds_confirmed = models.BooleanField(
default=False,
help_text="Boolean indicating if DS record adding is confirmed",
)
dnssec_key_confirmed = models.BooleanField(
default=False,
help_text="Boolean indicating if Key record adding is confirmed",
)
# ForeignKey on UserDomainRole creates a "permissions" member for
# all of the user-roles that are in place for this domain

View file

@ -9,7 +9,7 @@
<p>DNSSEC, or DNS Security Extensions, is additional security layer to protect your website. Enabling DNSSEC ensures that when someone visits your website, they can be certain that it's connecting to the correct server, preventing potential hijacking or tampering with your domain's records. <a href="https://www.icann.org/resources/pages/dnssec-what-is-it-why-important-2019-03-05-en">Read more about DNSSEC and why it is important.</a></p>
<form class="usa-form usa-form--extra-large" method="post">
<form class="usa-form usa-form--large" method="post">
{% csrf_token %}
{% if not domain.dnssec_enabled %}
<div class="usa-alert usa-alert--info usa-alert--slim margin-bottom-3">

View file

@ -16,6 +16,16 @@
</p>
</div>
</div>
{% elif not domain.dnssec_ds_confirmed %}
<p>In order to enable DNSSEC and add DS records, you must first configure it with your DNS hosting service. Your configuration will determine whether you need to add DS Data or Key Data. Contact your DNS hosting provider if you are unsure which record type to add.</p>
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
{% csrf_token %}
<button
type="submit"
class="usa-button"
name="confirm-ds"
>Add DS Data record</button>
</form>
{% else %}
{% include "includes/required_fields.html" %}

View file

@ -16,6 +16,16 @@
</p>
</div>
</div>
{% elif not domain.dnssec_key_confirmed %}
<p>In order to enable DNSSEC and add DS records, you must first configure it with your DNS hosting service. Your configuration will determine whether you need to add DS Data or Key Data. Contact your DNS hosting provider if you are unsure which record type to add.</p>
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
{% csrf_token %}
<button
type="submit"
class="usa-button"
name="confirm-key"
>Add DS Key record</button>
</form>
{% else %}
{% include "includes/required_fields.html" %}

View file

@ -255,6 +255,8 @@ class DomainDNSSECView(DomainPermissionView, FormMixin):
self.domain.save()
elif 'cancel' in request.POST:
self.domain.dnssec_enabled = False
self.domain.dnssec_ds_confirmed = False
self.domain.dnssec_key_confirmed = False
self.domain.save()
elif 'disable_dnssec' in request.POST:
try:
@ -266,6 +268,8 @@ class DomainDNSSECView(DomainPermissionView, FormMixin):
self.request, errmsg
)
self.domain.dnssec_enabled = False
self.domain.dnssec_ds_confirmed = False
self.domain.dnssec_key_confirmed = False
self.domain.save()
return self.form_valid(form)
@ -313,6 +317,12 @@ class DomainDsdataView(DomainPermissionView, FormMixin):
self.object = self.get_object()
formset = self.get_form()
if 'confirm-ds' in request.POST:
self.object.dnssec_ds_confirmed = True
self.object.dnssec_key_confirmed = False
self.object.save()
return super().form_valid(formset)
if formset.is_valid():
return self.form_valid(formset)
else:
@ -397,6 +407,12 @@ class DomainKeydataView(DomainPermissionView, FormMixin):
"""Formset submission posts to this view."""
self.object = self.get_object()
formset = self.get_form()
if 'confirm-key' in request.POST:
self.object.dnssec_key_confirmed = True
self.object.dnssec_ds_confirmed = False
self.object.save()
return super().form_valid(formset)
if formset.is_valid():
return self.form_valid(formset)