Skip to content

Commit

Permalink
add self link and view for preprint subjects relationship
Browse files Browse the repository at this point in the history
  • Loading branch information
adlius committed May 16, 2024
1 parent 3448bba commit 4ce0b5b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions api/preprints/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']})

Expand Down
1 change: 1 addition & 0 deletions api/preprints/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
re_path(r'^(?P<preprint_id>\w+)/files/osfstorage/$', views.PreprintFilesList.as_view(), name=views.PreprintFilesList.view_name),
re_path(r'^(?P<preprint_id>\w+)/identifiers/$', views.PreprintIdentifierList.as_view(), name=views.PreprintIdentifierList.view_name),
re_path(r'^(?P<preprint_id>\w+)/relationships/node/$', views.PreprintNodeRelationship.as_view(), name=views.PreprintNodeRelationship.view_name),
re_path(r'^(?P<preprint_id>\w+)/relationships/subjects/$', views.PreprintSubjectsRelationship.as_view(), name=views.PreprintSubjectsRelationship.view_name),
re_path(r'^(?P<preprint_id>\w+)/review_actions/$', views.PreprintActionList.as_view(), name=views.PreprintActionList.view_name),
re_path(r'^(?P<preprint_id>\w+)/requests/$', views.PreprintRequestListCreate.as_view(), name=views.PreprintRequestListCreate.view_name),
re_path(r'^(?P<preprint_id>\w+)/subjects/$', views.PreprintSubjectsList.as_view(), name=views.PreprintSubjectsList.view_name),
Expand Down
21 changes: 20 additions & 1 deletion api/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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*
Expand Down

0 comments on commit 4ce0b5b

Please sign in to comment.