[ENG-9907] Analytics are increasing (unique views) when a contributor is viewing their own content (Project) (BE)#11669
Open
antkryt wants to merge 1 commit intoCenterForOpenScience:feature/pbs-26-6from
Conversation
brianjgeiger
requested changes
Mar 31, 2026
Comment on lines
+361
to
+417
| class TestContributorExclusion: | ||
|
|
||
| def test_creator_pageview_not_recorded(self, app, mock_save): | ||
| user = AuthUserFactory() | ||
| project = ProjectFactory(creator=user) | ||
| payload = counted_usage_payload( | ||
| item_guid=project._id, | ||
| action_labels=['view', 'web'], | ||
| pageview_info={'page_url': f'https://osf.io/{project._id}/'}, | ||
| ) | ||
| resp = app.post_json_api(COUNTED_USAGE_URL, payload, auth=user.auth) | ||
| assert resp.status_code == 204 | ||
| assert mock_save.call_count == 0 | ||
|
|
||
| def test_read_contributor_pageview_not_recorded(self, app, mock_save): | ||
| creator = AuthUserFactory() | ||
| reader = AuthUserFactory() | ||
| project = ProjectFactory(creator=creator) | ||
| project.add_contributor(reader, permissions=READ, auth=Auth(creator)) | ||
| payload = counted_usage_payload( | ||
| item_guid=project._id, | ||
| action_labels=['view', 'web'], | ||
| pageview_info={'page_url': f'https://osf.io/{project._id}/analytics/'}, | ||
| ) | ||
| resp = app.post_json_api(COUNTED_USAGE_URL, payload, auth=reader.auth) | ||
| assert resp.status_code == 204 | ||
| assert mock_save.call_count == 0 | ||
|
|
||
| def test_non_contributor_pageview_recorded(self, app, mock_save): | ||
| creator = AuthUserFactory() | ||
| visitor = AuthUserFactory() | ||
| project = ProjectFactory(creator=creator, is_public=True) | ||
| payload = counted_usage_payload( | ||
| item_guid=project._id, | ||
| action_labels=['view', 'web'], | ||
| pageview_info={'page_url': f'https://osf.io/{project._id}/'}, | ||
| ) | ||
| resp = app.post_json_api(COUNTED_USAGE_URL, payload, auth=visitor.auth) | ||
| assert resp.status_code == 201 | ||
| assert mock_save.call_count == 1 | ||
|
|
||
| def test_parent_contributor_not_on_child_component_pageview_recorded(self, app, mock_save): | ||
| creator = AuthUserFactory() | ||
| child_owner = AuthUserFactory() | ||
| parent_reader = AuthUserFactory() | ||
| parent = ProjectFactory(creator=creator, is_public=True) | ||
| child = NodeFactory(parent=parent, creator=child_owner, is_public=True) | ||
| parent.add_contributor(parent_reader, permissions=READ, auth=Auth(creator)) | ||
| assert not child.contributors_and_group_members.filter(guids___id=parent_reader._id).exists() | ||
| payload = counted_usage_payload( | ||
| item_guid=child._id, | ||
| action_labels=['view', 'web'], | ||
| pageview_info={'page_url': f'https://osf.io/{child._id}/'}, | ||
| ) | ||
| resp = app.post_json_api(COUNTED_USAGE_URL, payload, auth=parent_reader.auth) | ||
| assert resp.status_code == 201 | ||
| assert mock_save.call_count == 1 |
Collaborator
There was a problem hiding this comment.
Could you add a test for a user using a View Only Link to make sure they're counted? Also one for if a user is an admin on a parent project but is not a contributor on the component (like your read contributor one above, but for Admin). For the admin one, I'm not sure that we want to change it whichever way it works out, but I would like to know what to expect there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket
Purpose
do not count contrib views
Changes
Side Effects
QE Notes
CE Notes
Documentation