Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions admin/preprints/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
re_path(r'^(?P<guid>\w+)/remove_user/(?P<user_id>[a-z0-9]+)/$', views.PreprintRemoveContributorView.as_view(), name='remove-user'),
re_path(r'^(?P<guid>\w+)/make_private/$', views.PreprintMakePrivate.as_view(), name='make-private'),
re_path(r'^(?P<guid>\w+)/fix_editing/$', views.PreprintFixEditing.as_view(), name='fix-editing'),
re_path(r'^(?P<guid>\w+)/fix_coi/$', views.PreprintFixCOI.as_view(), name='fix-coi'),
re_path(r'^(?P<guid>\w+)/make_public/$', views.PreprintMakePublic.as_view(), name='make-public'),
re_path(r'^(?P<guid>\w+)/remove/$', views.PreprintDeleteView.as_view(), name='remove'),
re_path(r'^(?P<guid>\w+)/restore/$', views.PreprintDeleteView.as_view(), name='restore'),
Expand Down
16 changes: 16 additions & 0 deletions admin/preprints/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,22 @@ def post(self, request, *args, **kwargs):
return redirect(self.get_success_url())


class PreprintFixCOI(PreprintMixin, View):
""" Allows an authorized user to manually fix conflict of interest field.
"""
permission_required = 'osf.change_preprint'

def post(self, request, *args, **kwargs):
preprint = self.get_object()
if preprint.conflict_of_interest_statement and not preprint.has_coi:
preprint.update_has_coi(auth=request, has_coi=True, ignore_permission=True)
messages.success(request, 'The COI was successfully fixed.')
else:
messages.error(request, 'The COI is either already fixed or the preprint does not have conflict of interest set.')

return redirect(self.get_success_url())


class PreprintMakePublic(PreprintMixin, View):
""" Allows an authorized user to manually make a private preprint public.
"""
Expand Down
21 changes: 21 additions & 0 deletions admin/templates/preprints/fix_coi.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% if perms.osf.change_preprint %}
<a data-toggle="modal" data-target="#confirmFixCOI" class="btn btn-warning">
Fix COI
</a>
<div class="modal" id="confirmFixCOI">
<div class="modal-dialog">
<div class="modal-content">
<form class="well" method="post" action="{% url 'preprints:fix-coi' guid=preprint.guid %}">
{% csrf_token %}
<div class="modal-footer">
<h3 style="text-align: center">This functionality fixes only the case when conflict of interest statement was previously set by user but is not displayed for him</h3>
<input class="btn btn-danger" type="submit" value="Confirm" />
<button type="button" class="btn btn-default" data-dismiss="modal">
Cancel
</button>
</div>
</form>
</div>
</div>
</div>
{% endif %}
1 change: 1 addition & 0 deletions admin/templates/preprints/preprint.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
{% include "preprints/make_public.html" with preprint=preprint %}
{% include "preprints/make_published.html" with preprint=preprint %}
{% include "preprints/fix_editing.html" with preprint=preprint %}
{% include "preprints/fix_coi.html" with preprint=preprint %}
{% include "preprints/assign_new_version.html" with preprint=preprint %}
</div>
</div>
Expand Down
39 changes: 39 additions & 0 deletions admin_tests/preprints/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -960,3 +960,42 @@ def test_osf_admin_can_create_new_version_with_unregistered_contributors(self, p
preprint.refresh_from_db()

assert len(preprint.get_preprint_versions()) == 2


@pytest.mark.urls('admin.base.urls')
class TestPreprintFixCOIView:

@pytest.fixture()
def plain_view(self):
return views.PreprintFixCOI

def test_admin_user_can_fix_coi_only_when_coi_is_set(self, user, preprint, plain_view):
admin_group = Group.objects.get(name='osf_admin')
preprint.has_coi = False
preprint.conflict_of_interest_statement = 'some text'
preprint.save()

request = RequestFactory().post(reverse('preprints:fix-coi', kwargs={'guid': preprint._id}))
request.user = user
patch_messages(request)

admin_group.permissions.add(Permission.objects.get(codename='change_preprint'))
user.groups.add(admin_group)

plain_view.as_view()(request, guid=preprint._id)
preprint.reload()

assert preprint.has_coi
assert preprint.conflict_of_interest_statement == 'some text'

# this case is not fixable because the preprint doesn't have COI statement set but has_coi = True
# which means we should add COI text by ourselves
preprint.has_coi = True
preprint.conflict_of_interest_statement = ''
preprint.save()

plain_view.as_view()(request, guid=preprint._id)
preprint.reload()

assert preprint.has_coi
assert preprint.conflict_of_interest_statement == ''
Loading