diff --git a/credentials/apps/edx_credentials_extensions/edly_credentials_app/api/v1/views/edly_sites.py b/credentials/apps/edx_credentials_extensions/edly_credentials_app/api/v1/views/edly_sites.py index 6176f391d..31f848fa7 100644 --- a/credentials/apps/edx_credentials_extensions/edly_credentials_app/api/v1/views/edly_sites.py +++ b/credentials/apps/edx_credentials_extensions/edly_credentials_app/api/v1/views/edly_sites.py @@ -48,6 +48,7 @@ def process_client_sites_setup(self): """ edly_slug = self.request.data.get('edly_slug', '') credentials_base = self.request.data.get('credentials_site', '') + old_credentials_base = self.request.data.get('old_domain_values', {}).get('credentials_site', None) theme_dir_name = self.request.data.get('theme_dir_name', 'openedx') lms_url_root = '{protocol}://{lms_url_root}'.format( protocol=self.request.data.get('protocol', 'https'), @@ -61,7 +62,11 @@ def process_client_sites_setup(self): protocol=self.request.data.get('protocol', 'https'), wordpress_site=self.request.data.get('wordpress_site', '') ) - credentials_site, __ = Site.objects.update_or_create(domain=credentials_base, defaults=dict(name=credentials_base)) + credentials_site, __ = Site.objects.update_or_create( + domain=old_credentials_base, + name=old_credentials_base, + defaults={'domain': credentials_base, 'name': credentials_base}, + ) credentials_site_config, __ = SiteConfiguration.objects.update_or_create( site=credentials_site, defaults=dict( diff --git a/credentials/apps/edx_credentials_extensions/edly_credentials_app/api/v1/views/tests/test_views.py b/credentials/apps/edx_credentials_extensions/edly_credentials_app/api/v1/views/tests/test_views.py index a733c49ef..dbac41233 100644 --- a/credentials/apps/edx_credentials_extensions/edly_credentials_app/api/v1/views/tests/test_views.py +++ b/credentials/apps/edx_credentials_extensions/edly_credentials_app/api/v1/views/tests/test_views.py @@ -191,6 +191,9 @@ def test_client_setup_idempotent(self): sites_count = Site.objects.all().count() site_configurations_count = SiteConfiguration.objects.all().count() + old_domain = self.request_data.get('credentials_site') + self.request_data['credentials_site'] = 'new.example.credentials' + self.request_data['old_domain_values'] = dict(credentials_site=old_domain) response = self.client.post(self.edly_sites_url, data=self.request_data, format='json') assert response.status_code == status.HTTP_200_OK