From 123503b8dd5380471bcc7a3e076fc06ba6577788 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Fri, 31 Mar 2017 03:20:39 +0200 Subject: [PATCH] Nameserver mnts, glue magic --- domains/forms.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/domains/forms.py b/domains/forms.py index 4cd3c89..0245adf 100644 --- a/domains/forms.py +++ b/domains/forms.py @@ -95,9 +95,15 @@ class NameserverForm(MntFormMixin, WhoisObjectFormMixin, forms.ModelForm): if not self.errors: name = cleaned_data.get("name") + mntBy = cleaned_data.get("mnt_by") zone = ".".join(name.split(".")[-3:]) - ipv4 = cleaned_data.get("glueIPv4") - ipv6 = cleaned_data.get("glueIPv6") + ipv4 = cleaned_data.get("glueIPv4", None) + ipv6 = cleaned_data.get("glueIPv6", None) + + if not ipv4: + ipv4 = None + if not ipv6: + ipv6 = None if self._create and (ipv4 or ipv6) or not self._create and not (self.instance.glueIPv4 == ipv4 and self.instance.glueIPv6 == ipv6): mnts = self._user.maintainer_set.all() @@ -110,6 +116,17 @@ class NameserverForm(MntFormMixin, WhoisObjectFormMixin, forms.ModelForm): if not found: raise forms.ValidationError("You have glue IPs set, but this domain is not under a domain you control.") + + failedMnts = set() + for ns in Nameserver.objects.filter(name=name, mnt_by__in=mntBy): + if self._create or self.instance.pk != ns.pk: + for mnt in ns.mnt_by.all(): + if mnt in mntBy: + failedMnts.add(mnt.handle) + + if len(failedMnts) > 0: + raise forms.ValidationError("The following maintainer objects already have this nameservers: %s" % ", ".join(failedMnts)) + return cleaned_data