Set target user in report action
This commit is contained in:
parent
ab442db40b
commit
27a57e304d
|
@ -36,7 +36,13 @@ class Ajax::ReportController < AjaxController
|
|||
return
|
||||
end
|
||||
|
||||
current_user.report object, params[:reason]
|
||||
target_user = if object.class.to_s == "User"
|
||||
object
|
||||
elsif object.respond_to? :user
|
||||
object.user
|
||||
end
|
||||
|
||||
current_user.report object, target_user, params[:reason]
|
||||
|
||||
@response[:status] = :okay
|
||||
@response[:message] = t(".success", parameter: params[:type].titleize)
|
||||
|
|
|
@ -148,10 +148,10 @@ class User < ApplicationRecord
|
|||
def admin? = has_cached_role?(:administrator)
|
||||
|
||||
# region stuff used for reporting/moderation
|
||||
def report(object, reason = nil)
|
||||
existing = Report.find_by(type: "Reports::#{object.class}", target_id: object.id, user_id: id, deleted: false)
|
||||
def report(object, target_user = nil, reason = nil)
|
||||
existing = Report.find_by(type: "Reports::#{object.class}", target_id: object.id, user_id: id, target_user_id: target_user&.id, deleted: false)
|
||||
if existing.nil?
|
||||
Report.create(type: "Reports::#{object.class}", target_id: object.id, user_id: id, reason:)
|
||||
Report.create(type: "Reports::#{object.class}", target_id: object.id, user_id: id, target_user_id: target_user&.id, reason:)
|
||||
elsif !reason.nil? && reason.length.positive?
|
||||
existing.append_reason(reason)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue