Store and retrieve avatars in/from LDAP exclusively
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
No need to keep them in two places at the same time. We can fetch them from LDAP whenever we want to do something with them.
This commit is contained in:
@@ -2,19 +2,10 @@ class User < ApplicationRecord
|
||||
include EmailValidatable
|
||||
|
||||
attr_accessor :display_name
|
||||
attr_accessor :avatar_new
|
||||
|
||||
serialize :preferences, UserPreferences
|
||||
|
||||
#
|
||||
# File attachments
|
||||
#
|
||||
|
||||
has_one_attached :avatar do |attachable|
|
||||
attachable.variant :small, resize_to_fill: [64, 64], convert: :jpeg
|
||||
attachable.variant :medium, resize_to_fill: [256, 256], convert: :jpeg
|
||||
attachable.variant :large, resize_to_fill: [512, 512], convert: :jpeg
|
||||
end
|
||||
|
||||
#
|
||||
# Relations
|
||||
#
|
||||
@@ -167,9 +158,8 @@ class User < ApplicationRecord
|
||||
@display_name ||= ldap_entry[:display_name]
|
||||
end
|
||||
|
||||
|
||||
def avatar_base64(variant: :large)
|
||||
Base64.strict_encode64 avatar.variant(variant).processed.download
|
||||
def avatar
|
||||
@avatar_base64 ||= LdapManager::FetchAvatar.call(cn: cn, ou: ou)
|
||||
end
|
||||
|
||||
def services_enabled
|
||||
@@ -202,14 +192,14 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def acceptable_avatar
|
||||
return unless avatar.attached?
|
||||
return unless avatar_new.present?
|
||||
|
||||
if avatar.blob.byte_size > 1.megabyte
|
||||
if avatar_new.size > 1.megabyte
|
||||
errors.add(:avatar, "file size is too large")
|
||||
end
|
||||
|
||||
acceptable_types = ["image/jpeg", "image/png"]
|
||||
unless acceptable_types.include?(avatar.content_type)
|
||||
unless acceptable_types.include?(avatar_new.content_type)
|
||||
errors.add(:avatar, "must be a JPEG or PNG file")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user