mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-04 17:06:27 +00:00
Merge branch 'fix_#248' into 'dev'
Fix #248 See merge request re2o/re2o!498
This commit is contained in:
commit
94d9efcc0b
2 changed files with 42 additions and 6 deletions
36
machines/migrations/0107_fix_lowercase_domain.py
Normal file
36
machines/migrations/0107_fix_lowercase_domain.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
from django.core.exceptions import ValidationError
|
||||
import logging
|
||||
|
||||
def fix_duplicate(apps, schema_editor):
|
||||
logger = logging.getLogger(__name__)
|
||||
db_alias = schema_editor.connection.alias
|
||||
Domain = apps.get_model("machines", "Domain")
|
||||
domains_to_fix = filter(lambda m : not m.name.islower(), Domain.objects.using(db_alias).all())
|
||||
for domain in domains_to_fix:
|
||||
try:
|
||||
domain.name = domain.name.lower()
|
||||
domain.validate_unique()
|
||||
domain.clean()
|
||||
except ValidationError:
|
||||
old_name = domain.name
|
||||
domain.name = domain.name.lower() + str(domain.interface_parent.id)
|
||||
domain.clean()
|
||||
warning_message = "Warning : Domain %s has been renamed %s due to dns uniqueness" % (old_name, domain.name)
|
||||
logger.warning(warning_message)
|
||||
domain.save()
|
||||
|
||||
def unfix_duplicate(apps, schema_editor):
|
||||
return
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("machines", "0106_auto_20191120_0159")]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(fix_duplicate, unfix_duplicate),
|
||||
]
|
|
@ -1623,15 +1623,15 @@ class Domain(RevMixin, AclMixin, FieldPermissionModelMixin, models.Model):
|
|||
raise ValidationError(
|
||||
_("You can't create a CNAME record pointing to itself.")
|
||||
)
|
||||
HOSTNAME_LABEL_PATTERN = re.compile(r"(?!-)[A-Z\d-]+(?<!-)$", re.IGNORECASE)
|
||||
dns = self.name.lower()
|
||||
if len(dns) > 63:
|
||||
HOSTNAME_LABEL_PATTERN = re.compile(r"(?!-)[a-z\d-]+(?<!-)$")
|
||||
self.name = self.name.lower()
|
||||
if len(self.name) > 63:
|
||||
raise ValidationError(
|
||||
_("The domain name %s is too long (over 63 characters).") % dns
|
||||
_("The domain name %s is too long (over 63 characters).") % self.name
|
||||
)
|
||||
if not HOSTNAME_LABEL_PATTERN.match(dns):
|
||||
if not HOSTNAME_LABEL_PATTERN.match(self.name):
|
||||
raise ValidationError(
|
||||
_("The domain name %s contains forbidden characters.") % dns
|
||||
_("The domain name %s contains forbidden characters.") % self.name
|
||||
)
|
||||
self.validate_unique()
|
||||
super(Domain, self).clean()
|
||||
|
|
Loading…
Reference in a new issue