Read about our upcoming Code of Conduct on this issue

abuse_report.rb 690 Bytes
Newer Older
1
class AbuseReport < ActiveRecord::Base
2
3
4
5
  include CacheMarkdownField

  cache_markdown_field :message, pipeline: :single_line

6
  belongs_to :reporter, class_name: 'User'
7
8
9
10
11
  belongs_to :user

  validates :reporter, presence: true
  validates :user, presence: true
  validates :message, presence: true
12
  validates :user_id, uniqueness: { message: 'has already been reported' }
Robert Speicher's avatar
Robert Speicher committed
13

14
15
16
  # For CacheMarkdownField
  alias_method :author, :reporter

17
  def remove_user(deleted_by:)
18
    user.block
19
    DeleteUserWorker.perform_async(deleted_by.id, user.id, delete_solo_owned_groups: true)
20
21
  end

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

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