2018-07-25 05:30:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-08-06 08:03:27 -04:00
|
|
|
class AbuseReport < ActiveRecord::Base
|
2016-10-06 17:17:11 -04:00
|
|
|
include CacheMarkdownField
|
|
|
|
|
|
|
|
cache_markdown_field :message, pipeline: :single_line
|
|
|
|
|
2015-09-29 12:08:55 -04:00
|
|
|
belongs_to :reporter, class_name: 'User'
|
2015-08-06 08:03:27 -04:00
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
validates :reporter, presence: true
|
|
|
|
validates :user, presence: true
|
|
|
|
validates :message, presence: true
|
2016-01-16 16:25:35 -05:00
|
|
|
validates :user_id, uniqueness: { message: 'has already been reported' }
|
2016-01-04 18:59:42 -05:00
|
|
|
|
2016-10-06 17:17:11 -04:00
|
|
|
# For CacheMarkdownField
|
|
|
|
alias_method :author, :reporter
|
|
|
|
|
2016-03-12 07:11:30 -05:00
|
|
|
def remove_user(deleted_by:)
|
2017-06-02 09:18:24 -04:00
|
|
|
user.delete_async(deleted_by: deleted_by, params: { hard_delete: true })
|
2016-01-12 20:48:16 -05:00
|
|
|
end
|
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
def notify
|
|
|
|
return unless self.persisted?
|
|
|
|
|
|
|
|
AbuseReportMailer.notify(self.id).deliver_later
|
|
|
|
end
|
2015-08-06 08:03:27 -04:00
|
|
|
end
|