From 979eded66a7e29c3677692452ca80e45549027aa Mon Sep 17 00:00:00 2001 From: Matt Frazier Date: Fri, 23 Aug 2024 14:22:39 -0400 Subject: [PATCH] Don't record preprint metrics from contributors --- addons/base/views.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/addons/base/views.py b/addons/base/views.py index 6fea2444421..6253f7bc91b 100644 --- a/addons/base/views.py +++ b/addons/base/views.py @@ -696,6 +696,10 @@ def osfstoragefile_mark_viewed(self, auth, fileversion, file_node): @file_signals.file_viewed.connect def osfstoragefile_update_view_analytics(self, auth, fileversion, file_node): resource = file_node.target + user = getattr(auth, 'user', None) + if hasattr(resource, 'is_contributor_or_group_member') and resource.is_contributor_or_group_member(user): + # Don't record views by contributors + return enqueue_update_analytics( resource, file_node, @@ -707,6 +711,10 @@ def osfstoragefile_update_view_analytics(self, auth, fileversion, file_node): @file_signals.file_viewed.connect def osfstoragefile_viewed_update_metrics(self, auth, fileversion, file_node): resource = file_node.target + user = getattr(auth, 'user', None) + if hasattr(resource, 'is_contributor_or_group_member') and resource.is_contributor_or_group_member(user): + # Don't record views by contributors + return if waffle.switch_is_active(features.ELASTICSEARCH_METRICS) and isinstance(resource, Preprint): try: PreprintView.record_for_preprint( @@ -730,6 +738,10 @@ def osfstoragefile_downloaded_update_analytics(self, auth, fileversion, file_nod @file_signals.file_downloaded.connect def osfstoragefile_downloaded_update_metrics(self, auth, fileversion, file_node): resource = file_node.target + user = getattr(auth, 'user', None) + if hasattr(resource, 'is_contributor_or_group_member') and resource.is_contributor_or_group_member(user): + # Don't record downloads by contributors + return if waffle.switch_is_active(features.ELASTICSEARCH_METRICS) and isinstance(resource, Preprint): try: PreprintDownload.record_for_preprint(