Skip to content

Commit dc9bdda

Browse files
committed
OpenConceptLab/ocl_issues#2030 FHIR endpoints must be handled with or without trailing slash
1 parent fc90744 commit dc9bdda

File tree

11 files changed

+30
-8
lines changed

11 files changed

+30
-8
lines changed

core/code_systems/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def to_representation(self, instance):
280280

281281
def create(self, validated_data):
282282
concepts = validated_data.pop('concepts', [])
283-
uri = self.context['request'].path + validated_data['mnemonic']
283+
uri = '/'.join([self.context['request'].path.rstrip('/'), validated_data['mnemonic']])
284284
ident = IdentifierSerializer.include_ocl_identifier(uri, RESOURCE_TYPE, validated_data)
285285
source = SourceCreateOrUpdateSerializer().prepare_object(validated_data)
286286

core/code_systems/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ def test_put_code_system_without_concepts(self):
345345
@patch('core.sources.models.index_source_mappings', Mock(__name__='index_source_mappings'))
346346
def test_post_code_system_with_concepts(self):
347347
response = self.client.post(
348-
f'/users/{self.user.mnemonic}/CodeSystem/',
348+
f'/users/{self.user.mnemonic}/CodeSystem',
349349
HTTP_AUTHORIZATION='Token ' + self.user_token,
350350
data={
351351
'url': 'http://localhost/url',

core/code_systems/urls.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
urlpatterns = [
66
path('', views.CodeSystemListView.as_view(), name='code-system-list'),
77
path('$lookup/', views.CodeSystemListLookupView.as_view(), name='code-system-list-lookup'),
8+
path('$lookup', views.CodeSystemListLookupView.as_view(), name='code-system-list-lookup_no_slash'),
89
path('$validate-code/', views.CodeSystemValidateCodeView.as_view(), name='code-system-validate-code'),
9-
path("<str:source>/", views.CodeSystemRetrieveUpdateView.as_view(), name='code-system-detail')
10+
path('$validate-code', views.CodeSystemValidateCodeView.as_view(), name='code-system-validate-code_no_slash'),
11+
path("<str:source>/", views.CodeSystemRetrieveUpdateView.as_view(), name='code-system-detail'),
12+
path("<str:source>", views.CodeSystemRetrieveUpdateView.as_view(), name='code-system-detail_no_slash'),
1013
]

core/code_systems/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class CodeSystemListLookupView(ConceptRetrieveUpdateDestroyView):
7777
def is_container_version_specified(self):
7878
return True
7979

80+
def verify_scope(self):
81+
pass
82+
8083
def get_queryset(self):
8184
queryset = super().get_queryset()
8285
code = self.request.query_params.get('code')

core/concept_maps/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def to_representation(self, instance):
156156

157157
def create(self, validated_data):
158158
mappings = validated_data.pop('mappings', [])
159-
uri = self.context['request'].path + validated_data['mnemonic']
159+
uri = '/'.join([self.context['request'].path.rstrip('/'), validated_data['mnemonic']])
160160
ident = IdentifierSerializer.include_ocl_identifier(uri, RESOURCE_TYPE, validated_data)
161161
source = SourceCreateOrUpdateSerializer().prepare_object(validated_data)
162162

core/concept_maps/urls.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
urlpatterns = [
66
path('', views.ConceptMapListView.as_view(), name='concept-map-list'),
7-
path('$translate', views.ConceptMapTranslateView.as_view(), name='concept-map-list-translate'),
8-
path("<str:source>/", views.ConceptMapRetrieveUpdateView.as_view(), name='concept-map-detail')
7+
path('$translate/', views.ConceptMapTranslateView.as_view(), name='concept-map-list-translate'),
8+
path('$translate', views.ConceptMapTranslateView.as_view(), name='concept-map-list-translate_no_slash'),
9+
path("<str:source>/", views.ConceptMapRetrieveUpdateView.as_view(), name='concept-map-detail'),
10+
path("<str:source>", views.ConceptMapRetrieveUpdateView.as_view(), name='concept-map-detail_no_slash')
911
]

core/orgs/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
path('<str:org>/repos/', include('core.repos.urls'), name='org-repos-urls'),
2323
path('<str:org>/sources/', include('core.sources.urls')),
2424
path('<str:org>/CodeSystem/', include('core.code_systems.urls'), name='code_systems_urls'),
25+
path('<str:org>/CodeSystem', include('core.code_systems.urls'), name='code_systems_urls_no_slash'),
2526
path('<str:org>/ValueSet/', include('core.value_sets.urls'), name='value_sets_urls'),
27+
path('<str:org>/ValueSet', include('core.value_sets.urls'), name='value_sets_urls_no_slash'),
2628
path('<str:org>/ConceptMap/', include('core.concept_maps.urls'), name='concept_maps_urls'),
29+
path('<str:org>/ConceptMap', include('core.concept_maps.urls'), name='concept_maps_urls_no_slash'),
2730
path('<str:org>/collections/', include('core.collections.urls')),
2831
path('<str:org>/pins/', include('core.pins.urls')),
2932
path('<str:org>/events/', include('core.events.urls')),

core/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@
7272
# TODO: require FHIR subdomain
7373
path('fhir/', include('core.fhir.urls'), name='fhir_urls'),
7474
path('fhir/CodeSystem/', include('core.code_systems.urls'), name='code_systems_urls'),
75+
path('fhir/CodeSystem', include('core.code_systems.urls'), name='code_systems_urls_no_slash'),
7576
path('fhir/ValueSet/', include('core.value_sets.urls'), name='value_sets_urls'),
77+
path('fhir/ValueSet', include('core.value_sets.urls'), name='value_sets_urls_no_slash'),
7678
path('fhir/ConceptMap/', include('core.concept_maps.urls'), name='concept_maps_urls'),
79+
path('fhir/ConceptMap', include('core.concept_maps.urls'), name='concept_maps_urls_no_slash'),
7780

7881
path('collections/', include('core.collections.urls'), name='collections_urls'),
7982
path('concepts/', concept_views.ConceptListView.as_view(), name='all_concepts_urls'),

core/users/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848

4949
# TODO: require FHIR subdomain
5050
path('<str:user>/CodeSystem/', include('core.code_systems.urls'), name='code_systems_urls'),
51+
path('<str:user>/CodeSystem', include('core.code_systems.urls'), name='code_systems_urls_no_slash'),
5152
path('<str:user>/ValueSet/', include('core.value_sets.urls'), name='value_sets_urls'),
53+
path('<str:user>/ValueSet', include('core.value_sets.urls'), name='value_sets_urls_no_slash'),
5254
path('<str:user>/ConceptMap/', include('core.concept_maps.urls'), name='concept_maps_urls'),
55+
path('<str:user>/ConceptMap', include('core.concept_maps.urls'), name='concept_maps_urls_no_slash'),
5356
]

core/value_sets/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class Meta:
165165
'immutable', 'text', 'compose')
166166

167167
def create(self, validated_data):
168-
uri = self.context['request'].path + validated_data['mnemonic']
168+
uri = '/'.join([self.context['request'].path.rstrip('/'), validated_data['mnemonic']])
169169
ident = IdentifierSerializer.include_ocl_identifier(uri, RESOURCE_TYPE, validated_data)
170170
collection = CollectionCreateOrUpdateSerializer().prepare_object(validated_data)
171171
collection_version = collection.version if collection.version != HEAD else '0.1'

0 commit comments

Comments
 (0)