Nameserver mnts, glue magic

This commit is contained in:
Sebastian Lohff 2017-03-31 03:20:39 +02:00
parent 697f203974
commit 123503b8dd
1 changed files with 19 additions and 2 deletions

View File

@ -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