Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-6445] [ENG-6457] Preprints Version Creation and API Implementation - Part 2 #10807

Open
wants to merge 17 commits into
base: feature/preprints-doi-versioning
Choose a base branch
from

Conversation

Ostap-Zherebetskyi
Copy link

@Ostap-Zherebetskyi Ostap-Zherebetskyi commented Nov 21, 2024

Purpose

Preprints Version Creation and API Implementation - Part 2

Changes

  • Implement preprint version creation
  • Implement API endpoints to fetch and create versioned preprints
  • Update Preprint serializer
  • Minor fixes / improvements

QA Notes

N/A

Documentation

N/A

Side Effects

N/A

Ticket

https://openscience.atlassian.net/browse/ENG-6457
https://openscience.atlassian.net/browse/ENG-6445

@cslzchen cslzchen marked this pull request as ready for review November 21, 2024 15:46
@cslzchen cslzchen changed the title Preprints Version Creation and API Implementation - Part 2 [ENG-6445] [ENG-6457] Preprints Version Creation and API Implementation - Part 2 Nov 21, 2024
api/preprints/serializers.py Outdated Show resolved Hide resolved
api/preprints/views.py Outdated Show resolved Hide resolved
framework/exceptions/__init__.py Outdated Show resolved Hide resolved
osf/models/preprint.py Outdated Show resolved Hide resolved
osf/models/preprint.py Outdated Show resolved Hide resolved
osf/models/preprint.py Outdated Show resolved Hide resolved
osf/models/preprint.py Outdated Show resolved Hide resolved
@cslzchen cslzchen self-requested a review November 25, 2024 19:12
Copy link
Collaborator

@cslzchen cslzchen left a comment

Choose a reason for hiding this comment

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

A few last nit-picking suggestions, should be good to go after taking care of them. 🎆

title = ser.CharField(required=False)

dupliate_from_guid = ser.CharField(required=True, write_only=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use create_from_guid, which seems to describe version creation better than duplicate.

try:
preprint, update_data = Preprint.create_version(dupliate_from_guid, auth)
except PendingVersionExists:
raise Conflict(detail='Before creating a new version, you must publish the latest version.')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder for myself: need to check with FE if this detail is surfaced back directly to the user; if so, we need Product to provide the exact language; if not, we may not need to provide the detail.

Comment on lines +168 to +173
# These permissions are not checked for the list of preprints, permissions handled by the query
permission_classes = (
drf_permissions.IsAuthenticatedOrReadOnly,
base_permissions.TokenHasScope,
ContributorOrPublic,
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reminder for myself: it seems neither the create nor the list checks the permission ... if the comment is correct ... need to double check ... I think these are still checked but just not strict enough, which finer-grained access control are done in get_queryset().

Comment on lines 114 to 115
class PendingVersionExists(FrameworkError):
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add docstr to explain what this error is and when it is raised. PendingPreprintVersionExists is a better name too.

Comment on lines +513 to +514
except cls.MultipleObjectsReturned:
return None
Copy link
Collaborator

Choose a reason for hiding this comment

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

Future improvements: let's return None for now, but we may need to add some sentry log to detect this and maybe re-raise the exception afterwards.

Comment on lines 300 to 318
def has_create_version_permission(self, user):
from guardian.shortcuts import get_group_perms
object_type = self.guardian_object_type

if not user or user.is_anonymous:
return False
perm = f'{ADMIN}_{object_type}'
# Using get_group_perms to get permissions that are inferred through
# group membership - not inherited from superuser status
has_permission = perm in get_group_perms(user, self)

return has_permission

@classmethod
def create_version(cls, dupliate_from_guid):
def create_version(cls, dupliate_from_guid, auth):
source_preprint = cls.load(dupliate_from_guid.split(cls.GUID_VERSION_DELIMITER)[0])
if not source_preprint:
raise NotFound
if not source_preprint.has_create_version_permission(auth.user):
Copy link
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 simply use source_preprint.has_permission(auth.user, ADMIN).

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