Read about our upcoming Code of Conduct on this issue

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

3
class AbuseReport < ApplicationRecord
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' }
Robert Speicher's avatar
Robert Speicher committed
15

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

19
  def remove_user(deleted_by:)
Nick Thomas's avatar
Nick Thomas committed
20
    user.delete_async(deleted_by: deleted_by, params: { hard_delete: true })
21
22
  end

Robert Speicher's avatar
Robert Speicher committed
23
24
25
26
27
  def notify
    return unless self.persisted?

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