mirror of
https://github.com/discourse/discourse.git
synced 2025-03-23 06:15:41 +08:00
FIX: when associating Github account disassociate others
There are some cases where an email floats from one GitHub account to another if this happens just take over the Github mapping record
This commit is contained in:
parent
59ce11d10c
commit
45f01e637b
@ -86,7 +86,12 @@ class Auth::GithubAuthenticator < Auth::Authenticator
|
||||
if !!candidate[:verified] && (user = User.find_by_email(candidate[:email]))
|
||||
result.email = candidate[:email]
|
||||
result.email_valid = !!candidate[:verified]
|
||||
GithubUserInfo.create(
|
||||
|
||||
GithubUserInfo
|
||||
.where('user_id = ? OR github_user_id = ?', user.id, github_user_id)
|
||||
.destroy_all
|
||||
|
||||
GithubUserInfo.create!(
|
||||
user_id: user.id,
|
||||
screen_name: screen_name,
|
||||
github_user_id: github_user_id
|
||||
|
@ -84,6 +84,35 @@ describe Auth::GithubAuthenticator do
|
||||
expect(result.email).to eq("john@example.com")
|
||||
end
|
||||
|
||||
it 'should not error out if user already has a different old github account attached' do
|
||||
|
||||
# There is a rare case where an end user had
|
||||
# 2 different github accounts and moved emails between the 2
|
||||
|
||||
GithubUserInfo.create!(user_id: user.id, screen_name: 'bob', github_user_id: 100)
|
||||
|
||||
hash = {
|
||||
extra: {
|
||||
all_emails: [{
|
||||
email: user.email,
|
||||
primary: false,
|
||||
verified: true,
|
||||
}]
|
||||
},
|
||||
info: {
|
||||
email: "john@example.com",
|
||||
nickname: "john",
|
||||
name: "John Bob",
|
||||
},
|
||||
uid: "1001"
|
||||
}
|
||||
|
||||
result = authenticator.after_authenticate(hash)
|
||||
|
||||
expect(result.user.id).to eq(user.id)
|
||||
expect(GithubUserInfo.where(user_id: user.id).pluck(:github_user_id)).to eq([1001])
|
||||
end
|
||||
|
||||
it 'will not authenticate for already existing users with an unverified email' do
|
||||
hash = {
|
||||
extra: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user