From 4ce0b5bccdcbd900689a005a37bd97e481166f43 Mon Sep 17 00:00:00 2001 From: Yuhuai Liu Date: Thu, 16 May 2024 11:35:36 -0400 Subject: [PATCH] add self link and view for preprint subjects relationship --- api/preprints/serializers.py | 5 +++++ api/preprints/urls.py | 1 + api/preprints/views.py | 21 ++++++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/api/preprints/serializers.py b/api/preprints/serializers.py index 6a00e581f4d..0e7f7724171 100644 --- a/api/preprints/serializers.py +++ b/api/preprints/serializers.py @@ -222,6 +222,11 @@ def subjects_view_kwargs(self): # Overrides TaxonomizableSerializerMixin return {'preprint_id': '<_id>'} + @property + def subjects_self_view(self): + # Overrides TaxonomizableSerializerMixin + return 'preprints:preprint-relationships-subjects' + def get_preprint_url(self, obj): return absolute_reverse('preprints:preprint-detail', kwargs={'preprint_id': obj._id, 'version': self.context['request'].parser_context['kwargs']['version']}) diff --git a/api/preprints/urls.py b/api/preprints/urls.py index 70c72d991f6..c8b48e6b1cd 100644 --- a/api/preprints/urls.py +++ b/api/preprints/urls.py @@ -16,6 +16,7 @@ re_path(r'^(?P\w+)/files/osfstorage/$', views.PreprintFilesList.as_view(), name=views.PreprintFilesList.view_name), re_path(r'^(?P\w+)/identifiers/$', views.PreprintIdentifierList.as_view(), name=views.PreprintIdentifierList.view_name), re_path(r'^(?P\w+)/relationships/node/$', views.PreprintNodeRelationship.as_view(), name=views.PreprintNodeRelationship.view_name), + re_path(r'^(?P\w+)/relationships/subjects/$', views.PreprintSubjectsRelationship.as_view(), name=views.PreprintSubjectsRelationship.view_name), re_path(r'^(?P\w+)/review_actions/$', views.PreprintActionList.as_view(), name=views.PreprintActionList.view_name), re_path(r'^(?P\w+)/requests/$', views.PreprintRequestListCreate.as_view(), name=views.PreprintRequestListCreate.view_name), re_path(r'^(?P\w+)/subjects/$', views.PreprintSubjectsList.as_view(), name=views.PreprintSubjectsList.view_name), diff --git a/api/preprints/views.py b/api/preprints/views.py index 08df330c7db..4cfa6f51e0a 100644 --- a/api/preprints/views.py +++ b/api/preprints/views.py @@ -58,7 +58,7 @@ from api.requests.permissions import PreprintRequestPermission from api.requests.serializers import PreprintRequestSerializer, PreprintRequestCreateSerializer from api.requests.views import PreprintRequestMixin -from api.subjects.views import BaseResourceSubjectsList +from api.subjects.views import BaseResourceSubjectsList, SubjectRelationshipBaseView from api.base.metrics import PreprintMetricsViewMixin from osf.metrics import PreprintDownload, PreprintView @@ -456,6 +456,25 @@ class PreprintSubjectsList(BaseResourceSubjectsList, PreprintMixin): def get_resource(self): return self.get_preprint() +class PreprintSubjectsRelationship(SubjectRelationshipBaseView, PreprintMixin): + """The documentation for this endpoint can be found [here](https://developer.osf.io/#operation/preprint_subjects_list). + """ + permission_classes = ( + drf_permissions.IsAuthenticatedOrReadOnly, + base_permissions.TokenHasScope, + ModeratorIfNeverPublicWithdrawn, + ContributorOrPublic, + PreprintPublishedOrWrite, + ) + + required_read_scopes = [CoreScopes.PREPRINTS_READ] + + view_category = 'preprints' + view_name = 'preprint-relationships-subjects' + + def get_resource(self, check_object_permissions=True): + return self.get_preprint(check_object_permissions=check_object_permissions) + class PreprintActionList(JSONAPIBaseView, generics.ListCreateAPIView, ListFilterMixin, PreprintMixin): """Action List *Read-only*