2020-04-19 00:59:18 +02:00
|
|
|
class Report < ApplicationRecord
|
2014-12-27 14:35:09 +01:00
|
|
|
belongs_to :user
|
|
|
|
validates :type, presence: true
|
|
|
|
validates :target_id, presence: true
|
|
|
|
validates :user_id, presence: true
|
|
|
|
|
|
|
|
def target
|
|
|
|
type.sub('Reports::', '').constantize.where(id: target_id).first
|
|
|
|
end
|
2014-12-28 23:26:16 +01:00
|
|
|
|
2023-01-02 11:16:47 +01:00
|
|
|
def append_reason(new_reason)
|
|
|
|
if reason.nil?
|
|
|
|
update(reason: new_reason)
|
|
|
|
else
|
|
|
|
update(reason: [reason || "", new_reason].join("\n"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-03 22:43:37 +01:00
|
|
|
class << self
|
|
|
|
include CursorPaginatable
|
|
|
|
|
|
|
|
define_cursor_paginator :cursored_reports, :list_reports
|
|
|
|
define_cursor_paginator :cursored_reports_of_type, :list_reports_of_type
|
|
|
|
|
|
|
|
def list_reports(options = {})
|
|
|
|
self.where(options.merge!(deleted: false)).reverse_order
|
|
|
|
end
|
|
|
|
|
|
|
|
def list_reports_of_type(type, options = {})
|
|
|
|
self.where(options.merge!(deleted: false)).where('LOWER(type) = ?', "reports::#{type}").reverse_order
|
|
|
|
end
|
|
|
|
end
|
2014-12-27 14:35:09 +01:00
|
|
|
end
|