[ENG-9907] Analytics are increasing (unique views) when a contributor is viewing their own content (Project) (BE)#11669
Conversation
| 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 |
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.
There was a problem hiding this comment.
Currently we don't count view ONLY if user is a contributor on the current node (not parent, child, etc): test_parent_contributor_not_on_child_component_pageview_recorded. Before my changes we counted any view (any call to /_/metrics/count) without any checks, so I'm not sure what logic is correct here
Ticket
Purpose
do not count contrib views
Changes
Side Effects
QE Notes
CE Notes
Documentation