Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions api/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ def get_preprint(self, check_object_permissions=True, ignore_404=False):
sentry.log_message(f'Preprint deleted: [guid={base_guid_id}, version={preprint_version}]')
raise NotFound

# May raise a permission denied
if check_object_permissions:
self.check_object_permissions(self.request, preprint)

user = self.request.user
if isinstance(user, AnonymousUser):
user_is_reviewer = user_is_contributor = False
Expand All @@ -162,8 +158,15 @@ def get_preprint(self, check_object_permissions=True, ignore_404=False):
raise PermissionDenied(
detail='This preprint is pending moderation and is not yet publicly available.',
)
# May raise a permission denied
if check_object_permissions:
self.check_object_permissions(self.request, preprint)
raise NotFound

# May raise a permission denied
if check_object_permissions:
self.check_object_permissions(self.request, preprint)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it's better to leave it where it was in order to not break current behavior

Copy link
Contributor Author

@mkovalua mkovalua Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is needed to implement the following workflow and behaviour described in the ticket

image

return preprint

class PreprintList(PreprintMetricsViewMixin, JSONAPIBaseView, generics.ListCreateAPIView, PreprintFilterMixin):
Expand Down
4 changes: 2 additions & 2 deletions api_tests/preprints/views/test_preprint_detail_reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_reviews_preprint_is_published_detail(

# test_unpublished_invisible_to_public
res = app.get(unpublished_url, expect_errors=True)
assert res.status_code == 401
assert res.status_code == 403

def test_reviews_preprint_initial_detail(
self, app, admin, write_contrib, non_contrib,
Expand Down Expand Up @@ -167,4 +167,4 @@ def test_reviews_preprint_is_public_detail(

# test_private_invisible_to_public
res = app.get(private_url, expect_errors=True)
assert res.status_code == 401
assert res.status_code == 403
11 changes: 11 additions & 0 deletions api_tests/preprints/views/test_preprint_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,17 @@ def test_unpublished_visible_to_write_contribs(
res = app.get(detail_url, auth=user_write_contrib.auth, expect_errors=True)
assert res.json['data']['id'] == preprint_unpublished._id

def test_unpublished_invisible_to_public(
self, app, preprint_unpublished, preprint_published,
list_url, detail_url):
res = app.get(list_url)
assert len(res.json['data']) == 1
assert preprint_unpublished._id not in [
d['id'] for d in res.json['data']]

res = app.get(detail_url, expect_errors=True)
assert res.status_code == 403


class TestPreprintIsValidList(PreprintIsValidListMixin):

Expand Down