闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
868 B

  1. # frozen_string_literal: true
  2. class User < ApplicationRecord
  3. include Settings::Extend
  4. devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable
  5. belongs_to :account, inverse_of: :user
  6. accepts_nested_attributes_for :account
  7. validates :account, presence: true
  8. validates :locale, inclusion: I18n.available_locales.map(&:to_s), unless: 'locale.nil?'
  9. validates :email, email: true
  10. 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') }
  11. scope :recent, -> { order('id desc') }
  12. scope :admins, -> { where(admin: true) }
  13. def send_devise_notification(notification, *args)
  14. devise_mailer.send(notification, self, *args).deliver_later
  15. end
  16. end