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.
This commit is contained in:
@@ -7,19 +7,24 @@ module Avatarable
|
||||
included do
|
||||
has_one_attached :avatar
|
||||
validate :acceptable_avatar, if: -> { avatar.changed? }
|
||||
after_save :fetch_avatar_from_gravatar
|
||||
end
|
||||
|
||||
def avatar_url
|
||||
return url_for(avatar.representation(resize: '250x250')) if avatar.attached? && avatar.representable?
|
||||
|
||||
if [SuperAdmin, User, Contact].include?(self.class) && email.present?
|
||||
hash = Digest::MD5.hexdigest(email)
|
||||
return "https://www.gravatar.com/avatar/#{hash}?d=404"
|
||||
end
|
||||
|
||||
''
|
||||
end
|
||||
|
||||
def fetch_avatar_from_gravatar
|
||||
return unless saved_changes.key?(:email)
|
||||
return if email.blank?
|
||||
|
||||
# Incase avatar_url is supplied, we don't want to fetch avatar from gravatar
|
||||
# So we will wait for it to be processed
|
||||
Avatar::AvatarFromGravatarJob.set(wait: 30.seconds).perform_later(self, email)
|
||||
end
|
||||
|
||||
def acceptable_avatar
|
||||
return unless avatar.attached?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user