mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-23 11:16:07 +02:00
work in progress
This commit is contained in:
parent
5eb2591e2b
commit
16164f1f05
4 changed files with 30 additions and 13 deletions
|
@ -25,7 +25,8 @@ class DomainNameserverForm(forms.Form):
|
|||
"""Form for changing nameservers."""
|
||||
|
||||
server = forms.CharField(label="Name server", strip=True)
|
||||
# when adding IPs to this form ensure they are stripped as well
|
||||
|
||||
ip = forms.CharField(label="IP address", strip=True, required=False)
|
||||
|
||||
|
||||
NameserverFormset = formset_factory(
|
||||
|
|
|
@ -322,6 +322,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
)
|
||||
elif ip is not None and ip != []:
|
||||
for addr in ip:
|
||||
logger.info(f"ip address {addr}")
|
||||
if not self._valid_ip_addr(addr):
|
||||
raise NameserverError(
|
||||
code=nsErrorCodes.INVALID_IP, nameserver=nameserver, ip=ip
|
||||
|
@ -334,7 +335,9 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
returns:
|
||||
isValid (boolean)-True for valid ip address"""
|
||||
try:
|
||||
logger.info(f"in valid_ip_addr: {ipToTest}")
|
||||
ip = ipaddress.ip_address(ipToTest)
|
||||
logger.info(ip.version)
|
||||
return ip.version == 6 or ip.version == 4
|
||||
|
||||
except ValueError:
|
||||
|
@ -602,7 +605,7 @@ class Domain(TimeStampedModel, DomainHelper):
|
|||
if len(hosts) > 13:
|
||||
raise NameserverError(code=nsErrorCodes.TOO_MANY_HOSTS)
|
||||
|
||||
if self.state not in [self.State.DNS_NEEDED, self.State.READY]:
|
||||
if self.state not in [self.State.DNS_NEEDED, self.State.READY, self.State.UNKNOWN]:
|
||||
raise ActionNotAllowed("Nameservers can not be " "set in the current state")
|
||||
|
||||
logger.info("Setting nameservers")
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
{% for form in formset %}
|
||||
<div class="server-form">
|
||||
<div class="grid-row grid-gap-2 flex-end">
|
||||
<div class="tablet:grid-col-6">
|
||||
{% with sublabel_text="Example: ns"|concat:forloop.counter|concat:".example.com" %}
|
||||
{% if forloop.counter <= 2 %}
|
||||
{% with attr_required=True %}
|
||||
|
@ -32,6 +34,13 @@
|
|||
{% endif %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
<div class="tablet:grid-col-6">
|
||||
{% with sublabel_text="Example: ns"|concat:forloop.counter|concat:".example.com" %}
|
||||
{% input_with_errors form.ip %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
<button type="button" class="usa-button usa-button--unstyled display-block" id="add-nameserver-form">
|
||||
|
|
|
@ -173,7 +173,7 @@ class DomainNameserversView(DomainPermissionView, FormMixin):
|
|||
|
||||
if nameservers is not None:
|
||||
# Add existing nameservers as initial data
|
||||
initial_data.extend({"server": name} for name, *ip in nameservers)
|
||||
initial_data.extend({"server": name, "ip": ip} for name, ip in nameservers)
|
||||
|
||||
# Ensure at least 3 fields, filled or empty
|
||||
while len(initial_data) < 2:
|
||||
|
@ -198,6 +198,7 @@ class DomainNameserversView(DomainPermissionView, FormMixin):
|
|||
|
||||
for i, form in enumerate(formset):
|
||||
form.fields["server"].label += f" {i+1}"
|
||||
form.fields["ip"].label += f" {i+1}"
|
||||
if i < 2:
|
||||
form.fields["server"].required = True
|
||||
else:
|
||||
|
@ -221,7 +222,10 @@ class DomainNameserversView(DomainPermissionView, FormMixin):
|
|||
nameservers = []
|
||||
for form in formset:
|
||||
try:
|
||||
as_tuple = (form.cleaned_data["server"],)
|
||||
as_tuple = (
|
||||
form.cleaned_data["server"],
|
||||
[form.cleaned_data["ip"]]
|
||||
)
|
||||
nameservers.append(as_tuple)
|
||||
except KeyError:
|
||||
# no server information in this field, skip it
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue