Skip to content

[ENG-12508] exclude preprints relationship for AVOL and return 403 on direct fetch - #11991

Open
ihorsokhanexoft wants to merge 3 commits into
CenterForOpenScience:feature/pbs-26-20from
ihorsokhanexoft:fix/ENG-12508
Open

ihorsokhanexoft wants to merge 3 commits into
CenterForOpenScience:feature/pbs-26-20from
ihorsokhanexoft:fix/ENG-12508

Conversation

@ihorsokhanexoft

Copy link
Copy Markdown
Contributor

Ticket

https://openscience.atlassian.net/browse/ENG-12508

Purpose

User can access node preprints when uses AVOL

Changes

Hide preprints relationship on node data fetch when AVOL is used. v2/nodes/<guid>/
Raise 403 on v2/nodes/<guid>/preprints/ when AVOL is used

@adlius adlius left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we can achieve the same functionality in a different existing way.

Comment thread api/base/serializers.py Outdated
return not isinstance(self.field, RelationshipField)


class HideIfViewOnlyLink(ConditionalField):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we had similar functionalities before. Could you check the non_anonymized_fields list defined in NodeSerializer and see if removing the preprint from that would work?

@ihorsokhanexoft ihorsokhanexoft Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@adlius we should remove preprints relationship only when AVOL is used. Removing preprints from non_anonymized_fields will remove property from response regardless of AVOL is used or not

@adlius adlius left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two nit picks. LGTM otherwise.

Comment thread api/nodes/views.py Outdated
return self.preprints_queryset(node.preprints.all(), auth_user, latest_only=True)

def get_queryset(self):
if self.request.query_params.get('view_only'):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

One more thing: can we use is_anonymized() to check the request here is instead of just looking at whether there is a URL query param?

assert set(expected) == set(actual)

def test_view_only_link_cannot_fetch_node_preprints(self, app, project_one):
view_only_link = PrivateLinkFactory()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should this be anonymous=True?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants