mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
names: Handle addition of duplicate static domains
Tests: - Adding an new unique domain works. - Adding an existing domain results in an error. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
5544eff707
commit
84bf20e1b8
@ -11,6 +11,8 @@ from django.utils.translation import gettext_lazy as _
|
||||
from plinth import cfg
|
||||
from plinth.utils import format_lazy
|
||||
|
||||
from . import privileged
|
||||
|
||||
HOSTNAME_REGEX = r'^[a-zA-Z0-9]([-a-zA-Z0-9]{,61}[a-zA-Z0-9])?$'
|
||||
|
||||
|
||||
@ -116,3 +118,11 @@ class DomainAddForm(forms.Form):
|
||||
r'^[a-zA-Z0-9]([-a-zA-Z0-9.]{,251}[a-zA-Z0-9])?$',
|
||||
_('Invalid domain name')), _domain_label_validator
|
||||
], strip=True)
|
||||
|
||||
def clean_domain_name(self):
|
||||
"""Check if the name is valid."""
|
||||
domain_name = self.cleaned_data['domain_name']
|
||||
if domain_name in privileged.get_domains():
|
||||
raise ValidationError(_('Domain already exists.'))
|
||||
|
||||
return domain_name
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user