Skip to content

Commit

Permalink
Add new endpoint nodes:node-cedar-metadata-records-list
Browse files Browse the repository at this point in the history
  • Loading branch information
cslzchen committed Jan 24, 2024
1 parent 9d835e4 commit 7003ca4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/nodes/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,11 @@ class NodeSerializer(TaxonomizableSerializerMixin, JSONAPISerializer):
related_view_kwargs={'node_id': '<_id>'},
)

cedar_metadata_records = RelationshipField(
related_view='nodes:node-cedar-metadata-records-list',
related_view_kwargs={'node_id': '<_id>'},
)

@property
def subjects_related_view(self):
# Overrides TaxonomizableSerializerMixin
Expand Down
1 change: 1 addition & 0 deletions api/nodes/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
re_path(r'^(?P<node_id>\w+)/addons/(?P<provider>\w+)/folders/$', views.NodeAddonFolderList.as_view(), name=views.NodeAddonFolderList.view_name),
re_path(r'^(?P<node_id>\w+)/bibliographic_contributors/$', views.NodeBibliographicContributorsList.as_view(), name=views.NodeBibliographicContributorsList.view_name),
re_path(r'^(?P<node_id>\w+)/children/$', views.NodeChildrenList.as_view(), name=views.NodeChildrenList.view_name),
re_path(r'^(?P<node_id>\w+)/cedar_metadata_records/$', views.NodeCedarMetadataRecordList.as_view(), name=views.NodeCedarMetadataRecordList.view_name),
re_path(r'^(?P<node_id>\w+)/citation/$', views.NodeCitationDetail.as_view(), name=views.NodeCitationDetail.view_name),
re_path(r'^(?P<node_id>\w+)/citation/(?P<style_id>[-\w]+)/$', views.NodeCitationStyleDetail.as_view(), name=views.NodeCitationStyleDetail.view_name),
re_path(r'^(?P<node_id>\w+)/comments/$', views.NodeCommentsList.as_view(), name=views.NodeCommentsList.view_name),
Expand Down
26 changes: 26 additions & 0 deletions api/nodes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
WaterButlerMixin,
)
from api.base.waffle_decorators import require_flag
from api.cedar_metadata_records.serializers import CedarMetadataRecordsListSerializer
from api.cedar_metadata_records.permissions import CedarMetadataRecordPermission
from api.citations.utils import render_citation
from api.comments.permissions import CanCommentOrPublic
from api.comments.serializers import (
Expand Down Expand Up @@ -150,6 +152,7 @@
Guid,
File,
Folder,
CedarMetadataRecord,
)
from addons.osfstorage.models import Region
from osf.utils.permissions import ADMIN, WRITE_NODE
Expand Down Expand Up @@ -2285,3 +2288,26 @@ def get_serializer_context(self):
context['wiki_addon'] = node.get_addon('wiki')
context['forward_addon'] = node.get_addon('forward')
return context


class NodeCedarMetadataRecordList(JSONAPIBaseView, generics.ListAPIView, ListFilterMixin):

permission_classes = (
CedarMetadataRecordPermission,
drf_permissions.IsAuthenticatedOrReadOnly,
base_permissions.TokenHasScope,
)
required_read_scopes = [CoreScopes.CEDAR_METADATA_RECORD_READ]
required_write_scopes = [CoreScopes.NULL]

serializer_class = CedarMetadataRecordsListSerializer
parser_classes = (JSONAPIMultipleRelationshipsParser, JSONAPIMultipleRelationshipsParserForRegularJSON, )

view_category = 'nodes'
view_name = 'node-cedar-metadata-records-list'

def get_default_queryset(self):
return CedarMetadataRecord.objects.filter(guid___id=self.kwargs['node_id'])

def get_queryset(self):
return self.get_queryset_from_request()

0 comments on commit 7003ca4

Please sign in to comment.