account_warning.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: account_warnings
  5. #
  6. # id :bigint(8) not null, primary key
  7. # account_id :bigint(8)
  8. # target_account_id :bigint(8)
  9. # action :integer default("none"), not null
  10. # text :text default(""), not null
  11. # created_at :datetime not null
  12. # updated_at :datetime not null
  13. # report_id :bigint(8)
  14. # status_ids :string is an Array
  15. # overruled_at :datetime
  16. #
  17. class AccountWarning < ApplicationRecord
  18. enum action: {
  19. none: 0,
  20. disable: 1_000,
  21. mark_statuses_as_sensitive: 1_250,
  22. delete_statuses: 1_500,
  23. sensitive: 2_000,
  24. silence: 3_000,
  25. suspend: 4_000,
  26. }, _suffix: :action
  27. belongs_to :account, inverse_of: :account_warnings
  28. belongs_to :target_account, class_name: 'Account', inverse_of: :strikes
  29. belongs_to :report, optional: true
  30. has_one :appeal, dependent: :destroy, inverse_of: :strike
  31. scope :latest, -> { order(id: :desc) }
  32. scope :custom, -> { where.not(text: '') }
  33. scope :recent, -> { where('account_warnings.created_at >= ?', 3.months.ago) }
  34. def statuses
  35. Status.with_discarded.where(id: status_ids || [])
  36. end
  37. def overruled?
  38. overruled_at.present?
  39. end
  40. end