Skip to content

Commit

Permalink
Merge pull request #10901 from Ostap-Zherebetskyi/fix/edit_rejected_p…
Browse files Browse the repository at this point in the history
…reprints

[ENG-6850] Update old version mix-in check to allow 'rejected'
  • Loading branch information
cslzchen authored Jan 9, 2025
2 parents 2f3e993 + be067dc commit 608cce3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
45 changes: 19 additions & 26 deletions api/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,40 +72,33 @@


class PreprintOldVersionsImmutableMixin:
"""Override method to reject modify requests for old preprint versions (except for withdrawal)
"""
def update(self, request, *args, **kwargs):
"""Override method to reject modify requests for old preprint versions (except for withdrawal)"""

@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

def handle_request(self, request, method, *args, **kwargs):
preprint = self.get_preprint(check_object_permissions=False)
is_pre_mod_pending = (
preprint.provider.reviews_workflow == Workflows.PRE_MODERATION.value and preprint.machine_state == 'pending'
)
if preprint.is_latest_version or preprint.machine_state == 'initial' or is_pre_mod_pending:
return super().update(request, *args, **kwargs)
if PreprintOldVersionsImmutableMixin.is_edit_allowed(preprint):
return method(request, *args, **kwargs)
message = f'User can not edit previous versions of a preprint: [_id={preprint._id}]'
sentry.log_message(message)
raise Conflict(detail=message)

def update(self, request, *args, **kwargs):
return self.handle_request(request, super().update, *args, **kwargs)

def create(self, request, *args, **kwargs):
preprint = self.get_preprint(check_object_permissions=False)
is_pre_mod_pending = (
preprint.provider.reviews_workflow == Workflows.PRE_MODERATION.value and preprint.machine_state == 'pending'
)
if preprint.is_latest_version or preprint.machine_state == 'initial' or is_pre_mod_pending:
return super().create(request, *args, **kwargs)
message = f'User can not edit previous versions of a preprint: [_id={preprint._id}]'
sentry.log_message(message)
raise Conflict(detail=message)
return self.handle_request(request, super().create, *args, **kwargs)

def destroy(self, request, *args, **kwargs):
preprint = self.get_preprint(check_object_permissions=False)
is_pre_mod_pending = (
preprint.provider.reviews_workflow == Workflows.PRE_MODERATION.value and preprint.machine_state == 'pending'
)
if preprint.is_latest_version or preprint.machine_state == 'initial' or is_pre_mod_pending:
return super().destroy(request, *args, **kwargs)
message = f'User can not edit previous versions of a preprint: [_id={preprint._id}]'
sentry.log_message(message)
raise Conflict(detail=message)
return self.handle_request(request, super().destroy, *args, **kwargs)


class PreprintMixin(NodeMixin):
Expand Down
5 changes: 5 additions & 0 deletions osf/models/preprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,11 @@ def run_accept(self, user, comment, **kwargs):
base_guid_obj.object_id = self.pk
base_guid_obj.content_type = ContentType.objects.get_for_model(self)
base_guid_obj.save()

versioned_guid = self.versioned_guids.first()
if versioned_guid.is_rejected:
versioned_guid.is_rejected = False
versioned_guid.save()
return ret

# Override ReviewableMixin
Expand Down

0 comments on commit 608cce3

Please sign in to comment.