Skip to content

Commit

Permalink
Use proper version when reversing odata URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
esoergel committed Oct 21, 2024
1 parent 30b6e86 commit 75b74af
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions corehq/apps/api/odata/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ def to_json(self, data, options=None):
domain = data.pop('domain', None)
config_id = data.pop('config_id', None)
api_path = data.pop('api_path', None)
api_version = data.pop('api_version', None)
table_id = data.pop('table_id', None)

assert all([domain, config_id, api_path]), [domain, config_id, api_path]
assert all([domain, config_id, api_path, api_version]), \
[domain, config_id, api_path, api_version]

context_urlname = self.metadata_url
context_url_args = [domain, config_id]
context_url_args = [domain, api_version, config_id]
if table_id > 0:
context_urlname = self.table_metadata_url
context_url_args.append(table_id)
Expand Down
8 changes: 4 additions & 4 deletions corehq/apps/api/odata/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ class ODataCaseServiceView(BaseODataView):
urlname = 'odata_case_service_from_export_instance'
table_urlname = 'odata_case_service_from_export_instance_table'

def get(self, request, domain, config_id, **kwargs):
def get(self, request, domain, api_version, config_id, **kwargs):
table_id = int(kwargs.get('table_id', 0))
config = get_document_or_404(CaseExportInstance, domain, config_id)
if raise_odata_permissions_issues(request.couch_user, domain, config):
raise Http404()
urlname = ODataCaseMetadataView.urlname
url_args = [domain, config_id]
url_args = [domain, api_version, config_id]
if table_id > 0:
urlname = ODataCaseMetadataView.table_urlname
url_args.append(table_id)
Expand Down Expand Up @@ -126,13 +126,13 @@ class ODataFormServiceView(BaseODataView):
urlname = 'odata_form_service_from_export_instance'
table_urlname = 'odata_form_service_from_export_instance_table'

def get(self, request, domain, config_id, **kwargs):
def get(self, request, domain, api_version, config_id, **kwargs):
table_id = int(kwargs.get('table_id', 0))
config = get_document_or_404(FormExportInstance, domain, config_id)
if raise_odata_permissions_issues(request.couch_user, domain, config):
raise Http404()
urlname = ODataFormMetadataView.urlname
url_args = [domain, config_id]
url_args = [domain, api_version, config_id]
if table_id > 0:
urlname = ODataFormMetadataView.table_urlname
url_args.append(table_id)
Expand Down
1 change: 1 addition & 0 deletions corehq/apps/api/resources/v0_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ def create_response(self, request, data, response_class=HttpResponse,
**response_kwargs):
data['domain'] = request.domain
data['api_path'] = request.path
data['api_version'] = self.api_name
# Avoids storing these properties on the class instance which protects against the possibility of
# concurrent requests making conflicting updates to properties
data['config_id'] = request.resolver_match.kwargs['config_id']
Expand Down
4 changes: 2 additions & 2 deletions corehq/apps/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def versioned_apis(api_list):


urlpatterns = [
path('v0.5/odata/', include(odata_urlpatterns)),
path('odata/v1/', include(odata_urlpatterns)),
url(r'(?P<api_version>v0.5)/odata/', include(odata_urlpatterns)),
url(r'odata/(?P<api_version>v1)/', include(odata_urlpatterns)),
url(r'(?P<api_version>v0.5)/messaging-event/$',
messaging_events, name="api_messaging_event_list"),
url(r'(?P<api_version>v0.5)/messaging-event/(?P<event_id>\d+)/$',
Expand Down

0 comments on commit 75b74af

Please sign in to comment.