mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-04 08:52:16 +02:00
broad brush strokes for view and template
This commit is contained in:
parent
887d8c00f0
commit
ef2b8494cb
4 changed files with 153 additions and 21 deletions
|
@ -5,5 +5,5 @@ from .domain import (
|
|||
DomainSecurityEmailForm,
|
||||
DomainOrgNameAddressForm,
|
||||
ContactForm,
|
||||
DNSSECDSDataFormset,
|
||||
DomainDsdataFormset,
|
||||
)
|
||||
|
|
|
@ -141,24 +141,29 @@ class DomainOrgNameAddressForm(forms.ModelForm):
|
|||
self.fields["zipcode"].widget.attrs.pop("maxlength", None)
|
||||
|
||||
|
||||
class DomainDNSSECDSDataForm(forms.Form):
|
||||
class DomainDsdataForm(forms.Form):
|
||||
|
||||
"""Form for adding or editing a security email to a domain."""
|
||||
|
||||
# Q: What are the options?
|
||||
ALGORITHM_CHOICES = [
|
||||
("ECC Ghost", "ECC Ghost"),
|
||||
(1, "ERSA/MD5 [RSAMD5]"),
|
||||
(2 , "Diffie-Hellman [DH]"),
|
||||
(3 ,"DSA/SHA-1 [DSA]"),
|
||||
(5 ,"RSA/SHA-1 [RSASHA1]"),
|
||||
]
|
||||
# Q: What are the options?
|
||||
DIGEST_TYPE_CHOICES = [
|
||||
("SHA-256", "SHA-256"),
|
||||
(0, "Reserved"),
|
||||
(1, "SHA-256"),
|
||||
]
|
||||
|
||||
has_ds_key_data = forms.TypedChoiceField(
|
||||
required=True,
|
||||
label="DS Data record type",
|
||||
choices=[(False, "DS Data"), (True, "DS Data with Key Data")],
|
||||
)
|
||||
# TODO: ds key data
|
||||
# has_ds_key_data = forms.TypedChoiceField(
|
||||
# required=True,
|
||||
# label="DS Data record type",
|
||||
# choices=[(False, "DS Data"), (True, "DS Data with Key Data")],
|
||||
# )
|
||||
|
||||
key_tag = forms.IntegerField(
|
||||
required=True,
|
||||
|
@ -172,20 +177,21 @@ class DomainDNSSECDSDataForm(forms.Form):
|
|||
)
|
||||
|
||||
algorithm = forms.TypedChoiceField(
|
||||
required=True,
|
||||
label="Algorithm",
|
||||
choices=[("", "--Select--")] + ALGORITHM_CHOICES,
|
||||
choices=[(-1, "--Select--")] + ALGORITHM_CHOICES,
|
||||
# Q: Is this even needed or is a required=True sufficient?
|
||||
error_messages={
|
||||
"required": (
|
||||
"You must select an Algorithm"
|
||||
)
|
||||
},
|
||||
# error_messages={
|
||||
# "required": (
|
||||
# "You must select an Algorithm"
|
||||
# )
|
||||
# },
|
||||
)
|
||||
# Q: Is ChoiceFiled right? Or do we need to data types other than strings
|
||||
# (TypedChoiceField)
|
||||
digest_type = forms.TypedChoiceField(
|
||||
label="Digest Type",
|
||||
choices=[("", "--Select--")] + DIGEST_TYPE_CHOICES,
|
||||
choices=[(-1, "--Select--")] + DIGEST_TYPE_CHOICES,
|
||||
# Q: Is this even needed or is a required=True sufficient?
|
||||
error_messages={
|
||||
"required": (
|
||||
|
@ -193,12 +199,28 @@ class DomainDNSSECDSDataForm(forms.Form):
|
|||
)
|
||||
},
|
||||
)
|
||||
digest = forms.CharField(label="Digest")
|
||||
digest = forms.CharField(
|
||||
required=True,
|
||||
label="Digest",
|
||||
# validators=[
|
||||
# RegexValidator(
|
||||
# "^[0-9]{5}(?:-[0-9]{4})?$|^$",
|
||||
# message="Accepted range 0-65535.",
|
||||
# )
|
||||
# ],
|
||||
)
|
||||
|
||||
# Conditional DS Key Data fields
|
||||
# TODO: Conditional DS Key Data fields
|
||||
|
||||
|
||||
|
||||
DNSSECDSDataFormset = formset_factory(
|
||||
DomainDNSSECDSDataForm,
|
||||
DomainDsdataFormset = formset_factory(
|
||||
DomainDsdataForm,
|
||||
extra=1,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# TODO:
|
||||
# class DomainKeyDataForm(forms.Form):
|
||||
|
||||
# """"""
|
|
@ -7,4 +7,40 @@
|
|||
|
||||
<h1>DS Data</h1>
|
||||
|
||||
{% include "includes/required_fields.html" %}
|
||||
|
||||
<form class="usa-form usa-form--large" method="post" novalidate id="form-container">
|
||||
{% csrf_token %}
|
||||
{{ formset.management_form }}
|
||||
|
||||
{% for form in formset %}
|
||||
<div class="server-form">
|
||||
{% with attr_required=True %}
|
||||
{% input_with_errors form.key_tag %}
|
||||
{% endwith %}
|
||||
{% with attr_required=True %}
|
||||
{% input_with_errors form.algorithm %}
|
||||
{% endwith %}
|
||||
{% with attr_required=True %}
|
||||
{% input_with_errors form.digest_type %}
|
||||
{% endwith %}
|
||||
{% with attr_required=True %}
|
||||
{% input_with_errors form.digest %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<button type="button" class="usa-button usa-button--unstyled display-block" id="add-form">
|
||||
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img" width="24" height="24">
|
||||
<use xlink:href="{%static 'img/sprite.svg'%}#add_circle"></use>
|
||||
</svg><span class="margin-left-05">Add new record</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
class="usa-button"
|
||||
>Save
|
||||
</button>
|
||||
</form>
|
||||
|
||||
{% endblock %} {# domain_content #}
|
||||
|
|
|
@ -28,7 +28,14 @@ from ..forms import (
|
|||
DomainAddUserForm,
|
||||
DomainSecurityEmailForm,
|
||||
NameserverFormset,
|
||||
DomainDsdataFormset,
|
||||
)
|
||||
|
||||
from epplibwrapper import (
|
||||
common,
|
||||
extensions,
|
||||
)
|
||||
|
||||
from ..utility.email import send_templated_email, EmailSendingError
|
||||
from .utility import DomainPermissionView, DomainInvitationPermissionDeleteView
|
||||
|
||||
|
@ -233,6 +240,73 @@ class DomainDsdataView(DomainPermissionView):
|
|||
"""Domain DNSSEC ds data editing view."""
|
||||
|
||||
template_name = "domain_dsdata.html"
|
||||
form_class = DomainDsdataFormset
|
||||
|
||||
def get_initial(self):
|
||||
"""The initial value for the form (which is a formset here)."""
|
||||
domain = self.get_object()
|
||||
dnssecdata: extensions.DNSSECExtension = domain.dnssecdata
|
||||
initial_data = []
|
||||
|
||||
if dnssecdata.keyData is not None:
|
||||
# TODO: Throw an error
|
||||
pass
|
||||
|
||||
if dnssecdata.dsData is not None:
|
||||
# Add existing nameservers as initial data
|
||||
# TODO: create context for each element in the record
|
||||
# key_tag
|
||||
# algorithm
|
||||
# digest_type
|
||||
# digest
|
||||
initial_data.extend({"dsrecord": record} for record in dnssecdata.dsData)
|
||||
|
||||
return initial_data
|
||||
|
||||
def get_success_url(self):
|
||||
"""Redirect to the DS Data page for the domain."""
|
||||
return reverse("domain-dns-dnssec-dsdata", kwargs={"pk": self.object.pk})
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Adjust context from FormMixin for formsets."""
|
||||
context = super().get_context_data(**kwargs)
|
||||
# use "formset" instead of "form" for the key
|
||||
context["formset"] = context.pop("form")
|
||||
return context
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""Formset submission posts to this view."""
|
||||
self.object = self.get_object()
|
||||
formset = self.get_form()
|
||||
|
||||
if formset.is_valid():
|
||||
return self.form_valid(formset)
|
||||
else:
|
||||
return self.form_invalid(formset)
|
||||
|
||||
def form_valid(self, formset):
|
||||
"""The formset is valid, perform something with it."""
|
||||
|
||||
# Set the nameservers from the formset
|
||||
dnssecdata = []
|
||||
for form in formset:
|
||||
try:
|
||||
# TODO: build the right list of dicts to be passed
|
||||
dsrecord = (form.cleaned_data["dsrecord"],)
|
||||
dnssecdata.append(dsrecord)
|
||||
except KeyError:
|
||||
# no server information in this field, skip it
|
||||
pass
|
||||
domain = self.get_object()
|
||||
domain.dnssecdata = dnssecdata
|
||||
|
||||
messages.success(
|
||||
self.request, "The DS Data records for this domain have been updated."
|
||||
)
|
||||
|
||||
# superclass has the redirect
|
||||
return super().form_valid(formset)
|
||||
|
||||
|
||||
|
||||
class DomainKeydataView(DomainPermissionView):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue