user.rb 698 Bytes
Newer Older
Eugen Rochko's avatar
Eugen Rochko committed
1
class User < ApplicationRecord
Eugen Rochko's avatar
Eugen Rochko committed
2
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
3

Eugen Rochko's avatar
Eugen Rochko committed
4
  belongs_to :account, inverse_of: :user
5
  accepts_nested_attributes_for :account
6

Eugen Rochko's avatar
Eugen Rochko committed
7
  validates :account, presence: true
8

9
  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
10
  scope :recent,   -> { order('id desc') }
11
  scope :admins,   -> { where(admin: true) }
12 13 14 15

  has_settings do |s|
    s.key :notification_emails, defaults: { follow: true, reblog: true, favourite: true, mention: true }
  end
Eugen Rochko's avatar
Eugen Rochko committed
16
end