demarches-normaliennes/app/models/concerns/user_find_by_concern.rb

24 lines
595 B
Ruby
Raw Normal View History

module UserFindByConcern
extend ActiveSupport::Concern
included do
def self.by_email(email)
find_by(users: { email: email })
end
def self.find_all_by_identifier(ids: [], emails: [])
find_all_by_identifier_with_emails(ids:, emails:).first
end
def self.find_all_by_identifier_with_emails(ids: [], emails: [])
2023-12-06 14:41:32 +01:00
valid_emails, invalid_emails = emails.partition { Devise.email_regexp.match?(_1) }
[
where(id: ids).or(where(users: { email: valid_emails })).distinct(:id),
valid_emails,
invalid_emails
]
end
end
end