{"action":"created","comment":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/201065137","pull_request_review_id":135493961,"id":201065137,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMTA2NTEzNw==","diff_hunk":"@@ -117,6 +123,25 @@ def get_absolute_url(self, obj):\n             'version': self.context['request'].parser_context['kwargs']['version']\n         })\n \n+    def get_node_count(self, obj):\n+        return default_node_list_queryset(model_cls=Node).filter(contributor__user__id=obj.id).count()\n+\n+    def get_quickfiles_count(self, obj):\n+        return QuickFilesNode.objects.get(contributor__user__id=obj.id).files.filter(type='osf.osfstoragefile').count()\n+\n+    def get_registration_count(self, obj):\n+        return default_node_list_queryset(model_cls=Registration).filter(contributor__user__id=obj.id).count()\n+\n+    def get_preprint_count(self, obj):\n+        return PreprintService.objects.filter(Q(node___contributors__guids___id=obj._id)","path":"api/users/serializers.py","position":73,"original_position":73,"commit_id":"c71a5ac261a5b85eaba852cafef72de7addafec9","original_commit_id":"c71a5ac261a5b85eaba852cafef72de7addafec9","user":{"login":"pattisdr","id":9755598,"node_id":"MDQ6VXNlcjk3NTU1OTg=","avatar_url":"https://avatars2.githubusercontent.com/u/9755598?v=4","gravatar_id":"","url":"https://api.github.com/users/pattisdr","html_url":"https://github.com/pattisdr","followers_url":"https://api.github.com/users/pattisdr/followers","following_url":"https://api.github.com/users/pattisdr/following{/other_user}","gists_url":"https://api.github.com/users/pattisdr/gists{/gist_id}","starred_url":"https://api.github.com/users/pattisdr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pattisdr/subscriptions","organizations_url":"https://api.github.com/users/pattisdr/orgs","repos_url":"https://api.github.com/users/pattisdr/repos","events_url":"https://api.github.com/users/pattisdr/events{/privacy}","received_events_url":"https://api.github.com/users/pattisdr/received_events","type":"User","site_admin":false},"body":"It looks to me like deleted preprints aren't accounted for here, there's a confusion between the logged in user and the target user, and reviewers will see a different count.\r\n\r\nThe UserPreprints queryset starts with a base queryset of preprints who have the target user as a contributor. That base queryset is further filtered to make sure preprints are not deleted and to see if the logged in user is either an admin/reviewer or the preprint is viewable by anyone (published/public).\r\n\r\nThat being said, I would make it something like this:\r\n```python\r\nfrom guardian.shortcuts import get_objects_for_user\r\nfrom osf.models import PreprintProvider\r\n    class UserSerializer(JSONAPISerializer):\r\n    ...\r\n      def get_preprint_count(self, obj):\r\n          auth_user =  get_user_auth(self.context['request']).user\r\n          query = Q(is_published=True, node__is_public=True)\r\n          if auth_user:\r\n              admin_user_query = Q(node__contributor__user_id=auth_user.id, node__contributor__admin=True)\r\n              reviews_user_query = Q(node__is_public=True, provider__in=get_objects_for_user(auth_user, 'view_submissions', PreprintProvider))\r\n              query = query | admin_user_query | reviews_user_query\r\n\r\n          return PreprintService.objects.filter(node___contributors__guids__id=obj.id, node__is_deleted=False).filter(query).count()\r\n```\r\n\r\nThis is very similar to logic in PreprintFilterMixin.preprints_queryset but I wouldn't waste your time trying to consolidate because the divorce rewrites and moves that code.  More of a note to self: if your PR gets in before mine, divorce code will need to tweak your counts.","created_at":"2018-07-09T16:24:13Z","updated_at":"2018-07-09T16:39:11Z","html_url":"https://github.com/CenterForOpenScience/osf.io/pull/8437#discussion_r201065137","pull_request_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/8437","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/201065137"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/8437#discussion_r201065137"},"pull_request":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/8437"}}},"pull_request":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/8437","id":194683180,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk0NjgzMTgw","html_url":"https://github.com/CenterForOpenScience/osf.io/pull/8437","diff_url":"https://github.com/CenterForOpenScience/osf.io/pull/8437.diff","patch_url":"https://github.com/CenterForOpenScience/osf.io/pull/8437.patch","issue_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/8437","number":8437,"state":"open","locked":false,"title":"[PLAT-846] Add related counts to relationship fields","user":{"login":"Johnetordoff","id":9688518,"node_id":"MDQ6VXNlcjk2ODg1MTg=","avatar_url":"https://avatars3.githubusercontent.com/u/9688518?v=4","gravatar_id":"","url":"https://api.github.com/users/Johnetordoff","html_url":"https://github.com/Johnetordoff","followers_url":"https://api.github.com/users/Johnetordoff/followers","following_url":"https://api.github.com/users/Johnetordoff/following{/other_user}","gists_url":"https://api.github.com/users/Johnetordoff/gists{/gist_id}","starred_url":"https://api.github.com/users/Johnetordoff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Johnetordoff/subscriptions","organizations_url":"https://api.github.com/users/Johnetordoff/orgs","repos_url":"https://api.github.com/users/Johnetordoff/repos","events_url":"https://api.github.com/users/Johnetordoff/events{/privacy}","received_events_url":"https://api.github.com/users/Johnetordoff/received_events","type":"User","site_admin":false},"body":"## Purpose\r\n\r\nThe ember teams would like to know how many related items they are looking at before the request the API for more info, but certain related fields don't have counts associated with them. This PR adds that.\r\n\r\n## Note\r\n\r\nI considered writing tests for this be the ticket says this behavior will be generalized to apply to all relationship fields so I think tests should be held off until then, when we won't have to special case.\r\n\r\n## Changes\r\n\r\n- add related counts for user serializer for:\r\n   - node\r\n   - quickfiles\r\n   - institutions\r\n   - registrations\r\n   - preprints\r\n\r\n- add related counts for node serializer for:\r\n   - forks\r\n\r\n## QA Notes\r\n\r\nVisting /v2/users or  /v2/nodes in list or detail view should give counts of how many items are included when you include the query parameter `related_counts=True` for specific counts use the param `related_counts=preprints` or `related_counts=preprints,nodes` etc. \r\n\r\n## Documentation\r\n\r\n`related_counts` is to be documented by this: https://github.com/CenterForOpenScience/developer.osf.io/pull/21\r\n\r\n## Side Effects\r\n\r\nNone that I know of.\r\n\r\n## Ticket\r\n\r\nhttps://openscience.atlassian.net/projects/PLAT/issues/PLAT-846","created_at":"2018-06-13T18:57:01Z","updated_at":"2018-07-09T16:39:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b114bd38eab8155766e92fd673f38a5672381fc6","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/8437/commits","review_comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/8437/comments","review_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/8437/comments","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/c71a5ac261a5b85eaba852cafef72de7addafec9","head":{"label":"Johnetordoff:related-counts","ref":"related-counts","sha":"c71a5ac261a5b85eaba852cafef72de7addafec9","user":{"login":"Johnetordoff","id":9688518,"node_id":"MDQ6VXNlcjk2ODg1MTg=","avatar_url":"https://avatars3.githubusercontent.com/u/9688518?v=4","gravatar_id":"","url":"https://api.github.com/users/Johnetordoff","html_url":"https://github.com/Johnetordoff","followers_url":"https://api.github.com/users/Johnetordoff/followers","following_url":"https://api.github.com/users/Johnetordoff/following{/other_user}","gists_url":"https://api.github.com/users/Johnetordoff/gists{/gist_id}","starred_url":"https://api.github.com/users/Johnetordoff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Johnetordoff/subscriptions","organizations_url":"https://api.github.com/users/Johnetordoff/orgs","repos_url":"https://api.github.com/users/Johnetordoff/repos","events_url":"https://api.github.com/users/Johnetordoff/events{/privacy}","received_events_url":"https://api.github.com/users/Johnetordoff/received_events","type":"User","site_admin":false},"repo":{"id":80773184,"node_id":"MDEwOlJlcG9zaXRvcnk4MDc3MzE4NA==","name":"osf.io","full_name":"Johnetordoff/osf.io","owner":{"login":"Johnetordoff","id":9688518,"node_id":"MDQ6VXNlcjk2ODg1MTg=","avatar_url":"https://avatars3.githubusercontent.com/u/9688518?v=4","gravatar_id":"","url":"https://api.github.com/users/Johnetordoff","html_url":"https://github.com/Johnetordoff","followers_url":"https://api.github.com/users/Johnetordoff/followers","following_url":"https://api.github.com/users/Johnetordoff/following{/other_user}","gists_url":"https://api.github.com/users/Johnetordoff/gists{/gist_id}","starred_url":"https://api.github.com/users/Johnetordoff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Johnetordoff/subscriptions","organizations_url":"https://api.github.com/users/Johnetordoff/orgs","repos_url":"https://api.github.com/users/Johnetordoff/repos","events_url":"https://api.github.com/users/Johnetordoff/events{/privacy}","received_events_url":"https://api.github.com/users/Johnetordoff/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Johnetordoff/osf.io","description":"Facilitating Open Science","fork":true,"url":"https://api.github.com/repos/Johnetordoff/osf.io","forks_url":"https://api.github.com/repos/Johnetordoff/osf.io/forks","keys_url":"https://api.github.com/repos/Johnetordoff/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Johnetordoff/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Johnetordoff/osf.io/teams","hooks_url":"https://api.github.com/repos/Johnetordoff/osf.io/hooks","issue_events_url":"https://api.github.com/repos/Johnetordoff/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/Johnetordoff/osf.io/events","assignees_url":"https://api.github.com/repos/Johnetordoff/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/Johnetordoff/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/Johnetordoff/osf.io/tags","blobs_url":"https://api.github.com/repos/Johnetordoff/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Johnetordoff/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Johnetordoff/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/Johnetordoff/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Johnetordoff/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/Johnetordoff/osf.io/languages","stargazers_url":"https://api.github.com/repos/Johnetordoff/osf.io/stargazers","contributors_url":"https://api.github.com/repos/Johnetordoff/osf.io/contributors","subscribers_url":"https://api.github.com/repos/Johnetordoff/osf.io/subscribers","subscription_url":"https://api.github.com/repos/Johnetordoff/osf.io/subscription","commits_url":"https://api.github.com/repos/Johnetordoff/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/Johnetordoff/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/Johnetordoff/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/Johnetordoff/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/Johnetordoff/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/Johnetordoff/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Johnetordoff/osf.io/merges","archive_url":"https://api.github.com/repos/Johnetordoff/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Johnetordoff/osf.io/downloads","issues_url":"https://api.github.com/repos/Johnetordoff/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/Johnetordoff/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/Johnetordoff/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/Johnetordoff/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Johnetordoff/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/Johnetordoff/osf.io/releases{/id}","deployments_url":"https://api.github.com/repos/Johnetordoff/osf.io/deployments","created_at":"2017-02-02T22:05:12Z","updated_at":"2018-04-29T17:00:28Z","pushed_at":"2018-07-09T16:09:33Z","git_url":"git://github.com/Johnetordoff/osf.io.git","ssh_url":"git@github.com:Johnetordoff/osf.io.git","clone_url":"https://github.com/Johnetordoff/osf.io.git","svn_url":"https://github.com/Johnetordoff/osf.io","homepage":"https://osf.io","size":181370,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"CenterForOpenScience:release/next-platform","ref":"release/next-platform","sha":"a0917f8f1685ab710fa0ed236f178b1fe235e87a","user":{"login":"CenterForOpenScience","id":3344584,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMzNDQ1ODQ=","avatar_url":"https://avatars1.githubusercontent.com/u/3344584?v=4","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"repo":{"id":10199599,"node_id":"MDEwOlJlcG9zaXRvcnkxMDE5OTU5OQ==","name":"osf.io","full_name":"CenterForOpenScience/osf.io","owner":{"login":"CenterForOpenScience","id":3344584,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMzNDQ1ODQ=","avatar_url":"https://avatars1.githubusercontent.com/u/3344584?v=4","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CenterForOpenScience/osf.io","description":"Facilitating Open Science","fork":false,"url":"https://api.github.com/repos/CenterForOpenScience/osf.io","forks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/forks","keys_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/teams","hooks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/hooks","issue_events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/events","assignees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/tags","blobs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/languages","stargazers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/stargazers","contributors_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contributors","subscribers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscribers","subscription_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscription","commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/merges","archive_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/downloads","issues_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/releases{/id}","deployments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/deployments","created_at":"2013-05-21T15:53:37Z","updated_at":"2018-07-09T03:15:16Z","pushed_at":"2018-07-09T16:27:13Z","git_url":"git://github.com/CenterForOpenScience/osf.io.git","ssh_url":"git@github.com:CenterForOpenScience/osf.io.git","clone_url":"https://github.com/CenterForOpenScience/osf.io.git","svn_url":"https://github.com/CenterForOpenScience/osf.io","homepage":"https://osf.io","size":172760,"stargazers_count":449,"watchers_count":449,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":247,"mirror_url":null,"archived":false,"open_issues_count":231,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":247,"open_issues":231,"watchers":449,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/8437"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/8437"},"issue":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/8437"},"comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/8437/comments"},"review_comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/8437/comments"},"review_comment":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/8437/commits"},"statuses":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/c71a5ac261a5b85eaba852cafef72de7addafec9"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"pattisdr"}}