From cd9ed369b0dcbb014648e31a53939131accbbc50 Mon Sep 17 00:00:00 2001 From: Kelvin Moutet Date: Fri, 29 Nov 2019 10:17:08 +0100 Subject: [PATCH] Fix backend domain name from dynamic to static --- .../serializers/ledger/aggregatealgo/serializer.py | 12 +++--------- .../serializers/ledger/algo/serializer.py | 12 +++--------- .../serializers/ledger/compositealgo/serializer.py | 12 +++--------- .../serializers/ledger/datamanager/serializer.py | 14 ++++---------- .../serializers/ledger/objective/serializer.py | 12 +++--------- backend/substrapp/tests/query/tests_query_algo.py | 1 + .../tests/query/tests_query_datamanager.py | 1 + .../tests/query/tests_query_datasample.py | 1 + .../substrapp/tests/query/tests_query_objective.py | 1 + 9 files changed, 20 insertions(+), 46 deletions(-) diff --git a/backend/substrapp/serializers/ledger/aggregatealgo/serializer.py b/backend/substrapp/serializers/ledger/aggregatealgo/serializer.py index d71b95b1b..3f8cf1bfe 100644 --- a/backend/substrapp/serializers/ledger/aggregatealgo/serializer.py +++ b/backend/substrapp/serializers/ledger/aggregatealgo/serializer.py @@ -19,20 +19,14 @@ def create(self, validated_data): permissions = validated_data.get('permissions') # TODO, create a datamigration with new Site domain name when we will know the name of the final website - host = '' - protocol = 'http://' - request = self.context.get('request', None) - - if request: - protocol = 'https://' if request.is_secure() else 'http://' - host = request.get_host() + current_site = getattr(settings, "DEFAULT_DOMAIN") args = { 'name': name, 'hash': get_hash(instance.file), - 'storageAddress': protocol + host + reverse('substrapp:aggregate_algo-file', args=[instance.pk]), + 'storageAddress': current_site + reverse('substrapp:aggregate_algo-file', args=[instance.pk]), 'descriptionHash': get_hash(instance.description), - 'descriptionStorageAddress': protocol + host + reverse( + 'descriptionStorageAddress': current_site + reverse( 'substrapp:aggregate_algo-description', args=[instance.pk]), 'permissions': {'process': { 'public': permissions.get('public'), diff --git a/backend/substrapp/serializers/ledger/algo/serializer.py b/backend/substrapp/serializers/ledger/algo/serializer.py index 78365f26e..5af7d1d01 100644 --- a/backend/substrapp/serializers/ledger/algo/serializer.py +++ b/backend/substrapp/serializers/ledger/algo/serializer.py @@ -19,20 +19,14 @@ def create(self, validated_data): permissions = validated_data.get('permissions') # TODO, create a datamigration with new Site domain name when we will know the name of the final website - host = '' - protocol = 'http://' - request = self.context.get('request', None) - - if request: - protocol = 'https://' if request.is_secure() else 'http://' - host = request.get_host() + current_site = getattr(settings, "DEFAULT_DOMAIN") args = { 'name': name, 'hash': get_hash(instance.file), - 'storageAddress': protocol + host + reverse('substrapp:algo-file', args=[instance.pk]), + 'storageAddress': current_site + reverse('substrapp:algo-file', args=[instance.pk]), 'descriptionHash': get_hash(instance.description), - 'descriptionStorageAddress': protocol + host + reverse('substrapp:algo-description', args=[instance.pk]), + 'descriptionStorageAddress': current_site + reverse('substrapp:algo-description', args=[instance.pk]), 'permissions': {'process': { 'public': permissions.get('public'), 'authorizedIDs': permissions.get('authorized_ids'), diff --git a/backend/substrapp/serializers/ledger/compositealgo/serializer.py b/backend/substrapp/serializers/ledger/compositealgo/serializer.py index d1ba44b46..f0df46c33 100644 --- a/backend/substrapp/serializers/ledger/compositealgo/serializer.py +++ b/backend/substrapp/serializers/ledger/compositealgo/serializer.py @@ -19,20 +19,14 @@ def create(self, validated_data): permissions = validated_data.get('permissions') # TODO, create a datamigration with new Site domain name when we will know the name of the final website - host = '' - protocol = 'http://' - request = self.context.get('request', None) - - if request: - protocol = 'https://' if request.is_secure() else 'http://' - host = request.get_host() + current_site = getattr(settings, "DEFAULT_DOMAIN") args = { 'name': name, 'hash': get_hash(instance.file), - 'storageAddress': protocol + host + reverse('substrapp:composite_algo-file', args=[instance.pk]), + 'storageAddress': current_site + reverse('substrapp:composite_algo-file', args=[instance.pk]), 'descriptionHash': get_hash(instance.description), - 'descriptionStorageAddress': protocol + host + reverse( + 'descriptionStorageAddress': current_site + reverse( 'substrapp:composite_algo-description', args=[instance.pk]), 'permissions': {'process': { 'public': permissions.get('public'), diff --git a/backend/substrapp/serializers/ledger/datamanager/serializer.py b/backend/substrapp/serializers/ledger/datamanager/serializer.py index 3d9f87beb..95d333e2b 100644 --- a/backend/substrapp/serializers/ledger/datamanager/serializer.py +++ b/backend/substrapp/serializers/ledger/datamanager/serializer.py @@ -23,22 +23,16 @@ def create(self, validated_data): objective_key = validated_data.get('objective_key', '') # TODO, create a datamigration with new Site domain name when we will know the name of the final website - host = '' - protocol = 'http://' - request = self.context.get('request', None) - - if request: - protocol = 'https://' if request.is_secure() else 'http://' - host = request.get_host() + current_site = getattr(settings, "DEFAULT_DOMAIN") args = { 'name': name, 'openerHash': get_hash(instance.data_opener), - 'openerStorageAddress': protocol + host + reverse('substrapp:data_manager-opener', args=[instance.pk]), + 'openerStorageAddress': current_site + reverse('substrapp:data_manager-opener', args=[instance.pk]), 'type': data_type, 'descriptionHash': get_hash(instance.description), - 'descriptionStorageAddress': protocol + host + reverse('substrapp:data_manager-description', - args=[instance.pk]), + 'descriptionStorageAddress': current_site + reverse('substrapp:data_manager-description', + args=[instance.pk]), 'objectiveKey': objective_key, 'permissions': {'process': { 'public': permissions.get('public'), diff --git a/backend/substrapp/serializers/ledger/objective/serializer.py b/backend/substrapp/serializers/ledger/objective/serializer.py index f21862456..16eeafd45 100644 --- a/backend/substrapp/serializers/ledger/objective/serializer.py +++ b/backend/substrapp/serializers/ledger/objective/serializer.py @@ -27,21 +27,15 @@ def create(self, validated_data): test_data_sample_keys = validated_data.get('test_data_sample_keys', []) # TODO, create a datamigration with new Site domain name when we will know the name of the final website - host = '' - protocol = 'http://' - request = self.context.get('request', None) - - if request: - protocol = 'https://' if request.is_secure() else 'http://' - host = request.get_host() + current_site = getattr(settings, "DEFAULT_DOMAIN") args = { 'name': name, 'descriptionHash': get_hash(instance.description), - 'descriptionStorageAddress': protocol + host + reverse('substrapp:objective-description', args=[instance.pk]), # noqa + 'descriptionStorageAddress': current_site + reverse('substrapp:objective-description', args=[instance.pk]), # noqa 'metricsName': metrics_name, 'metricsHash': get_hash(instance.metrics), - 'metricsStorageAddress': protocol + host + reverse('substrapp:objective-metrics', args=[instance.pk]), + 'metricsStorageAddress': current_site + reverse('substrapp:objective-metrics', args=[instance.pk]), 'testDataset': { 'dataManagerKey': test_data_manager_key, 'dataSampleKeys': test_data_sample_keys, diff --git a/backend/substrapp/tests/query/tests_query_algo.py b/backend/substrapp/tests/query/tests_query_algo.py index fa98326be..50f01b9ed 100644 --- a/backend/substrapp/tests/query/tests_query_algo.py +++ b/backend/substrapp/tests/query/tests_query_algo.py @@ -26,6 +26,7 @@ @override_settings(MEDIA_ROOT=MEDIA_ROOT) @override_settings(LEDGER={'name': 'test-org', 'peer': 'test-peer'}) @override_settings(LEDGER_SYNC_ENABLED=True) +@override_settings(DEFAULT_DOMAIN='http://testserver') class AlgoQueryTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/substrapp/tests/query/tests_query_datamanager.py b/backend/substrapp/tests/query/tests_query_datamanager.py index 1282eab31..0fa166b72 100644 --- a/backend/substrapp/tests/query/tests_query_datamanager.py +++ b/backend/substrapp/tests/query/tests_query_datamanager.py @@ -21,6 +21,7 @@ @override_settings(MEDIA_ROOT=MEDIA_ROOT) @override_settings(LEDGER={'name': 'test-org', 'peer': 'test-peer'}) @override_settings(LEDGER_SYNC_ENABLED=True) +@override_settings(DEFAULT_DOMAIN='http://testserver') class DataManagerQueryTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/substrapp/tests/query/tests_query_datasample.py b/backend/substrapp/tests/query/tests_query_datasample.py index 83e8d8fa9..32fabb4df 100644 --- a/backend/substrapp/tests/query/tests_query_datasample.py +++ b/backend/substrapp/tests/query/tests_query_datasample.py @@ -30,6 +30,7 @@ @override_settings(MEDIA_ROOT=MEDIA_ROOT) @override_settings(LEDGER={'name': 'test-org', 'peer': 'test-peer'}) @override_settings(LEDGER_SYNC_ENABLED=True) +@override_settings(DEFAULT_DOMAIN='http://testserver') class DataSampleQueryTests(APITestCase): client_class = AuthenticatedClient diff --git a/backend/substrapp/tests/query/tests_query_objective.py b/backend/substrapp/tests/query/tests_query_objective.py index c61bdc80c..1cc731661 100644 --- a/backend/substrapp/tests/query/tests_query_objective.py +++ b/backend/substrapp/tests/query/tests_query_objective.py @@ -23,6 +23,7 @@ @override_settings(MEDIA_ROOT=MEDIA_ROOT) @override_settings(LEDGER={'name': 'test-org', 'peer': 'test-peer'}) @override_settings(LEDGER_SYNC_ENABLED=True) +@override_settings(DEFAULT_DOMAIN='http://testserver') class ObjectiveQueryTests(APITestCase): client_class = AuthenticatedClient