Skip to content

Commit a404bcd

Browse files
authored
Merge pull request #11633 from ihorsokhanexoft/fix/ENG-10328
[ENG-10328] fixed non-consistent COI
2 parents dcb6bd4 + 23f0a83 commit a404bcd

5 files changed

Lines changed: 78 additions & 0 deletions

File tree

admin/preprints/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
re_path(r'^(?P<guid>\w+)/remove_user/(?P<user_id>[a-z0-9]+)/$', views.PreprintRemoveContributorView.as_view(), name='remove-user'),
1818
re_path(r'^(?P<guid>\w+)/make_private/$', views.PreprintMakePrivate.as_view(), name='make-private'),
1919
re_path(r'^(?P<guid>\w+)/fix_editing/$', views.PreprintFixEditing.as_view(), name='fix-editing'),
20+
re_path(r'^(?P<guid>\w+)/fix_coi/$', views.PreprintFixCOI.as_view(), name='fix-coi'),
2021
re_path(r'^(?P<guid>\w+)/make_public/$', views.PreprintMakePublic.as_view(), name='make-public'),
2122
re_path(r'^(?P<guid>\w+)/remove/$', views.PreprintDeleteView.as_view(), name='remove'),
2223
re_path(r'^(?P<guid>\w+)/restore/$', views.PreprintDeleteView.as_view(), name='restore'),

admin/preprints/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,22 @@ def post(self, request, *args, **kwargs):
668668
return redirect(self.get_success_url())
669669

670670

671+
class PreprintFixCOI(PreprintMixin, View):
672+
""" Allows an authorized user to manually fix conflict of interest field.
673+
"""
674+
permission_required = 'osf.change_preprint'
675+
676+
def post(self, request, *args, **kwargs):
677+
preprint = self.get_object()
678+
if preprint.conflict_of_interest_statement and not preprint.has_coi:
679+
preprint.update_has_coi(auth=request, has_coi=True, ignore_permission=True)
680+
messages.success(request, 'The COI was successfully fixed.')
681+
else:
682+
messages.error(request, 'The COI is either already fixed or the preprint does not have conflict of interest set.')
683+
684+
return redirect(self.get_success_url())
685+
686+
671687
class PreprintMakePublic(PreprintMixin, View):
672688
""" Allows an authorized user to manually make a private preprint public.
673689
"""
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% if perms.osf.change_preprint %}
2+
<a data-toggle="modal" data-target="#confirmFixCOI" class="btn btn-warning">
3+
Fix COI
4+
</a>
5+
<div class="modal" id="confirmFixCOI">
6+
<div class="modal-dialog">
7+
<div class="modal-content">
8+
<form class="well" method="post" action="{% url 'preprints:fix-coi' guid=preprint.guid %}">
9+
{% csrf_token %}
10+
<div class="modal-footer">
11+
<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>
12+
<input class="btn btn-danger" type="submit" value="Confirm" />
13+
<button type="button" class="btn btn-default" data-dismiss="modal">
14+
Cancel
15+
</button>
16+
</div>
17+
</form>
18+
</div>
19+
</div>
20+
</div>
21+
{% endif %}

admin/templates/preprints/preprint.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
{% include "preprints/make_public.html" with preprint=preprint %}
2929
{% include "preprints/make_published.html" with preprint=preprint %}
3030
{% include "preprints/fix_editing.html" with preprint=preprint %}
31+
{% include "preprints/fix_coi.html" with preprint=preprint %}
3132
{% include "preprints/assign_new_version.html" with preprint=preprint %}
3233
</div>
3334
</div>

admin_tests/preprints/test_views.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,3 +960,42 @@ def test_osf_admin_can_create_new_version_with_unregistered_contributors(self, p
960960
preprint.refresh_from_db()
961961

962962
assert len(preprint.get_preprint_versions()) == 2
963+
964+
965+
@pytest.mark.urls('admin.base.urls')
966+
class TestPreprintFixCOIView:
967+
968+
@pytest.fixture()
969+
def plain_view(self):
970+
return views.PreprintFixCOI
971+
972+
def test_admin_user_can_fix_coi_only_when_coi_is_set(self, user, preprint, plain_view):
973+
admin_group = Group.objects.get(name='osf_admin')
974+
preprint.has_coi = False
975+
preprint.conflict_of_interest_statement = 'some text'
976+
preprint.save()
977+
978+
request = RequestFactory().post(reverse('preprints:fix-coi', kwargs={'guid': preprint._id}))
979+
request.user = user
980+
patch_messages(request)
981+
982+
admin_group.permissions.add(Permission.objects.get(codename='change_preprint'))
983+
user.groups.add(admin_group)
984+
985+
plain_view.as_view()(request, guid=preprint._id)
986+
preprint.reload()
987+
988+
assert preprint.has_coi
989+
assert preprint.conflict_of_interest_statement == 'some text'
990+
991+
# this case is not fixable because the preprint doesn't have COI statement set but has_coi = True
992+
# which means we should add COI text by ourselves
993+
preprint.has_coi = True
994+
preprint.conflict_of_interest_statement = ''
995+
preprint.save()
996+
997+
plain_view.as_view()(request, guid=preprint._id)
998+
preprint.reload()
999+
1000+
assert preprint.has_coi
1001+
assert preprint.conflict_of_interest_statement == ''

0 commit comments

Comments
 (0)