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

Eugen Rochko's avatar
Eugen Rochko committed
3
class User < ApplicationRecord
Eugen Rochko's avatar
Eugen Rochko committed
4
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
5

Eugen Rochko's avatar
Eugen Rochko committed
6
  belongs_to :account, inverse_of: :user
7
  accepts_nested_attributes_for :account
8

Eugen Rochko's avatar
Eugen Rochko committed
9
  validates :account, presence: true
10

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

  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
18
end