2020-04-19 00:59:18 +02:00
|
|
|
class Report < ApplicationRecord
|
2014-12-27 14:35:09 +01:00
|
|
|
belongs_to :user
|
2024-01-23 19:57:26 +01:00
|
|
|
belongs_to :target_user, class_name: "User", optional: true
|
2014-12-27 14:35:09 +01:00
|
|
|
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
|
2014-12-27 14:35:09 +01:00
|
|
|
end
|