From 97f0b1933e373056ba8b4ee06bd333dd1f5addc4 Mon Sep 17 00:00:00 2001 From: John Tordoff <> Date: Thu, 19 Sep 2024 11:45:14 -0400 Subject: [PATCH] stop preprint affiliation special casing --- osf/metadata/osf_gathering.py | 2 +- osf/metrics/reporters/institutional_users.py | 2 -- ...ution_link_to_external_reports_archive.py} | 2 +- .../test_institutional_users_reporter.py | 20 +++++-------------- 4 files changed, 7 insertions(+), 19 deletions(-) rename osf/migrations/{0023_institution_link_to_external_reports_archive.py => 0024_institution_link_to_external_reports_archive.py} (84%) diff --git a/osf/metadata/osf_gathering.py b/osf/metadata/osf_gathering.py index 6e5e25c6d0b..9a93f7214fe 100644 --- a/osf/metadata/osf_gathering.py +++ b/osf/metadata/osf_gathering.py @@ -823,7 +823,7 @@ def gather_agents(focus): def gather_affiliated_institutions(focus): if hasattr(focus.dbmodel, 'get_affiliated_institutions'): # like OSFUser institution_qs = focus.dbmodel.get_affiliated_institutions() - elif hasattr(focus.dbmodel, 'affiliated_institutions'): # like AbstractNode + elif hasattr(focus.dbmodel, 'affiliated_institutions'): # like AbstractNode or Preprint institution_qs = focus.dbmodel.affiliated_institutions.all() else: institution_qs = () diff --git a/osf/metrics/reporters/institutional_users.py b/osf/metrics/reporters/institutional_users.py index abe835bcb9c..98e13003387 100644 --- a/osf/metrics/reporters/institutional_users.py +++ b/osf/metrics/reporters/institutional_users.py @@ -103,8 +103,6 @@ def _embargoed_registration_queryset(self): ) def _published_preprint_queryset(self): - if not hasattr(osfdb.Preprint, 'affiliated_institutions'): - return osfdb.Preprint.objects.none() # HACK: preprints affiliation project still in-progress return ( osfdb.Preprint.objects.can_view() # published/publicly-viewable .filter( diff --git a/osf/migrations/0023_institution_link_to_external_reports_archive.py b/osf/migrations/0024_institution_link_to_external_reports_archive.py similarity index 84% rename from osf/migrations/0023_institution_link_to_external_reports_archive.py rename to osf/migrations/0024_institution_link_to_external_reports_archive.py index 2900f45e12d..8e1a47fcffb 100644 --- a/osf/migrations/0023_institution_link_to_external_reports_archive.py +++ b/osf/migrations/0024_institution_link_to_external_reports_archive.py @@ -6,7 +6,7 @@ class Migration(migrations.Migration): dependencies = [ - ('osf', '0022_alter_abstractnode_subjects_alter_abstractnode_tags_and_more'), + ('osf', '0023_preprint_affiliated_institutions'), ] operations = [ diff --git a/osf_tests/metrics/reporters/test_institutional_users_reporter.py b/osf_tests/metrics/reporters/test_institutional_users_reporter.py index 6af191cc669..36e2079d888 100644 --- a/osf_tests/metrics/reporters/test_institutional_users_reporter.py +++ b/osf_tests/metrics/reporters/test_institutional_users_reporter.py @@ -20,11 +20,6 @@ ) -def _can_affiliate_preprints() -> bool: - # HACK: preprints affiliation project still in-progress - return hasattr(osfdb.Preprint, 'affiliated_institutions') - - def _patch_now(fakenow: datetime.datetime): return unittest.mock.patch('django.utils.timezone.now', return_value=fakenow) @@ -64,10 +59,7 @@ def _assert_report_matches_setup(self, report: InstitutionalUserReport, setup: _ self.assertEqual(report.private_project_count, setup.private_project_count) self.assertEqual(report.public_registration_count, setup.public_registration_count) self.assertEqual(report.embargoed_registration_count, setup.embargoed_registration_count) - if _can_affiliate_preprints(): - self.assertEqual(report.published_preprint_count, setup.published_preprint_count) - else: - self.assertEqual(report.published_preprint_count, 0) + self.assertEqual(report.published_preprint_count, setup.published_preprint_count) def test_no_users(self): _actual_reports = list(InstitutionalUsersReporter().report(self._yearmonth)) @@ -249,9 +241,7 @@ def _add_embargoed_registration(self) -> osfdb.Registration: ) def _add_published_preprint(self) -> osfdb.Preprint | None: - if _can_affiliate_preprints(): # HACK: preprints affiliation project still in-progress - return PreprintFactory( - creator=self.user, - is_public=True, - ) - return None + return PreprintFactory( + creator=self.user, + is_public=True, + )