mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
dynamicdns: Handle addition of duplicate domains
Tests: - Adding a new domain works. Adding a new domain with old name results in error message. - Editing a old domain works. Updating the domain name works. Updating configuration parameters without domain name change works. - Adding a domain with capital letters results in domain with lower cased letters. Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
84bf20e1b8
commit
d411718fb1
@ -5,10 +5,12 @@ Forms for the dynamicsdns module.
|
||||
|
||||
from django import forms
|
||||
from django.core import validators
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import gettext_lazy
|
||||
|
||||
from plinth import cfg
|
||||
from plinth.modules.dynamicdns import get_config
|
||||
from plinth.utils import format_lazy
|
||||
|
||||
|
||||
@ -94,10 +96,6 @@ class DomainForm(forms.Form):
|
||||
"""Further validate and transform field data."""
|
||||
cleaned_data = super().clean()
|
||||
|
||||
# Domain name is not case sensitive, but Let's Encrypt
|
||||
# certificate paths use lower-case domain name.
|
||||
cleaned_data['domain'] = cleaned_data['domain'].lower()
|
||||
|
||||
update_url = cleaned_data.get('update_url')
|
||||
password = cleaned_data.get('password')
|
||||
service_type = cleaned_data.get('service_type')
|
||||
@ -129,3 +127,14 @@ class DomainForm(forms.Form):
|
||||
|
||||
del cleaned_data['show_password']
|
||||
return cleaned_data
|
||||
|
||||
def clean_domain(self):
|
||||
"""Validate the domain field."""
|
||||
# Domain name is not case sensitive, but Let's Encrypt
|
||||
# certificate paths use lower-case domain name.
|
||||
domain = self.cleaned_data['domain'].lower()
|
||||
initial_domain = self.initial.get('domain')
|
||||
if initial_domain != domain and domain in get_config()['domains']:
|
||||
raise ValidationError(_('Domain already exists.'))
|
||||
|
||||
return domain
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user