Chatwoot/db/migrate/20220712145440_sync_gravatar_for_existing_avatarables.rb
Sojan Jose 6a6a37a67b
chore: Ability to Disable Gravatars (#5027)
fixes: #3853

- Introduced DISABLE_GRAVATAR Global Config, which will stop chatwoot from making API requests to gravatar
- Cleaned up avatar-related logic and centralized it into the avatarable concern
- Added specs for the missing cases
- Added migration for existing installations to move the avatar to attachment, rather than making the API that results in 404.
2022-07-21 19:27:12 +02:00

26 lines
661 B
Ruby

class SyncGravatarForExistingAvatarables < ActiveRecord::Migration[6.1]
def change
return if GlobalConfigService.load('DISABLE_GRAVATAR', '').present?
sync_user_avatars
sync_contact_avatars
end
private
def sync_user_avatars
::User.find_in_batches do |users_batch|
users_batch.each do |user|
Avatar::AvatarFromGravatarJob.perform_later(user, user.email)
end
end
end
def sync_contact_avatars
::Contact.where.not(email: nil).find_in_batches do |contacts_batch|
contacts_batch.each do |contact|
Avatar::AvatarFromGravatarJob.perform_later(contact, contact.email)
end
end
end
end