From ee476f139acaf79b37e7c3042397d87da2540299 Mon Sep 17 00:00:00 2001 From: Ihor Sokhan Date: Thu, 12 Mar 2026 09:53:25 +0200 Subject: [PATCH 1/2] fixed non-consistent COI --- admin/preprints/urls.py | 1 + admin/preprints/views.py | 16 ++++++++++ admin/templates/preprints/fix_coi.html | 21 +++++++++++++ admin/templates/preprints/preprint.html | 1 + admin_tests/preprints/test_views.py | 39 +++++++++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 admin/templates/preprints/fix_coi.html diff --git a/admin/preprints/urls.py b/admin/preprints/urls.py index d6eabdd870c..960e2e297e5 100644 --- a/admin/preprints/urls.py +++ b/admin/preprints/urls.py @@ -17,6 +17,7 @@ re_path(r'^(?P\w+)/remove_user/(?P[a-z0-9]+)/$', views.PreprintRemoveContributorView.as_view(), name='remove-user'), re_path(r'^(?P\w+)/make_private/$', views.PreprintMakePrivate.as_view(), name='make-private'), re_path(r'^(?P\w+)/fix_editing/$', views.PreprintFixEditing.as_view(), name='fix-editing'), + re_path(r'^(?P\w+)/fix_coi/$', views.PreprintFixCOI.as_view(), name='fix-coi'), re_path(r'^(?P\w+)/make_public/$', views.PreprintMakePublic.as_view(), name='make-public'), re_path(r'^(?P\w+)/remove/$', views.PreprintDeleteView.as_view(), name='remove'), re_path(r'^(?P\w+)/restore/$', views.PreprintDeleteView.as_view(), name='restore'), diff --git a/admin/preprints/views.py b/admin/preprints/views.py index 909006ea91d..d4dc4ea5365 100644 --- a/admin/preprints/views.py +++ b/admin/preprints/views.py @@ -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. """ diff --git a/admin/templates/preprints/fix_coi.html b/admin/templates/preprints/fix_coi.html new file mode 100644 index 00000000000..6ee06e66130 --- /dev/null +++ b/admin/templates/preprints/fix_coi.html @@ -0,0 +1,21 @@ +{% if perms.osf.change_node %} + + Fix COI + + +{% endif %} diff --git a/admin/templates/preprints/preprint.html b/admin/templates/preprints/preprint.html index d716b60aeb7..36066a94ccf 100644 --- a/admin/templates/preprints/preprint.html +++ b/admin/templates/preprints/preprint.html @@ -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 %} diff --git a/admin_tests/preprints/test_views.py b/admin_tests/preprints/test_views.py index 2cdcda136d1..e9bf4104182 100644 --- a/admin_tests/preprints/test_views.py +++ b/admin_tests/preprints/test_views.py @@ -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 == '' From 5fe6d8d1624c668ff6111488d14ef7253b732347 Mon Sep 17 00:00:00 2001 From: Ihor Sokhan Date: Thu, 12 Mar 2026 10:00:34 +0200 Subject: [PATCH 2/2] fixed permission in a template --- admin/templates/preprints/fix_coi.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/templates/preprints/fix_coi.html b/admin/templates/preprints/fix_coi.html index 6ee06e66130..1324c4b53c5 100644 --- a/admin/templates/preprints/fix_coi.html +++ b/admin/templates/preprints/fix_coi.html @@ -1,4 +1,4 @@ -{% if perms.osf.change_node %} +{% if perms.osf.change_preprint %} Fix COI