mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 06:25:15 +08:00
parent
22001b3c50
commit
e117deb2ba
|
@ -72,7 +72,7 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
|
|||
credentials: auth_token[:credentials] || {},
|
||||
extra: auth_token[:extra] || {}
|
||||
)
|
||||
retrieve_avatar(result.user, auth_token[:info][:image])
|
||||
retrieve_avatar(result.user, auth_token.dig(:info, :image))
|
||||
end
|
||||
|
||||
result.email_valid = true if result.email
|
||||
|
@ -94,7 +94,7 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
|
|||
def after_create_account(user, auth)
|
||||
data = auth[:extra_data]
|
||||
create_association!(data.merge(user: user))
|
||||
retrieve_avatar(user, data&.[]("info")&.[]("image"))
|
||||
retrieve_avatar(user, data.dig(:info, :image))
|
||||
end
|
||||
|
||||
def retrieve_avatar(user, url)
|
||||
|
|
|
@ -114,6 +114,40 @@ describe Auth::ManagedAuthenticator do
|
|||
expect(result.user.id).to eq(user.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe "avatar on update" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let!(:associated) { UserAssociatedAccount.create!(user: user, provider_name: 'myauth', provider_uid: "1234") }
|
||||
|
||||
it "schedules the job upon update correctly" do
|
||||
# No image supplied, do not schedule
|
||||
expect { result = authenticator.after_authenticate(hash) }
|
||||
.to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(0)
|
||||
|
||||
# Image supplied, schedule
|
||||
expect { result = authenticator.after_authenticate(hash.deep_merge(info: { image: "https://some.domain/image.jpg" })) }
|
||||
.to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(1)
|
||||
|
||||
# User already has profile picture, don't schedule
|
||||
user.user_avatar = Fabricate(:user_avatar, custom_upload: Fabricate(:upload))
|
||||
user.save!
|
||||
expect { result = authenticator.after_authenticate(hash.deep_merge(info: { image: "https://some.domain/image.jpg" })) }
|
||||
.to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "avatar on create" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
it "doesn't schedule with no image" do
|
||||
expect { result = authenticator.after_create_account(user, extra_data: hash) }
|
||||
.to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(0)
|
||||
end
|
||||
|
||||
it "schedules with image" do
|
||||
expect { result = authenticator.after_create_account(user, extra_data: hash.deep_merge(info: { image: "https://some.domain/image.jpg" })) }
|
||||
.to change { Jobs::DownloadAvatarFromUrl.jobs.count }.by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'description_for_user' do
|
||||
|
|
Loading…
Reference in New Issue
Block a user