abuse_report.rb 692 Bytes
Newer Older
1 2
# frozen_string_literal: true

3
class AbuseReport < ActiveRecord::Base
4 5 6 7
  include CacheMarkdownField

  cache_markdown_field :message, pipeline: :single_line

8
  belongs_to :reporter, class_name: 'User'
9 10 11 12 13
  belongs_to :user

  validates :reporter, presence: true
  validates :user, presence: true
  validates :message, presence: true
14
  validates :user_id, uniqueness: { message: 'has already been reported' }
15

16 17 18
  # For CacheMarkdownField
  alias_method :author, :reporter

19
  def remove_user(deleted_by:)
20
    user.delete_async(deleted_by: deleted_by, params: { hard_delete: true })
21 22
  end

23 24 25 26 27
  def notify
    return unless self.persisted?

    AbuseReportMailer.notify(self.id).deliver_later
  end
28
end