user.rb 873 Bytes
Newer Older
1 2
# frozen_string_literal: true

Eugen Rochko's avatar
Eugen Rochko committed
3
class User < ApplicationRecord
4 5
  include RailsSettings::Extend

Eugen Rochko's avatar
Eugen Rochko committed
6
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
7

Eugen Rochko's avatar
Eugen Rochko committed
8
  belongs_to :account, inverse_of: :user
9
  accepts_nested_attributes_for :account
10

Eugen Rochko's avatar
Eugen Rochko committed
11
  validates :account, presence: true
Eugen Rochko's avatar
Eugen Rochko committed
12
  validates :locale, inclusion: I18n.available_locales.map(&:to_s), unless: 'locale.nil?'
13
  validates :email, email: true
14

15
  scope :prolific, -> { joins('inner join statuses on statuses.account_id = users.account_id').select('users.*, count(statuses.id) as statuses_count').group('users.id').order('statuses_count desc') }
Eugen Rochko's avatar
Eugen Rochko committed
16
  scope :recent,   -> { order('id desc') }
17
  scope :admins,   -> { where(admin: true) }
18

19 20 21
  def send_devise_notification(notification, *args)
    devise_mailer.send(notification, self, *args).deliver_later
  end
Eugen Rochko's avatar
Eugen Rochko committed
22
end