Skip to content

Commit cf76bda

Browse files
authored
Merge pull request #58 from SubstraFoundation/fix-backend-domain
Fix backend domain name from dynamic to static
2 parents b2a13ac + cd9ed36 commit cf76bda

9 files changed

Lines changed: 20 additions & 46 deletions

File tree

backend/substrapp/serializers/ledger/aggregatealgo/serializer.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@ def create(self, validated_data):
1919
permissions = validated_data.get('permissions')
2020

2121
# TODO, create a datamigration with new Site domain name when we will know the name of the final website
22-
host = ''
23-
protocol = 'http://'
24-
request = self.context.get('request', None)
25-
26-
if request:
27-
protocol = 'https://' if request.is_secure() else 'http://'
28-
host = request.get_host()
22+
current_site = getattr(settings, "DEFAULT_DOMAIN")
2923

3024
args = {
3125
'name': name,
3226
'hash': get_hash(instance.file),
33-
'storageAddress': protocol + host + reverse('substrapp:aggregate_algo-file', args=[instance.pk]),
27+
'storageAddress': current_site + reverse('substrapp:aggregate_algo-file', args=[instance.pk]),
3428
'descriptionHash': get_hash(instance.description),
35-
'descriptionStorageAddress': protocol + host + reverse(
29+
'descriptionStorageAddress': current_site + reverse(
3630
'substrapp:aggregate_algo-description', args=[instance.pk]),
3731
'permissions': {'process': {
3832
'public': permissions.get('public'),

backend/substrapp/serializers/ledger/algo/serializer.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@ def create(self, validated_data):
1919
permissions = validated_data.get('permissions')
2020

2121
# TODO, create a datamigration with new Site domain name when we will know the name of the final website
22-
host = ''
23-
protocol = 'http://'
24-
request = self.context.get('request', None)
25-
26-
if request:
27-
protocol = 'https://' if request.is_secure() else 'http://'
28-
host = request.get_host()
22+
current_site = getattr(settings, "DEFAULT_DOMAIN")
2923

3024
args = {
3125
'name': name,
3226
'hash': get_hash(instance.file),
33-
'storageAddress': protocol + host + reverse('substrapp:algo-file', args=[instance.pk]),
27+
'storageAddress': current_site + reverse('substrapp:algo-file', args=[instance.pk]),
3428
'descriptionHash': get_hash(instance.description),
35-
'descriptionStorageAddress': protocol + host + reverse('substrapp:algo-description', args=[instance.pk]),
29+
'descriptionStorageAddress': current_site + reverse('substrapp:algo-description', args=[instance.pk]),
3630
'permissions': {'process': {
3731
'public': permissions.get('public'),
3832
'authorizedIDs': permissions.get('authorized_ids'),

backend/substrapp/serializers/ledger/compositealgo/serializer.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@ def create(self, validated_data):
1919
permissions = validated_data.get('permissions')
2020

2121
# TODO, create a datamigration with new Site domain name when we will know the name of the final website
22-
host = ''
23-
protocol = 'http://'
24-
request = self.context.get('request', None)
25-
26-
if request:
27-
protocol = 'https://' if request.is_secure() else 'http://'
28-
host = request.get_host()
22+
current_site = getattr(settings, "DEFAULT_DOMAIN")
2923

3024
args = {
3125
'name': name,
3226
'hash': get_hash(instance.file),
33-
'storageAddress': protocol + host + reverse('substrapp:composite_algo-file', args=[instance.pk]),
27+
'storageAddress': current_site + reverse('substrapp:composite_algo-file', args=[instance.pk]),
3428
'descriptionHash': get_hash(instance.description),
35-
'descriptionStorageAddress': protocol + host + reverse(
29+
'descriptionStorageAddress': current_site + reverse(
3630
'substrapp:composite_algo-description', args=[instance.pk]),
3731
'permissions': {'process': {
3832
'public': permissions.get('public'),

backend/substrapp/serializers/ledger/datamanager/serializer.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,16 @@ def create(self, validated_data):
2323
objective_key = validated_data.get('objective_key', '')
2424

2525
# TODO, create a datamigration with new Site domain name when we will know the name of the final website
26-
host = ''
27-
protocol = 'http://'
28-
request = self.context.get('request', None)
29-
30-
if request:
31-
protocol = 'https://' if request.is_secure() else 'http://'
32-
host = request.get_host()
26+
current_site = getattr(settings, "DEFAULT_DOMAIN")
3327

3428
args = {
3529
'name': name,
3630
'openerHash': get_hash(instance.data_opener),
37-
'openerStorageAddress': protocol + host + reverse('substrapp:data_manager-opener', args=[instance.pk]),
31+
'openerStorageAddress': current_site + reverse('substrapp:data_manager-opener', args=[instance.pk]),
3832
'type': data_type,
3933
'descriptionHash': get_hash(instance.description),
40-
'descriptionStorageAddress': protocol + host + reverse('substrapp:data_manager-description',
41-
args=[instance.pk]),
34+
'descriptionStorageAddress': current_site + reverse('substrapp:data_manager-description',
35+
args=[instance.pk]),
4236
'objectiveKey': objective_key,
4337
'permissions': {'process': {
4438
'public': permissions.get('public'),

backend/substrapp/serializers/ledger/objective/serializer.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,15 @@ def create(self, validated_data):
2727
test_data_sample_keys = validated_data.get('test_data_sample_keys', [])
2828

2929
# TODO, create a datamigration with new Site domain name when we will know the name of the final website
30-
host = ''
31-
protocol = 'http://'
32-
request = self.context.get('request', None)
33-
34-
if request:
35-
protocol = 'https://' if request.is_secure() else 'http://'
36-
host = request.get_host()
30+
current_site = getattr(settings, "DEFAULT_DOMAIN")
3731

3832
args = {
3933
'name': name,
4034
'descriptionHash': get_hash(instance.description),
41-
'descriptionStorageAddress': protocol + host + reverse('substrapp:objective-description', args=[instance.pk]), # noqa
35+
'descriptionStorageAddress': current_site + reverse('substrapp:objective-description', args=[instance.pk]), # noqa
4236
'metricsName': metrics_name,
4337
'metricsHash': get_hash(instance.metrics),
44-
'metricsStorageAddress': protocol + host + reverse('substrapp:objective-metrics', args=[instance.pk]),
38+
'metricsStorageAddress': current_site + reverse('substrapp:objective-metrics', args=[instance.pk]),
4539
'testDataset': {
4640
'dataManagerKey': test_data_manager_key,
4741
'dataSampleKeys': test_data_sample_keys,

backend/substrapp/tests/query/tests_query_algo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@override_settings(MEDIA_ROOT=MEDIA_ROOT)
2727
@override_settings(LEDGER={'name': 'test-org', 'peer': 'test-peer'})
2828
@override_settings(LEDGER_SYNC_ENABLED=True)
29+
@override_settings(DEFAULT_DOMAIN='http://testserver')
2930
class AlgoQueryTests(APITestCase):
3031
client_class = AuthenticatedClient
3132

backend/substrapp/tests/query/tests_query_datamanager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
@override_settings(MEDIA_ROOT=MEDIA_ROOT)
2222
@override_settings(LEDGER={'name': 'test-org', 'peer': 'test-peer'})
2323
@override_settings(LEDGER_SYNC_ENABLED=True)
24+
@override_settings(DEFAULT_DOMAIN='http://testserver')
2425
class DataManagerQueryTests(APITestCase):
2526
client_class = AuthenticatedClient
2627

backend/substrapp/tests/query/tests_query_datasample.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
@override_settings(MEDIA_ROOT=MEDIA_ROOT)
3131
@override_settings(LEDGER={'name': 'test-org', 'peer': 'test-peer'})
3232
@override_settings(LEDGER_SYNC_ENABLED=True)
33+
@override_settings(DEFAULT_DOMAIN='http://testserver')
3334
class DataSampleQueryTests(APITestCase):
3435
client_class = AuthenticatedClient
3536

backend/substrapp/tests/query/tests_query_objective.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
@override_settings(MEDIA_ROOT=MEDIA_ROOT)
2424
@override_settings(LEDGER={'name': 'test-org', 'peer': 'test-peer'})
2525
@override_settings(LEDGER_SYNC_ENABLED=True)
26+
@override_settings(DEFAULT_DOMAIN='http://testserver')
2627
class ObjectiveQueryTests(APITestCase):
2728
client_class = AuthenticatedClient
2829

0 commit comments

Comments
 (0)