mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 05:43:44 +08:00
67dec38f31
It is possible that a user could exist without an email, if so we should not enqueue a job to download their gravatar. This commit resolves this error that can occur: ``` Job exception: undefined method `email' for nil:NilClass /var/www/discourse/app/models/user.rb:1204:in `email' /var/www/discourse/app/jobs/regular/update_gravatar.rb:12:in `execute' ``` This commit also fixes the original spec which actually was wrong. The job never enqueued in the original spec and so the gravatar was never actually updated and the test was checking if the two values were the same, but they were both null and never updated, so of course they were the same! A new test has also been added to make sure the gravatar job isn't enqueued when a user's email is missing.
22 lines
541 B
Ruby
22 lines
541 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class UpdateGravatar < ::Jobs::Base
|
|
|
|
sidekiq_options queue: 'low'
|
|
|
|
def execute(args)
|
|
user = User.find_by(id: args[:user_id])
|
|
avatar = UserAvatar.find_by(id: args[:avatar_id])
|
|
|
|
if user && avatar && avatar.user&.id == user.id && user.primary_email.present?
|
|
avatar.update_gravatar!
|
|
if !user.uploaded_avatar_id && avatar.gravatar_upload_id
|
|
user.update_column(:uploaded_avatar_id, avatar.gravatar_upload_id)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|