{"action":"created","comment":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/24358586","id":24358586,"diff_hunk":"@@ -0,0 +1,270 @@\n+import time\n+\n+import mendeley\n+from modularodm import fields\n+\n+\n+from website import settings\n+from website.addons.base import AddonNodeSettingsBase\n+from website.addons.base import AddonUserSettingsBase\n+from website.citations.models import Citation\n+from website.citations.models import CitationList\n+from website.oauth.models import ExternalProvider\n+\n+from .api import APISession\n+\n+\n+class AddonMendeleyUserSettings(AddonUserSettingsBase):\n+\n+    def _get_connected_accounts(self):\n+        \"\"\"Get user's connected Mendeley accounts\"\"\"\n+        return [\n+            x for x in self.owner.external_accounts if x.provider == 'mendeley'\n+        ]\n+\n+    def to_json(self, user):\n+        rv = super(AddonMendeleyUserSettings, self).to_json(user)\n+        rv['accounts'] = [\n+            {\n+                'id': account._id,\n+                'provider_id': account.provider_id,\n+                'display_name': account.display_name,\n+            } for account in self._get_connected_accounts()\n+        ]\n+        return rv\n+\n+\n+class AddonMendeleyNodeSettings(AddonNodeSettingsBase):\n+    external_account = fields.ForeignField('externalaccount',\n+                                           backref='connected')\n+\n+    mendeley_list_id = fields.StringField()\n+\n+    # Keep track of all user settings that have been associated with this\n+    #   instance. This is so OAuth grants can be checked, even if the grant is\n+    #   not currently being used.\n+    associated_user_settings = fields.AbstractForeignField(list=True)\n+\n+    _api = None\n+\n+    @property\n+    def api(self):\n+        \"\"\"authenticated ExternalProvider instance\"\"\"\n+        if self._api is None:\n+            self._api = Mendeley()\n+            self._api.account = self.external_account\n+        return self._api\n+\n+    def grant_oauth_access(self, user, external_account, metadata=None):\n+        \"\"\"Grant OAuth access, updates metadata on user settings\n+\n+        :param User user:\n+        :param ExternalAccount external_account:\n+        :param dict metadata:\n+        \"\"\"\n+        user_settings = user.get_addon('mendeley')\n+\n+        # associate the user settings with this node's settings\n+        if user_settings not in self.associated_user_settings:","path":"website/addons/mendeley/model.py","position":68,"original_position":68,"commit_id":"970afda984bfa28f11dd090fe5fa14828edcc90f","original_commit_id":"970afda984bfa28f11dd090fe5fa14828edcc90f","user":{"login":"jmcarp","id":1633460,"avatar_url":"https://avatars.githubusercontent.com/u/1633460?v=3","gravatar_id":"","url":"https://api.github.com/users/jmcarp","html_url":"https://github.com/jmcarp","followers_url":"https://api.github.com/users/jmcarp/followers","following_url":"https://api.github.com/users/jmcarp/following{/other_user}","gists_url":"https://api.github.com/users/jmcarp/gists{/gist_id}","starred_url":"https://api.github.com/users/jmcarp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmcarp/subscriptions","organizations_url":"https://api.github.com/users/jmcarp/orgs","repos_url":"https://api.github.com/users/jmcarp/repos","events_url":"https://api.github.com/users/jmcarp/events{/privacy}","received_events_url":"https://api.github.com/users/jmcarp/received_events","type":"User","site_admin":false},"body":"We're appending to `self.associated_user_settings` without calling `self.save()`. I'm guessing this works because something else is saving `self` indirectly, but it might be better to call it explicitly, or explain in a comment why we don't have to.","created_at":"2015-02-09T19:45:36Z","updated_at":"2015-02-09T19:45:36Z","html_url":"https://github.com/CenterForOpenScience/osf.io/pull/1730#discussion_r24358586","pull_request_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1730","_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/24358586"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/1730#discussion_r24358586"},"pull_request":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1730"}}},"pull_request":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1730","id":28827950,"html_url":"https://github.com/CenterForOpenScience/osf.io/pull/1730","diff_url":"https://github.com/CenterForOpenScience/osf.io/pull/1730.diff","patch_url":"https://github.com/CenterForOpenScience/osf.io/pull/1730.patch","issue_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/1730","number":1730,"state":"open","locked":false,"title":"[feature] [WIP] Mendeley","user":{"login":"lyndsysimon","id":131414,"avatar_url":"https://avatars.githubusercontent.com/u/131414?v=3","gravatar_id":"","url":"https://api.github.com/users/lyndsysimon","html_url":"https://github.com/lyndsysimon","followers_url":"https://api.github.com/users/lyndsysimon/followers","following_url":"https://api.github.com/users/lyndsysimon/following{/other_user}","gists_url":"https://api.github.com/users/lyndsysimon/gists{/gist_id}","starred_url":"https://api.github.com/users/lyndsysimon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyndsysimon/subscriptions","organizations_url":"https://api.github.com/users/lyndsysimon/orgs","repos_url":"https://api.github.com/users/lyndsysimon/repos","events_url":"https://api.github.com/users/lyndsysimon/events{/privacy}","received_events_url":"https://api.github.com/users/lyndsysimon/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-02-06T17:51:31Z","updated_at":"2015-02-09T19:45:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7c0beb3355764793937325f4716b20efad1506e1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1730/commits","review_comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1730/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/1730/comments","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/970afda984bfa28f11dd090fe5fa14828edcc90f","head":{"label":"lyndsysimon:feature/citations-staged-merge-2","ref":"feature/citations-staged-merge-2","sha":"970afda984bfa28f11dd090fe5fa14828edcc90f","user":{"login":"lyndsysimon","id":131414,"avatar_url":"https://avatars.githubusercontent.com/u/131414?v=3","gravatar_id":"","url":"https://api.github.com/users/lyndsysimon","html_url":"https://github.com/lyndsysimon","followers_url":"https://api.github.com/users/lyndsysimon/followers","following_url":"https://api.github.com/users/lyndsysimon/following{/other_user}","gists_url":"https://api.github.com/users/lyndsysimon/gists{/gist_id}","starred_url":"https://api.github.com/users/lyndsysimon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyndsysimon/subscriptions","organizations_url":"https://api.github.com/users/lyndsysimon/orgs","repos_url":"https://api.github.com/users/lyndsysimon/repos","events_url":"https://api.github.com/users/lyndsysimon/events{/privacy}","received_events_url":"https://api.github.com/users/lyndsysimon/received_events","type":"User","site_admin":false},"repo":{"id":26919430,"name":"osf.io","full_name":"lyndsysimon/osf.io","owner":{"login":"lyndsysimon","id":131414,"avatar_url":"https://avatars.githubusercontent.com/u/131414?v=3","gravatar_id":"","url":"https://api.github.com/users/lyndsysimon","html_url":"https://github.com/lyndsysimon","followers_url":"https://api.github.com/users/lyndsysimon/followers","following_url":"https://api.github.com/users/lyndsysimon/following{/other_user}","gists_url":"https://api.github.com/users/lyndsysimon/gists{/gist_id}","starred_url":"https://api.github.com/users/lyndsysimon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyndsysimon/subscriptions","organizations_url":"https://api.github.com/users/lyndsysimon/orgs","repos_url":"https://api.github.com/users/lyndsysimon/repos","events_url":"https://api.github.com/users/lyndsysimon/events{/privacy}","received_events_url":"https://api.github.com/users/lyndsysimon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lyndsysimon/osf.io","description":"Facilitating Open Science","fork":true,"url":"https://api.github.com/repos/lyndsysimon/osf.io","forks_url":"https://api.github.com/repos/lyndsysimon/osf.io/forks","keys_url":"https://api.github.com/repos/lyndsysimon/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lyndsysimon/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lyndsysimon/osf.io/teams","hooks_url":"https://api.github.com/repos/lyndsysimon/osf.io/hooks","issue_events_url":"https://api.github.com/repos/lyndsysimon/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/lyndsysimon/osf.io/events","assignees_url":"https://api.github.com/repos/lyndsysimon/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/lyndsysimon/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/lyndsysimon/osf.io/tags","blobs_url":"https://api.github.com/repos/lyndsysimon/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lyndsysimon/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lyndsysimon/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/lyndsysimon/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lyndsysimon/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/lyndsysimon/osf.io/languages","stargazers_url":"https://api.github.com/repos/lyndsysimon/osf.io/stargazers","contributors_url":"https://api.github.com/repos/lyndsysimon/osf.io/contributors","subscribers_url":"https://api.github.com/repos/lyndsysimon/osf.io/subscribers","subscription_url":"https://api.github.com/repos/lyndsysimon/osf.io/subscription","commits_url":"https://api.github.com/repos/lyndsysimon/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/lyndsysimon/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/lyndsysimon/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/lyndsysimon/osf.io/issues/comments/{number}","contents_url":"https://api.github.com/repos/lyndsysimon/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/lyndsysimon/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lyndsysimon/osf.io/merges","archive_url":"https://api.github.com/repos/lyndsysimon/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lyndsysimon/osf.io/downloads","issues_url":"https://api.github.com/repos/lyndsysimon/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/lyndsysimon/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/lyndsysimon/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/lyndsysimon/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lyndsysimon/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/lyndsysimon/osf.io/releases{/id}","created_at":"2014-11-20T15:49:38Z","updated_at":"2014-11-20T15:49:42Z","pushed_at":"2015-02-06T19:48:16Z","git_url":"git://github.com/lyndsysimon/osf.io.git","ssh_url":"git@github.com:lyndsysimon/osf.io.git","clone_url":"https://github.com/lyndsysimon/osf.io.git","svn_url":"https://github.com/lyndsysimon/osf.io","homepage":"http://osf.io","size":76316,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"CenterForOpenScience:develop","ref":"develop","sha":"3912ffdb0c44f0fbcc0b504c7d4f206ff67841ef","user":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","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,"name":"osf.io","full_name":"CenterForOpenScience/osf.io","owner":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars.githubusercontent.com/u/3344584?v=3","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}","created_at":"2013-05-21T15:53:37Z","updated_at":"2015-02-09T17:29:27Z","pushed_at":"2015-02-09T17:29:27Z","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":"http://osf.io","size":82088,"stargazers_count":69,"watchers_count":69,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":44,"mirror_url":null,"open_issues_count":338,"forks":44,"open_issues":338,"watchers":69,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1730"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/1730"},"issue":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/1730"},"comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/1730/comments"},"review_comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/1730/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/1730/commits"},"statuses":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/970afda984bfa28f11dd090fe5fa14828edcc90f"}}}}