fix: [BB-6261] warn and trim name for site configuration before saving
This commit is contained in:
committed by
Navin Karkera
parent
0874ccfc94
commit
1172dd00e5
@@ -70,6 +70,7 @@ class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
site_id = options.get('site_id')
|
||||
domain = options.get('domain')
|
||||
name = domain
|
||||
configuration = options.get('configuration')
|
||||
config_file_data = options.get('config_file_data')
|
||||
|
||||
@@ -78,9 +79,18 @@ class Command(BaseCommand):
|
||||
if site_id is not None:
|
||||
site, created = Site.objects.get_or_create(id=site_id)
|
||||
else:
|
||||
name_max_length = Site._meta.get_field("name").max_length
|
||||
if name:
|
||||
if len(str(name)) > name_max_length:
|
||||
LOG.warning(
|
||||
f"The name {name} is too long, truncating to {name_max_length}"
|
||||
" characters. Please update site name in admin."
|
||||
)
|
||||
# trim name as the column has a limit of 50 characters
|
||||
name = name[:name_max_length]
|
||||
site, created = Site.objects.get_or_create(
|
||||
domain=domain,
|
||||
name=domain,
|
||||
name=name,
|
||||
)
|
||||
if created:
|
||||
LOG.info(f"Site does not exist. Created new site '{site.domain}'")
|
||||
|
||||
@@ -107,6 +107,19 @@ class CreateOrUpdateSiteConfigurationTest(TestCase):
|
||||
assert not site_configuration.site_values
|
||||
assert not site_configuration.enabled
|
||||
|
||||
def test_site_created_when_domain_longer_than_50_characters(self):
|
||||
"""
|
||||
Verify that a SiteConfiguration instance is created with name trimmed
|
||||
to 50 characters when domain is longer than 50 characters
|
||||
"""
|
||||
self.assert_site_configuration_does_not_exist()
|
||||
|
||||
domain = "studio.newtestserverwithlongname.development.opencraft.hosting"
|
||||
call_command(self.command, f"{domain}")
|
||||
site = Site.objects.filter(domain=domain)
|
||||
assert site.exists()
|
||||
assert site[0].name == domain[:50]
|
||||
|
||||
def test_both_enabled_disabled_flags(self):
|
||||
"""
|
||||
Verify the error on providing both the --enabled and --disabled flags.
|
||||
|
||||
Reference in New Issue
Block a user