diff --git a/app/controllers/ajax/report_controller.rb b/app/controllers/ajax/report_controller.rb index 3481f45b..6451bd6d 100644 --- a/app/controllers/ajax/report_controller.rb +++ b/app/controllers/ajax/report_controller.rb @@ -36,13 +36,7 @@ class Ajax::ReportController < AjaxController return end - 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] + current_user.report object, 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 69b48cfc..358606c3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -148,7 +148,13 @@ class User < ApplicationRecord def admin? = has_cached_role?(:administrator) # region stuff used for reporting/moderation - def report(object, target_user = nil, reason = nil) + def report(object, reason = nil) + target_user = if object.class.to_s == "User" + object + elsif object.respond_to? :user + object.user + end + 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, target_user_id: target_user&.id, reason:)