FIX: Do not schedule avatar download if image is '' (#27687)

This commit is contained in:
Natalie Tay 2024-07-03 19:50:31 +08:00 committed by GitHub
parent f3130bc6d9
commit 751750c7f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -148,7 +148,7 @@ class Auth::ManagedAuthenticator < Auth::Authenticator
end end
def retrieve_avatar(user, url) def retrieve_avatar(user, url)
return unless user && url return unless user && url.present?
return if user.user_avatar.try(:custom_upload_id).present? return if user.user_avatar.try(:custom_upload_id).present?
Jobs.enqueue(:download_avatar_from_url, url: url, user_id: user.id, override_gravatar: false) Jobs.enqueue(:download_avatar_from_url, url: url, user_id: user.id, override_gravatar: false)
end end

View File

@ -293,6 +293,14 @@ RSpec.describe Auth::ManagedAuthenticator do
}.not_to change { Jobs::DownloadAvatarFromUrl.jobs.count } }.not_to change { Jobs::DownloadAvatarFromUrl.jobs.count }
end end
it "does not schedule if image is empty" do
association.info["image"] = ""
association.save!
expect {
authenticator.after_create_account(user, create_auth_result(extra_data: create_hash))
}.not_to change { Jobs::DownloadAvatarFromUrl.jobs.count }
end
it "schedules with image" do it "schedules with image" do
association.info["image"] = "https://some.domain/image.jpg" association.info["image"] = "https://some.domain/image.jpg"
association.save! association.save!