Skip to content

Commit

Permalink
improve permissions and remove old PreprintInstitutionsList
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Jul 5, 2024
1 parent 3a7bbb0 commit 60bfb27
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 193 deletions.
3 changes: 2 additions & 1 deletion api/base/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from framework.auth.cas import CasResponse

from osf.models import ApiOAuth2Application, ApiOAuth2PersonalToken
from osf.utils import permissions as osf_permissions
from website.util.sanitize import is_iterable_but_not_string
from api.base.utils import get_user_auth

Expand Down Expand Up @@ -170,6 +171,6 @@ def has_object_permission(self, request, view, obj):
if request.method in permissions.SAFE_METHODS:
return resource.is_public or resource.can_view(auth)
else:
return resource.has_permission(auth.user, 'write')
return resource.has_permission(auth.user, osf_permissions.WRITE)


15 changes: 0 additions & 15 deletions api/preprints/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,3 @@ def has_object_permission(self, request, view, obj):
raise exceptions.PermissionDenied(detail='Withdrawn preprints may not be edited')
return True
raise exceptions.NotFound


class PreprintInstitutionPermission(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
if obj.is_public:
return True

auth = get_user_auth(request)
if not auth.user:
return False

if request.method in permissions.SAFE_METHODS:
return obj.has_permission(auth.user, 'read')
else:
return obj.has_permission(auth.user, 'write')
1 change: 0 additions & 1 deletion api/preprints/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
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),
re_path(r'^(?P<preprint_id>\w+)/institutions/$', views.PreprintInstitutionsList.as_view(), name=views.PreprintInstitutionsList.view_name),
re_path(r'^(?P<preprint_id>\w+)/relationships/institutions/$', views.PreprintInstitutionsRelationshipList.as_view(), name=views.PreprintInstitutionsRelationshipList.view_name),
]
30 changes: 1 addition & 29 deletions api/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
PreprintStorageProviderSerializer,
PreprintNodeRelationshipSerializer,
PreprintContributorsCreateSerializer,
PreprintsInstitutionsRelationshipSerializer
PreprintsInstitutionsRelationshipSerializer,
)
from api.files.serializers import OsfStorageFileSerializer
from api.nodes.serializers import (
Expand All @@ -58,7 +58,6 @@
AdminOrPublic,
ContributorDetailPermissions,
PreprintFilesPermissions,
PreprintInstitutionPermission,
)
from api.nodes.permissions import ContributorOrPublic
from api.base.permissions import WriteOrPublicForRelationshipInstitutions
Expand All @@ -68,7 +67,6 @@
from api.subjects.views import BaseResourceSubjectsList
from api.base.metrics import PreprintMetricsViewMixin
from osf.metrics import PreprintDownload, PreprintView
from api.institutions.serializers import InstitutionSerializer


class PreprintMixin(NodeMixin):
Expand Down Expand Up @@ -625,32 +623,6 @@ def get_queryset(self):
return self.get_queryset_from_request()


class PreprintInstitutionsList(JSONAPIBaseView, generics.ListAPIView, ListFilterMixin, PreprintMixin):
"""The documentation for this endpoint can be found [here](https://developer.osf.io/#operation/preprint_institutions_list).
"""
permission_classes = (
drf_permissions.IsAuthenticatedOrReadOnly,
base_permissions.TokenHasScope,
PreprintInstitutionPermission,
)

required_read_scopes = [CoreScopes.PREPRINTS_READ, CoreScopes.INSTITUTION_READ]
required_write_scopes = [CoreScopes.NULL]
serializer_class = InstitutionSerializer

model = Institution
view_category = 'preprints'
view_name = 'preprints-institutions'

ordering = ('-id',)

def get_resource(self):
return self.get_preprint()

def get_queryset(self):
return self.get_resource().affiliated_institutions.all()


class PreprintInstitutionsRelationshipList(JSONAPIBaseView, generics.RetrieveUpdateDestroyAPIView, generics.CreateAPIView, PreprintMixin):
""" """
permission_classes = (
Expand Down
147 changes: 0 additions & 147 deletions api_tests/preprints/views/test_preprint_institutions.py

This file was deleted.

0 comments on commit 60bfb27

Please sign in to comment.