From caa787e102867bfb410a7c080cb2d3b1e2a8d048 Mon Sep 17 00:00:00 2001 From: bodintsov Date: Wed, 12 Feb 2025 16:20:47 +0200 Subject: [PATCH] [ENG-6208] implemented unwithdraw specific preprint version (#10964) ## Purpose Allow to unwithdraw preprint versions in the admin app ## Ticket (https://openscience.atlassian.net/browse/ENG-6208) --- admin/preprints/urls.py | 1 + admin/preprints/views.py | 35 ++++++++++++++++ admin/templates/preprints/preprint.html | 2 +- .../preprints/unwithdraw_request.html | 41 +++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 admin/templates/preprints/unwithdraw_request.html diff --git a/admin/preprints/urls.py b/admin/preprints/urls.py index 815b7324bd1..f0a439f9722 100644 --- a/admin/preprints/urls.py +++ b/admin/preprints/urls.py @@ -26,4 +26,5 @@ re_path(r'^(?P\w+)/reject_withdrawal/$', views.PreprintRejectWithdrawalRequest.as_view(), name='reject-withdrawal'), re_path(r'^(?P\w+)/resync_crossref/$', views.PreprintResyncCrossRefView.as_view(), name='resync-crossref'), re_path(r'^(?P\w+)/make_published/$', views.PreprintMakePublishedView.as_view(), name='make-published'), + re_path(r'^(?P\w+)/unwithdraw/$', views.PreprintUnwithdrawView.as_view(), name='unwithdraw'), ] diff --git a/admin/preprints/views.py b/admin/preprints/views.py index 56aa72b4041..877ee838b9b 100644 --- a/admin/preprints/views.py +++ b/admin/preprints/views.py @@ -560,3 +560,38 @@ def post(self, request, *args, **kwargs): preprint = self.get_object() preprint.set_published(True, request, True) return redirect(self.get_success_url()) + +class PreprintUnwithdrawView(PreprintMixin, View): + """ Allows authorized users to unwithdraw a preprint that was previously withdrawn. + """ + permission_required = ('osf.change_node') + + def post(self, request, *args, **kwargs): + preprint = self.get_object() + + if preprint.machine_state != 'withdrawn': + messages.error(request, f'Preprint {preprint._id} is not withdrawn') + return redirect(self.get_success_url()) + + withdraw_action = preprint.actions.filter(to_state='withdrawn').last() + last_action = preprint.actions.last() + + preprint.withdrawal_justification = '' + preprint.date_withdrawn = None + + if withdraw_action: + preprint.machine_state = withdraw_action.from_state + withdraw_action.delete() + else: + if last_action: + preprint.machine_state = last_action.to_state + else: + # Default to put it back in moderation if we don't know where it came from + preprint.machine_state = 'pending' + + from osf.utils.migrations import disable_auto_now_fields + with disable_auto_now_fields(): + preprint.save() + + messages.success(request, f'Successfully unwithdrawn preprint {preprint._id}') + return redirect(self.get_success_url()) diff --git a/admin/templates/preprints/preprint.html b/admin/templates/preprints/preprint.html index 57f731efaf6..2763d3d35f1 100644 --- a/admin/templates/preprints/preprint.html +++ b/admin/templates/preprints/preprint.html @@ -116,7 +116,7 @@

Preprint: {{ preprint.title }} {% include "preprints/contributors.html" with preprint=preprint %} {% include "nodes/spam_status.html" with resource=preprint %} {% include "preprints/withdraw_request.html" with preprint=preprint %} - + {% include "preprints/unwithdraw_request.html" with preprint=preprint %} diff --git a/admin/templates/preprints/unwithdraw_request.html b/admin/templates/preprints/unwithdraw_request.html new file mode 100644 index 00000000000..38aba5d1817 --- /dev/null +++ b/admin/templates/preprints/unwithdraw_request.html @@ -0,0 +1,41 @@ +{% load node_extras %} + +{% if perms.osf.change_preprintrequest %} + + Unwithdraw Version + +
+ {% if preprint.machine_state == 'withdrawn' %} + Version {{ preprint.version }} + + + {% else %} + Not withdrawn version + + {% endif %} +
+ + +{% endif %} \ No newline at end of file