From 51c728e39ac4fa90ba85ad72132987d624da1357 Mon Sep 17 00:00:00 2001 From: Longze Chen Date: Thu, 9 Jan 2025 15:49:48 -0500 Subject: [PATCH 1/3] Fix preprint edit permission --- api/preprints/views.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/api/preprints/views.py b/api/preprints/views.py index 436249fb0bf..2fa938884b7 100644 --- a/api/preprints/views.py +++ b/api/preprints/views.py @@ -8,10 +8,11 @@ from framework import sentry from framework.auth.oauth_scopes import CoreScopes from osf.models import ( - ReviewAction, + Institution, Preprint, PreprintContributor, - Institution, + ReviewAction, + VersionedGuidMixin, ) from osf.utils.requests import check_select_for_update @@ -76,12 +77,14 @@ class PreprintOldVersionsImmutableMixin: @staticmethod def is_edit_allowed(preprint): - return True if any([ - preprint.is_latest_version, - preprint.machine_state in ['initial', 'rejected'], - preprint.provider.reviews_workflow == Workflows.PRE_MODERATION.value and - preprint.machine_state == 'pending', - ]) else False + if preprint.is_latest_version or preprint.machine_state == 'initial': + return True + if preprint.provider.reviews_workflow == Workflows.PRE_MODERATION.value: + if preprint.machine_state == 'pending': + return True + if preprint.machine_state == 'rejected' and preprint.version == VersionedGuidMixin.INITIAL_VERSION_NUMBER: + return True + return False def handle_request(self, request, method, *args, **kwargs): preprint = self.get_preprint(check_object_permissions=False) From 2a8df888d6f61f07fce24055331712f6082320a1 Mon Sep 17 00:00:00 2001 From: Longze Chen Date: Thu, 9 Jan 2025 15:51:35 -0500 Subject: [PATCH 2/3] Fix preprint contributor --- osf/models/preprint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osf/models/preprint.py b/osf/models/preprint.py index af689522eea..15d8c3c0930 100644 --- a/osf/models/preprint.py +++ b/osf/models/preprint.py @@ -429,7 +429,7 @@ def create_version(cls, create_from_guid, auth): preprint.save(guid_ready=True, first_save=True) # Add contributors - for contributor in latest_version.contributor_set.exclude(user=latest_version.creator): + for contributor in latest_version.contributor_set.exclude(user=preprint.creator): try: preprint.add_contributor( contributor.user, From 96ca301bb2ef6a649ef9f36f373b56791f3fad48 Mon Sep 17 00:00:00 2001 From: Longze Chen Date: Thu, 9 Jan 2025 22:44:05 -0500 Subject: [PATCH 3/3] Fix tests where pending submit is allowed for post-moderation --- api_tests/users/views/test_user_actions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/api_tests/users/views/test_user_actions.py b/api_tests/users/views/test_user_actions.py index 1236f70cc23..568574f5417 100644 --- a/api_tests/users/views/test_user_actions.py +++ b/api_tests/users/views/test_user_actions.py @@ -170,7 +170,6 @@ def test_bad_requests(self, app, url, preprint, provider, moderator): ('initial', 'accept'), ('initial', 'edit_comment'), ('initial', 'reject'), - ('pending', 'submit'), ('rejected', 'reject'), ('rejected', 'submit'), ],