Skip to content

Commit

Permalink
Merge pull request #58 from SubstraFoundation/fix-backend-domain
Browse files Browse the repository at this point in the history
Fix backend domain name from dynamic to static
  • Loading branch information
samlesu authored Dec 6, 2019
2 parents b2a13ac + cd9ed36 commit cf76bda
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 46 deletions.
12 changes: 3 additions & 9 deletions backend/substrapp/serializers/ledger/aggregatealgo/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
12 changes: 3 additions & 9 deletions backend/substrapp/serializers/ledger/algo/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
12 changes: 3 additions & 9 deletions backend/substrapp/serializers/ledger/compositealgo/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
14 changes: 4 additions & 10 deletions backend/substrapp/serializers/ledger/datamanager/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
12 changes: 3 additions & 9 deletions backend/substrapp/serializers/ledger/objective/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions backend/substrapp/tests/query/tests_query_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions backend/substrapp/tests/query/tests_query_datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions backend/substrapp/tests/query/tests_query_datasample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions backend/substrapp/tests/query/tests_query_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cf76bda

Please sign in to comment.