2020-01-07 17:29:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Avatarable
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
include Rails.application.routes.url_helpers
|
|
|
|
|
|
|
|
included do
|
|
|
|
has_one_attached :avatar
|
2022-01-27 00:01:41 +00:00
|
|
|
validate :acceptable_avatar, if: -> { avatar.changed? }
|
2022-07-21 17:27:12 +00:00
|
|
|
after_save :fetch_avatar_from_gravatar
|
2020-01-07 17:29:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def avatar_url
|
2020-11-13 14:26:30 +00:00
|
|
|
return url_for(avatar.representation(resize: '250x250')) if avatar.attached? && avatar.representable?
|
|
|
|
|
|
|
|
''
|
2020-01-07 17:29:17 +00:00
|
|
|
end
|
chore: Security Improvements to the API (#2893)
- Devise auth tokens are reset on password update
- Avatar attachment file type is limited to jpeg,gif and png
- Avatar attachment file size is limited to 15 mb
- Widget Message attachments are limited to types ['image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'image/tiff', 'application/pdf', 'audio/mpeg', 'video/mp4', 'audio/ogg', 'text/csv']
- Widget Message attachments are limited to 40Mb size limit.
2021-09-01 09:38:05 +00:00
|
|
|
|
2022-07-21 17:27:12 +00:00
|
|
|
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
|
|
|
|
|
chore: Security Improvements to the API (#2893)
- Devise auth tokens are reset on password update
- Avatar attachment file type is limited to jpeg,gif and png
- Avatar attachment file size is limited to 15 mb
- Widget Message attachments are limited to types ['image/png', 'image/jpeg', 'image/gif', 'image/bmp', 'image/tiff', 'application/pdf', 'audio/mpeg', 'video/mp4', 'audio/ogg', 'text/csv']
- Widget Message attachments are limited to 40Mb size limit.
2021-09-01 09:38:05 +00:00
|
|
|
def acceptable_avatar
|
|
|
|
return unless avatar.attached?
|
|
|
|
|
|
|
|
errors.add(:avatar, 'is too big') if avatar.byte_size > 15.megabytes
|
|
|
|
|
|
|
|
acceptable_types = ['image/jpeg', 'image/png', 'image/gif'].freeze
|
|
|
|
errors.add(:avatar, 'filetype not supported') unless acceptable_types.include?(avatar.content_type)
|
|
|
|
end
|
2020-01-07 17:29:17 +00:00
|
|
|
end
|