diff --git a/api/files/serializers.py b/api/files/serializers.py index 9e92bca2037..3e2569f9693 100644 --- a/api/files/serializers.py +++ b/api/files/serializers.py @@ -47,7 +47,7 @@ ShowIfVersion, ) from api.base.utils import absolute_reverse, get_user_auth -from api.base.exceptions import Conflict +from api.base.exceptions import Conflict, JSONAPIException from api.base.versioning import get_kebab_snake_case_field class CheckoutField(ser.HyperlinkedRelatedField): @@ -370,6 +370,13 @@ def get_file_guid(self, obj): return guid._id return None + def get_file_guid_or_error(self, obj): + if obj: + guid = obj.get_guid() + if guid: + return guid._id + raise JSONAPIException + def get_absolute_url(self, obj): return api_v2_url('files/{}/'.format(obj._id)) @@ -395,7 +402,7 @@ class FileSerializer(BaseFileSerializer): cedar_metadata_records = RelationshipField( related_view='files:file-cedar-metadata-records-list', - related_view_kwargs={'file_id': '<_id>'}, + related_view_kwargs={'file_guid': 'get_file_guid_or_error'}, ) def get_target_type(self, obj): diff --git a/api/files/urls.py b/api/files/urls.py index 0266e9c2750..3cc32c8f516 100644 --- a/api/files/urls.py +++ b/api/files/urls.py @@ -6,7 +6,7 @@ urlpatterns = [ re_path(r'^(?P\w+)/$', views.FileDetail.as_view(), name=views.FileDetail.view_name), - re_path(r'^(?P\w+)/cedar_metadata_records/$', views.FileCedarMetadataRecordsList.as_view(), name=views.FileCedarMetadataRecordsList.view_name), + re_path(r'^(?P\w+)/cedar_metadata_records/$', views.FileCedarMetadataRecordsList.as_view(), name=views.FileCedarMetadataRecordsList.view_name), re_path(r'^(?P\w+)/versions/$', views.FileVersionsList.as_view(), name=views.FileVersionsList.view_name), re_path(r'^(?P\w+)/versions/(?P\w+)/$', views.FileVersionDetail.as_view(), name=views.FileVersionDetail.view_name), ] diff --git a/api/files/views.py b/api/files/views.py index cbb8e421659..dd084748c84 100644 --- a/api/files/views.py +++ b/api/files/views.py @@ -193,7 +193,7 @@ class FileCedarMetadataRecordsList(JSONAPIBaseView, generics.ListAPIView, ListFi view_name = 'file-cedar-metadata-records-list' def get_default_queryset(self): - return CedarMetadataRecord.objects.filter(guid___id=self.kwargs['file_id']) + return CedarMetadataRecord.objects.filter(guid___id=self.kwargs['file_guid']) def get_queryset(self): return self.get_queryset_from_request()