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:)
|
2016-01-12 20:48:16 -05:00
|
|
|
user.block
|
2017-04-16 11:21:40 -04:00
|
|
|
DeleteUserWorker.perform_async(deleted_by.id, user.id, delete_solo_owned_groups: true, 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
|