{"action":"created","comment":{"url":"https://api.github.com/repos/getsentry/sentry/pulls/comments/190711168","pull_request_review_id":123147639,"id":190711168,"diff_hunk":"@@ -67,22 +74,33 @@ def handle(self, request, signed_params):\n         # TODO(epurkhiser): We could do some fancy slack querying here to\n         # render a nice linking page with info about the user their linking.\n \n-        identity, created = Identity.objects.get_or_create(\n-            user=request.user,\n-            idp=idp,\n-            defaults={\n-                'external_id': params['slack_id'],\n-                'status': IdentityStatus.VALID,\n-            },\n-        )\n+        # Link the user with the identity. Handle the case where the user is linked to a\n+        # different identity or the identity is linked to a different user.\n+        id_by_user = Identity.objects.get(user=request.user, idp=idp)\n+        id_by_external_id = Identity.objects.get(external_id=params['slack_id'], idp=idp)\n \n-        if not created:\n+        if not id_by_user and not id_by_external_id:","path":"src/sentry/integrations/slack/link_identity.py","position":38,"original_position":38,"commit_id":"b4ebb29de59f2a629ceebb25a3d49f0749272289","original_commit_id":"b4ebb29de59f2a629ceebb25a3d49f0749272289","user":{"login":"EvanPurkhiser","id":1421724,"avatar_url":"https://avatars0.githubusercontent.com/u/1421724?v=4","gravatar_id":"","url":"https://api.github.com/users/EvanPurkhiser","html_url":"https://github.com/EvanPurkhiser","followers_url":"https://api.github.com/users/EvanPurkhiser/followers","following_url":"https://api.github.com/users/EvanPurkhiser/following{/other_user}","gists_url":"https://api.github.com/users/EvanPurkhiser/gists{/gist_id}","starred_url":"https://api.github.com/users/EvanPurkhiser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EvanPurkhiser/subscriptions","organizations_url":"https://api.github.com/users/EvanPurkhiser/orgs","repos_url":"https://api.github.com/users/EvanPurkhiser/repos","events_url":"https://api.github.com/users/EvanPurkhiser/events{/privacy}","received_events_url":"https://api.github.com/users/EvanPurkhiser/received_events","type":"User","site_admin":false},"body":"Ah, no it won't, you'd prob want to just delete in that case and create again","created_at":"2018-05-24T19:53:55Z","updated_at":"2018-05-24T19:53:55Z","html_url":"https://github.com/getsentry/sentry/pull/8540#discussion_r190711168","pull_request_url":"https://api.github.com/repos/getsentry/sentry/pulls/8540","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/comments/190711168"},"html":{"href":"https://github.com/getsentry/sentry/pull/8540#discussion_r190711168"},"pull_request":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/8540"}},"in_reply_to_id":190703254},"pull_request":{"url":"https://api.github.com/repos/getsentry/sentry/pulls/8540","id":190176371,"html_url":"https://github.com/getsentry/sentry/pull/8540","diff_url":"https://github.com/getsentry/sentry/pull/8540.diff","patch_url":"https://github.com/getsentry/sentry/pull/8540.patch","issue_url":"https://api.github.com/repos/getsentry/sentry/issues/8540","number":8540,"state":"open","locked":false,"title":"feat(identity): Double write/read IDP and Identity","user":{"login":"adhiraj","id":693121,"avatar_url":"https://avatars3.githubusercontent.com/u/693121?v=4","gravatar_id":"","url":"https://api.github.com/users/adhiraj","html_url":"https://github.com/adhiraj","followers_url":"https://api.github.com/users/adhiraj/followers","following_url":"https://api.github.com/users/adhiraj/following{/other_user}","gists_url":"https://api.github.com/users/adhiraj/gists{/gist_id}","starred_url":"https://api.github.com/users/adhiraj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adhiraj/subscriptions","organizations_url":"https://api.github.com/users/adhiraj/orgs","repos_url":"https://api.github.com/users/adhiraj/repos","events_url":"https://api.github.com/users/adhiraj/events{/privacy}","received_events_url":"https://api.github.com/users/adhiraj/received_events","type":"User","site_admin":false},"body":"Step 2 of removing org from IdentityProvider.\r\n\r\n- IDP get_or_create: replace with org=0\r\n- IDP get: try org=0 first, then actual org\r\n- Identity get_or_create: use whatever idp is given\r\n- Identity get: try org=0 first, then actual org\r\n\r\nThis makes it so that new objects are created with org=0, and after bulk migrating the data to org=0 (using a script) all reads will go through org=0 objects.","created_at":"2018-05-24T05:50:39Z","updated_at":"2018-05-24T19:53:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7e79d377615f74d88ea4601f0a068b10331d700c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/getsentry/sentry/pulls/8540/commits","review_comments_url":"https://api.github.com/repos/getsentry/sentry/pulls/8540/comments","review_comment_url":"https://api.github.com/repos/getsentry/sentry/pulls/comments{/number}","comments_url":"https://api.github.com/repos/getsentry/sentry/issues/8540/comments","statuses_url":"https://api.github.com/repos/getsentry/sentry/statuses/b4ebb29de59f2a629ceebb25a3d49f0749272289","head":{"label":"getsentry:migrate_fk2","ref":"migrate_fk2","sha":"b4ebb29de59f2a629ceebb25a3d49f0749272289","user":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars0.githubusercontent.com/u/1396951?v=4","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"repo":{"id":873328,"name":"sentry","full_name":"getsentry/sentry","owner":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars0.githubusercontent.com/u/1396951?v=4","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getsentry/sentry","description":"Sentry is cross-platform application monitoring, with a focus on error reporting.","fork":false,"url":"https://api.github.com/repos/getsentry/sentry","forks_url":"https://api.github.com/repos/getsentry/sentry/forks","keys_url":"https://api.github.com/repos/getsentry/sentry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getsentry/sentry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getsentry/sentry/teams","hooks_url":"https://api.github.com/repos/getsentry/sentry/hooks","issue_events_url":"https://api.github.com/repos/getsentry/sentry/issues/events{/number}","events_url":"https://api.github.com/repos/getsentry/sentry/events","assignees_url":"https://api.github.com/repos/getsentry/sentry/assignees{/user}","branches_url":"https://api.github.com/repos/getsentry/sentry/branches{/branch}","tags_url":"https://api.github.com/repos/getsentry/sentry/tags","blobs_url":"https://api.github.com/repos/getsentry/sentry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getsentry/sentry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getsentry/sentry/git/refs{/sha}","trees_url":"https://api.github.com/repos/getsentry/sentry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getsentry/sentry/statuses/{sha}","languages_url":"https://api.github.com/repos/getsentry/sentry/languages","stargazers_url":"https://api.github.com/repos/getsentry/sentry/stargazers","contributors_url":"https://api.github.com/repos/getsentry/sentry/contributors","subscribers_url":"https://api.github.com/repos/getsentry/sentry/subscribers","subscription_url":"https://api.github.com/repos/getsentry/sentry/subscription","commits_url":"https://api.github.com/repos/getsentry/sentry/commits{/sha}","git_commits_url":"https://api.github.com/repos/getsentry/sentry/git/commits{/sha}","comments_url":"https://api.github.com/repos/getsentry/sentry/comments{/number}","issue_comment_url":"https://api.github.com/repos/getsentry/sentry/issues/comments{/number}","contents_url":"https://api.github.com/repos/getsentry/sentry/contents/{+path}","compare_url":"https://api.github.com/repos/getsentry/sentry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getsentry/sentry/merges","archive_url":"https://api.github.com/repos/getsentry/sentry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getsentry/sentry/downloads","issues_url":"https://api.github.com/repos/getsentry/sentry/issues{/number}","pulls_url":"https://api.github.com/repos/getsentry/sentry/pulls{/number}","milestones_url":"https://api.github.com/repos/getsentry/sentry/milestones{/number}","notifications_url":"https://api.github.com/repos/getsentry/sentry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getsentry/sentry/labels{/name}","releases_url":"https://api.github.com/repos/getsentry/sentry/releases{/id}","deployments_url":"https://api.github.com/repos/getsentry/sentry/deployments","created_at":"2010-08-30T22:06:41Z","updated_at":"2018-05-24T19:31:02Z","pushed_at":"2018-05-24T19:30:39Z","git_url":"git://github.com/getsentry/sentry.git","ssh_url":"git@github.com:getsentry/sentry.git","clone_url":"https://github.com/getsentry/sentry.git","svn_url":"https://github.com/getsentry/sentry","homepage":"https://sentry.io","size":87089,"stargazers_count":16731,"watchers_count":16731,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1983,"mirror_url":null,"archived":false,"open_issues_count":804,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":1983,"open_issues":804,"watchers":16731,"default_branch":"master"}},"base":{"label":"getsentry:migrate_fk","ref":"migrate_fk","sha":"dce33dd1d01d4c0cdba6ed29cb552d5e1ce98d10","user":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars0.githubusercontent.com/u/1396951?v=4","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"repo":{"id":873328,"name":"sentry","full_name":"getsentry/sentry","owner":{"login":"getsentry","id":1396951,"avatar_url":"https://avatars0.githubusercontent.com/u/1396951?v=4","gravatar_id":"","url":"https://api.github.com/users/getsentry","html_url":"https://github.com/getsentry","followers_url":"https://api.github.com/users/getsentry/followers","following_url":"https://api.github.com/users/getsentry/following{/other_user}","gists_url":"https://api.github.com/users/getsentry/gists{/gist_id}","starred_url":"https://api.github.com/users/getsentry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/getsentry/subscriptions","organizations_url":"https://api.github.com/users/getsentry/orgs","repos_url":"https://api.github.com/users/getsentry/repos","events_url":"https://api.github.com/users/getsentry/events{/privacy}","received_events_url":"https://api.github.com/users/getsentry/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/getsentry/sentry","description":"Sentry is cross-platform application monitoring, with a focus on error reporting.","fork":false,"url":"https://api.github.com/repos/getsentry/sentry","forks_url":"https://api.github.com/repos/getsentry/sentry/forks","keys_url":"https://api.github.com/repos/getsentry/sentry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/getsentry/sentry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/getsentry/sentry/teams","hooks_url":"https://api.github.com/repos/getsentry/sentry/hooks","issue_events_url":"https://api.github.com/repos/getsentry/sentry/issues/events{/number}","events_url":"https://api.github.com/repos/getsentry/sentry/events","assignees_url":"https://api.github.com/repos/getsentry/sentry/assignees{/user}","branches_url":"https://api.github.com/repos/getsentry/sentry/branches{/branch}","tags_url":"https://api.github.com/repos/getsentry/sentry/tags","blobs_url":"https://api.github.com/repos/getsentry/sentry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/getsentry/sentry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/getsentry/sentry/git/refs{/sha}","trees_url":"https://api.github.com/repos/getsentry/sentry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/getsentry/sentry/statuses/{sha}","languages_url":"https://api.github.com/repos/getsentry/sentry/languages","stargazers_url":"https://api.github.com/repos/getsentry/sentry/stargazers","contributors_url":"https://api.github.com/repos/getsentry/sentry/contributors","subscribers_url":"https://api.github.com/repos/getsentry/sentry/subscribers","subscription_url":"https://api.github.com/repos/getsentry/sentry/subscription","commits_url":"https://api.github.com/repos/getsentry/sentry/commits{/sha}","git_commits_url":"https://api.github.com/repos/getsentry/sentry/git/commits{/sha}","comments_url":"https://api.github.com/repos/getsentry/sentry/comments{/number}","issue_comment_url":"https://api.github.com/repos/getsentry/sentry/issues/comments{/number}","contents_url":"https://api.github.com/repos/getsentry/sentry/contents/{+path}","compare_url":"https://api.github.com/repos/getsentry/sentry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/getsentry/sentry/merges","archive_url":"https://api.github.com/repos/getsentry/sentry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/getsentry/sentry/downloads","issues_url":"https://api.github.com/repos/getsentry/sentry/issues{/number}","pulls_url":"https://api.github.com/repos/getsentry/sentry/pulls{/number}","milestones_url":"https://api.github.com/repos/getsentry/sentry/milestones{/number}","notifications_url":"https://api.github.com/repos/getsentry/sentry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/getsentry/sentry/labels{/name}","releases_url":"https://api.github.com/repos/getsentry/sentry/releases{/id}","deployments_url":"https://api.github.com/repos/getsentry/sentry/deployments","created_at":"2010-08-30T22:06:41Z","updated_at":"2018-05-24T19:31:02Z","pushed_at":"2018-05-24T19:30:39Z","git_url":"git://github.com/getsentry/sentry.git","ssh_url":"git@github.com:getsentry/sentry.git","clone_url":"https://github.com/getsentry/sentry.git","svn_url":"https://github.com/getsentry/sentry","homepage":"https://sentry.io","size":87089,"stargazers_count":16731,"watchers_count":16731,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1983,"mirror_url":null,"archived":false,"open_issues_count":804,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause"},"forks":1983,"open_issues":804,"watchers":16731,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/8540"},"html":{"href":"https://github.com/getsentry/sentry/pull/8540"},"issue":{"href":"https://api.github.com/repos/getsentry/sentry/issues/8540"},"comments":{"href":"https://api.github.com/repos/getsentry/sentry/issues/8540/comments"},"review_comments":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/8540/comments"},"review_comment":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/getsentry/sentry/pulls/8540/commits"},"statuses":{"href":"https://api.github.com/repos/getsentry/sentry/statuses/b4ebb29de59f2a629ceebb25a3d49f0749272289"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"EvanPurkhiser"}}