From 27a57e304d189cdee37de345c0c29542c33e8dec Mon Sep 17 00:00:00 2001 From: Andreas Nedbal Date: Tue, 23 Jan 2024 20:32:48 +0100 Subject: [PATCH] Set target user in report action --- app/controllers/ajax/report_controller.rb | 8 +++++++- app/models/user.rb | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/ajax/report_controller.rb b/app/controllers/ajax/report_controller.rb index 6451bd6d..3481f45b 100644 --- a/app/controllers/ajax/report_controller.rb +++ b/app/controllers/ajax/report_controller.rb @@ -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) diff --git a/app/models/user.rb b/app/models/user.rb index c6faa98c..69b48cfc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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