Skip to content

Commit

Permalink
Merge pull request #10906 from cslzchen/feature/fix-perm-and-contrib
Browse files Browse the repository at this point in the history
[ENG-6815][ENG-6881] Fix missing original admin contributor + Sync BE/FE permission logic for edit
  • Loading branch information
cslzchen authored Jan 10, 2025
2 parents 989ffd5 + 96ca301 commit bc6ceae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
19 changes: 11 additions & 8 deletions api/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion api_tests/users/views/test_user_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
Expand Down
2 changes: 1 addition & 1 deletion osf/models/preprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bc6ceae

Please sign in to comment.