Skip to content

Commit

Permalink
Merge branch 'feature/insti-dash-improv' of https://github.com/Center…
Browse files Browse the repository at this point in the history
…ForOpenScience/osf.io into summary-reporter-for-insti-dashboard

* 'feature/insti-dash-improv' of https://github.com/CenterForOpenScience/osf.io:
  remove preprint affiliation special-casing

# Conflicts:
#	api/institutions/serializers.py
  • Loading branch information
John Tordoff committed Sep 19, 2024
2 parents cf164b1 + 884bdfc commit 3ee0024
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
15 changes: 7 additions & 8 deletions api/institutions/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,11 @@ def create(self, validated_data):
'self': inst,
}


class InstitutionRelated(JSONAPIRelationshipSerializer):
id = ser.CharField(source='_id', required=False, allow_null=True)
class Meta:
type_ = 'institutions'


class RegistrationRelated(JSONAPIRelationshipSerializer):
id = ser.CharField(source='_id', required=False, allow_null=True)
class Meta:
type_ = 'registrations'


class InstitutionRegistrationsRelationshipSerializer(BaseAPISerializer):
data = ser.ListField(child=RegistrationRelated())
links = LinksField({
Expand Down Expand Up @@ -321,6 +313,7 @@ def get_absolute_url(self, obj):
},
)


class NewInstitutionUserMetricsSerializer(JSONAPISerializer):
'''serializer for institution-users metrics
Expand Down Expand Up @@ -364,3 +357,9 @@ class Meta:

def get_absolute_url(self):
return None # there is no detail view for institution-users


class InstitutionRelated(JSONAPIRelationshipSerializer):
id = ser.CharField(source='_id', required=False, allow_null=True)
class Meta:
type_ = 'institutions'
2 changes: 1 addition & 1 deletion osf/metadata/osf_gathering.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ()
Expand Down
2 changes: 0 additions & 2 deletions osf/metrics/reporters/institutional_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
32 changes: 11 additions & 21 deletions osf_tests/metrics/reporters/test_institutional_users_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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))
Expand All @@ -90,8 +82,8 @@ def test_one_user_with_stuff_and_no_files(self):
_reports = list(InstitutionalUsersReporter().report(self._yearmonth))
self.assertEqual(len(_reports), 1)
self._assert_report_matches_setup(_reports[0], self._user_setup_with_stuff)
self.assertEqual(_reports[0].public_file_count, 0)
self.assertEqual(_reports[0].storage_byte_count, 0)
self.assertEqual(_reports[0].public_file_count, 2) # preprint 2 files
self.assertEqual(_reports[0].storage_byte_count, 2674) # preprint bytes

def test_one_user_with_stuff_and_a_file(self):
self._user_setup_with_stuff.affiliate_user()
Expand All @@ -101,8 +93,8 @@ def test_one_user_with_stuff_and_a_file(self):
create_test_file(target=_project, user=_user, size=37)
(_report,) = InstitutionalUsersReporter().report(self._yearmonth)
self._assert_report_matches_setup(_report, self._user_setup_with_stuff)
self.assertEqual(_report.public_file_count, 1)
self.assertEqual(_report.storage_byte_count, 37)
self.assertEqual(_report.public_file_count, 3) # 2 preprint files
self.assertEqual(_report.storage_byte_count, 2711) # 2 preprint files

def test_one_user_with_stuff_and_multiple_files(self):
self._user_setup_with_stuff.affiliate_user()
Expand All @@ -118,8 +110,8 @@ def test_one_user_with_stuff_and_multiple_files(self):
create_test_file(target=_component, user=_user, size=47, filename='blarg')
(_report,) = InstitutionalUsersReporter().report(self._yearmonth)
self._assert_report_matches_setup(_report, self._user_setup_with_stuff)
self.assertEqual(_report.public_file_count, 5)
self.assertEqual(_report.storage_byte_count, 37 + 73 + 53 + 51 + 47)
self.assertEqual(_report.public_file_count, 7) # 2 preprint files
self.assertEqual(_report.storage_byte_count, 2935) # 2 preprint files + 37 + 73 + 53 + 51 + 47

def test_several_users(self):
_setups = [
Expand Down Expand Up @@ -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,
)

0 comments on commit 3ee0024

Please sign in to comment.