account_warning.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. normalizes :text, with: ->(text) { text.to_s }, apply_to_nil: true
  28. belongs_to :account, inverse_of: :account_warnings
  29. belongs_to :target_account, class_name: 'Account', inverse_of: :strikes
  30. belongs_to :report, optional: true
  31. has_one :appeal, dependent: :destroy, inverse_of: :strike
  32. scope :latest, -> { order(id: :desc) }
  33. scope :custom, -> { where.not(text: '') }
  34. scope :recent, -> { where('account_warnings.created_at >= ?', 3.months.ago) }
  35. def statuses
  36. Status.with_discarded.where(id: status_ids || [])
  37. end
  38. def overruled?
  39. overruled_at.present?
  40. end
  41. def to_log_human_identifier
  42. target_account.acct
  43. end
  44. end