diff --git a/app/models/moderation_report.rb b/app/models/moderation_report.rb index bb6191dde..200311dd9 100644 --- a/app/models/moderation_report.rb +++ b/app/models/moderation_report.rb @@ -113,10 +113,20 @@ class ModerationReport < ApplicationRecord end end + def self.received_by(user) + where(model: Comment.where(creator: user)).or(where(model: ForumPost.where(creator: user))).or(where(model: Dmail.received.where(from: user))) + end + def self.search(params) q = search_attributes(params, :id, :created_at, :updated_at, :reason, :creator, :model, :status) q = q.text_attribute_matches(:reason, params[:reason_matches]) + if params[:recipient_id].present? + q = q.received_by(User.search(id: params[:recipient_id])) + elsif params[:recipient_name].present? + q = q.received_by(User.search(name_matches: params[:recipient_name])) + end + q.apply_default_order(params) end diff --git a/app/views/moderation_reports/index.html.erb b/app/views/moderation_reports/index.html.erb index 0a6e68ea8..36cde1029 100644 --- a/app/views/moderation_reports/index.html.erb +++ b/app/views/moderation_reports/index.html.erb @@ -3,6 +3,7 @@

Moderation reports

<%= search_form_for(moderation_reports_path) do |f| %> + <%= f.input :recipient_name, label: "Reported user", input_html: { value: params[:search][:recipient_name], "data-autocomplete": "user" } %> <%= f.input :creator_name, label: "Reporter", input_html: { value: params[:search][:creator_name], "data-autocomplete": "user" } %> <%= f.input :reason_matches, label: "Reason", input_html: { value: params[:search][:reason_matches] } %> <%= f.input :model_id, label: "ID", input_html: { value: params[:search][:model_id] } %> @@ -33,6 +34,7 @@ <% t.column "Reported user" do |report| %> <%= link_to_user report.reported_user %> + <%= link_to "ยป", moderation_reports_path(search: { recipient_name: report.reported_user.name }) %> <% end %> <% t.column "Reporter" do |report| %> diff --git a/app/views/users/_statistics.html.erb b/app/views/users/_statistics.html.erb index 85ffc986b..9d1eb3e2c 100644 --- a/app/views/users/_statistics.html.erb +++ b/app/views/users/_statistics.html.erb @@ -240,6 +240,16 @@ <%= presenter.feedbacks(self) %> + <% if policy(ModerationReport).can_see_moderation_reports? %> + + Mod Reports + + <%= link_to "received:#{ModerationReport.received_by(user).count}", moderation_reports_path(search: { recipient_name: user.name }) %> + <%= link_to "submitted:#{ModerationReport.where(creator: user).count}", moderation_reports_path(search: { creator_name: user.name }) %> + + + <% end %> + <% if policy(UserNameChangeRequest.new(user: user)).show? %> <% user.user_name_change_requests.visible(CurrentUser.user).tap do |changes| %> <% if changes.present? %>