Skip to content

Commit

Permalink
[ENG-6208] implemented unwithdraw specific preprint version (#10964)
Browse files Browse the repository at this point in the history
## Purpose

Allow to unwithdraw preprint versions in the admin app

## Ticket

(https://openscience.atlassian.net/browse/ENG-6208)
  • Loading branch information
bodintsov authored Feb 12, 2025
1 parent 1855d55 commit caa787e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions admin/preprints/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@
re_path(r'^(?P<guid>\w+)/reject_withdrawal/$', views.PreprintRejectWithdrawalRequest.as_view(), name='reject-withdrawal'),
re_path(r'^(?P<guid>\w+)/resync_crossref/$', views.PreprintResyncCrossRefView.as_view(), name='resync-crossref'),
re_path(r'^(?P<guid>\w+)/make_published/$', views.PreprintMakePublishedView.as_view(), name='make-published'),
re_path(r'^(?P<guid>\w+)/unwithdraw/$', views.PreprintUnwithdrawView.as_view(), name='unwithdraw'),
]
35 changes: 35 additions & 0 deletions admin/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
2 changes: 1 addition & 1 deletion admin/templates/preprints/preprint.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ <h2>Preprint: <b>{{ preprint.title }}</b> <a href="{{ preprint.absolute_url }}">
{% 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 %}
</tbody>
</table>
</div>
Expand Down
41 changes: 41 additions & 0 deletions admin/templates/preprints/unwithdraw_request.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% load node_extras %}

{% if perms.osf.change_preprintrequest %}
<tr>
<td>Unwithdraw Version</td>
<td>
<div class="form-inline">
{% if preprint.machine_state == 'withdrawn' %}
Version {{ preprint.version }}
<button type="button" class="btn btn-danger" onclick="$('#confirmUnwithdraw').modal('show')">
Unwithdraw
</button>
<div class="modal" id="confirmUnwithdraw">
<div class="modal-dialog">
<div class="modal-content">
<form class="well" method="post" action="{% url 'admin:unwithdraw' guid=preprint.guid %}">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">x</button>
<h3>Are you sure you want to unwithdraw this version?</h3>
</div>
{% csrf_token %}
<div class="modal-footer">
<button class="btn btn-danger" type="submit">
Unwithdraw
</button>
<button type="button" class="btn btn-default" data-dismiss="modal">
Cancel
</button>
</div>
</form>
</div>
</div>
</div>
{% else %}
Not withdrawn version
<button type="submit" class="btn btn-danger" disabled>Unwithdraw</button>
{% endif %}
</div>
</td>
</tr>
{% endif %}

0 comments on commit caa787e

Please sign in to comment.