BigW Consortium Gitlab

abuse_report.rb 774 Bytes
Newer Older
Stan Hu committed
1 2 3 4 5 6 7 8 9 10 11 12
# == Schema Information
#
# Table name: abuse_reports
#
#  id          :integer          not null, primary key
#  reporter_id :integer
#  user_id     :integer
#  message     :text
#  created_at  :datetime
#  updated_at  :datetime
#

13
class AbuseReport < ActiveRecord::Base
14
  belongs_to :reporter, class_name: 'User'
15 16 17 18 19
  belongs_to :user

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

22
  def remove_user(deleted_by:)
23
    user.block
24
    DeleteUserWorker.perform_async(deleted_by.id, user.id, delete_solo_owned_groups: true)
25 26
  end

27 28 29 30 31
  def notify
    return unless self.persisted?

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