From 1a23bfa1ecae74ea47dfb76eadd4e6bc856fed70 Mon Sep 17 00:00:00 2001 From: nertc Date: Wed, 29 Jan 2025 12:39:46 +0400 Subject: [PATCH] Show reporting user on issues screen --- app/assets/stylesheets/common.scss | 8 +++++ app/controllers/issues_controller.rb | 9 ++++++ app/views/issues/_page.html.erb | 9 ++++++ config/locales/en.yml | 2 ++ test/system/issues_test.rb | 44 ++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+) diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 098370689..92b9f7240 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -816,6 +816,14 @@ tr.turn { } } +/* Rules for the issues page */ + +.issues.issues-index { + td.reporter_users { + max-width: 5rem; + } +} + /* Rules for the account confirmation page */ .accounts-terms-show { diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 5cedb3c70..b3f5434b6 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -44,6 +44,15 @@ class IssuesController < ApplicationController end @issues, @newer_issues_id, @older_issues_id = get_page_items(@issues, :limit => @params[:limit]) + + @unique_reporters = @issues.each_with_object({}) do |issue, reporters| + user_ids = issue.reports.order(:created_at => :desc).map(&:user_id).uniq + reporters[issue.id] = { + :count => user_ids.size, + :users => User.in_order_of(:id, user_ids.first(3)) + } + end + render :partial => "page" if turbo_frame_request_id == "pagination" end diff --git a/app/views/issues/_page.html.erb b/app/views/issues/_page.html.erb index f625f0e04..6b291e58d 100644 --- a/app/views/issues/_page.html.erb +++ b/app/views/issues/_page.html.erb @@ -13,6 +13,7 @@ <%= t ".reports" %> <%= t ".reported_item" %> <%= t ".reported_user" %> + <%= t ".reporter_users" %> <%= t ".last_updated" %> @@ -23,6 +24,14 @@ <%= link_to t(".reports_count", :count => issue.reports_count), issue %> <%= link_to reportable_title(issue.reportable), reportable_url(issue.reportable) %> <%= link_to issue.reported_user.display_name, issue.reported_user if issue.reported_user %> + + <% @unique_reporters[issue.id][:users].each do |reporter| %> + <%= link_to reporter.display_name, reporter, :class => "d-block text-truncate", :title => reporter.display_name %> + <% end %> + <% if @unique_reporters[issue.id][:count] > 3 %> +

<%= t ".more_reporters", :count => @unique_reporters[issue.id][:count] - 3 %>

+ <% end %> + <% if issue.user_updated %> <%= t ".last_updated_time_ago_user_html", :user => link_to(issue.user_updated.display_name, issue.user_updated), diff --git a/config/locales/en.yml b/config/locales/en.yml index 50c9cc754..2a9af16c6 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1509,9 +1509,11 @@ en: reports: Reports last_updated: Last Updated last_updated_time_ago_user_html: "%{time_ago} by %{user}" + reporter_users: Reporter Users reports_count: one: "%{count} Report" other: "%{count} Reports" + more_reporters: "and %{count} more" reported_item: Reported Item states: ignored: Ignored diff --git a/test/system/issues_test.rb b/test/system/issues_test.rb index 327b888bc..a961ea80f 100644 --- a/test/system/issues_test.rb +++ b/test/system/issues_test.rb @@ -204,4 +204,48 @@ class IssuesTest < ApplicationSystemTestCase assert_no_content(/extra_#{n}[^\d]/i) end end + + def test_single_issue_reporters + sign_in_as(create(:moderator_user)) + issue = create(:issue, :assigned_role => "moderator") + issue.reports << create(:report, :user => create(:user, :display_name => "Test Name")) + + visit issues_path + assert_content issue.reported_user.display_name + assert_content issue.reports.first.user.display_name + end + + def test_multiple_issue_reporters + sign_in_as(create(:moderator_user)) + issue = create(:issue, :assigned_role => "moderator") + + create_list(:report, 5, :issue => issue) + + visit issues_path + 0.upto(1).each do |n| + assert_no_content issue.reports[n].user.display_name + end + 2.upto(4).each do |n| + assert_content issue.reports[n].user.display_name + end + end + + def test_ordering_issue_reporters + sign_in_as(create(:moderator_user)) + issue = create(:issue, :assigned_role => "moderator") + + create_list(:report, 5, :issue => issue) + + 4.downto(0).each do |n| + issue.reports << create(:report, :user => issue.reports[n].user) + end + + visit issues_path + 0.upto(2).each do |n| + assert_content issue.reports[n].user.display_name + end + 3.upto(4).each do |n| + assert_no_content issue.reports[n].user.display_name + end + end end -- 2.39.5