Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-6105] Prevent recording of Preprint metrics from contributors #10715

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions addons/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Loading