Validate avatar images

Closes #3097
This commit is contained in:
Tom Hughes 2021-02-16 17:37:18 +00:00
parent 80f576a29b
commit 3c4f32a760
2 changed files with 7 additions and 0 deletions

View file

@ -104,6 +104,8 @@ class User < ApplicationRecord
validates :preferred_editor, :inclusion => Editors::ALL_EDITORS, :allow_nil => true
validates :auth_uid, :unless => proc { |u| u.auth_provider.nil? },
:uniqueness => { :scope => :auth_provider }
validates :avatar, :if => proc { |u| u.attachment_changes["avatar"] },
:image => true
validates_email_format_of :email, :if => proc { |u| u.email_changed? }
validates_email_format_of :new_email, :allow_blank => true, :if => proc { |u| u.new_email_changed? }

View file

@ -0,0 +1,5 @@
class ImageValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, " must be an image") unless value.image?
end
end