Disallow same nameserver with multiple glues

This commit is contained in:
Sebastian Lohff 2017-04-05 02:45:04 +02:00
parent c1afcbfa3a
commit 2fc672690f
1 changed files with 10 additions and 0 deletions

View File

@ -121,6 +121,16 @@ class NameserverForm(MntFormMixin, WhoisObjectFormMixin, forms.ModelForm):
if not found: if not found:
raise forms.ValidationError("You have glue IPs set, but this domain is not under a domain you control.") raise forms.ValidationError("You have glue IPs set, but this domain is not under a domain you control.")
if ipv4 or ipv6:
try:
ns = Nameserver.objects.get(Q(name=name) & (Q(glueIPv4__isnull=False) | Q(glueIPv6__isnull=False)))
if self._create or ns.pk != self.instance.pk:
nsMnts = ", ".join(n.handle for n in ns.mnt_by.all())
raise forms.ValidationError("Only one nameserver for this domain can have glue records and one already exists (maintained by %s)" % nsMnts)
except Nameserver.DoesNotExist:
pass
failedMnts = set() failedMnts = set()
for ns in Nameserver.objects.filter(name=name, mnt_by__in=mntBy): for ns in Nameserver.objects.filter(name=name, mnt_by__in=mntBy):
if self._create or self.instance.pk != ns.pk: if self._create or self.instance.pk != ns.pk: