Skip to content

Commit 284a142

Browse files
committed
Merge remote-tracking branch 'upstream/pull/5767'
2 parents be4644d + ff3d04a commit 284a142

File tree

8 files changed

+152
-8
lines changed

8 files changed

+152
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module Issues
2+
class ReportersController < ApplicationController
3+
layout "site"
4+
5+
before_action :authorize_web
6+
before_action :set_locale
7+
before_action :check_database_readable
8+
9+
authorize_resource :issue
10+
11+
def index
12+
@issue = Issue.visible_to(current_user).find(params[:issue_id])
13+
14+
user_ids = @issue.reports.order(:created_at => :desc).pluck(:user_id).uniq
15+
@unique_reporters = {
16+
@issue.id => {
17+
:count => user_ids.size,
18+
:users => User.in_order_of(:id, user_ids)
19+
}
20+
}
21+
22+
render :partial => "reporters", :locals => { :issue => @issue } if turbo_frame_request?
23+
rescue ActiveRecord::RecordNotFound
24+
redirect_to :controller => "/errors", :action => "not_found"
25+
end
26+
end
27+
end

app/controllers/issues_controller.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ def index
4545

4646
@issues, @newer_issues_id, @older_issues_id = get_page_items(@issues, :limit => @params[:limit])
4747

48+
@unique_reporters_limit = 3
4849
@unique_reporters = @issues.each_with_object({}) do |issue, reporters|
4950
user_ids = issue.reports.order(:created_at => :desc).pluck(:user_id).uniq
5051
reporters[issue.id] = {
5152
:count => user_ids.size,
52-
:users => User.in_order_of(:id, user_ids.first(3))
53+
:users => User.in_order_of(:id, user_ids.first(@unique_reporters_limit))
5354
}
5455
end
5556

app/views/issues/_page.html.erb

+1-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@
2525
<td><%= link_to reportable_title(issue.reportable), reportable_url(issue.reportable) %></td>
2626
<td><%= link_to issue.reported_user.display_name, issue.reported_user if issue.reported_user %></td>
2727
<td class="reporting_users text-truncate">
28-
<% @unique_reporters[issue.id][:users].each do |reporter| %>
29-
<%= link_to reporter.display_name, reporter, :class => "d-block text-truncate", :title => reporter.display_name %>
30-
<% end %>
31-
<% if @unique_reporters[issue.id][:count] > 3 %>
32-
<p class="m-0"><%= t ".more_reporters", :count => @unique_reporters[issue.id][:count] - 3 %></p>
33-
<% end %>
28+
<%= render :partial => "issues/reporters/reporters", :locals => { :issue => issue } %>
3429
</td>
3530
<td>
3631
<% if issue.user_updated %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<%= turbo_frame_tag "#{dom_id(issue)}_reporters", :data => { :turbo => false } do %>
2+
<% @unique_reporters[issue.id][:users].each do |reporter| %>
3+
<%= link_to reporter.display_name, reporter, :class => "d-block text-truncate", :title => reporter.display_name %>
4+
<% end %>
5+
<% if @unique_reporters_limit && @unique_reporters[issue.id][:count] > @unique_reporters_limit %>
6+
<p class="m-0">
7+
<%= link_to t(".more_reporters", :count => @unique_reporters[issue.id][:count] - @unique_reporters_limit),
8+
issue_reporters_path(issue),
9+
:class => "link-body-emphasis",
10+
:data => { :turbo => true } %>
11+
</p>
12+
<% end %>
13+
<% end %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<% content_for :heading do %>
2+
<h1><%= t ".title", :issue_id => @issue.id %></h1>
3+
<% end %>
4+
5+
<%= render :partial => "reporters", :locals => { :issue => @issue } %>

config/locales/en.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,6 @@ en:
15381538
reports_count:
15391539
one: "%{count} Report"
15401540
other: "%{count} Reports"
1541-
more_reporters: "and %{count} more"
15421541
reported_item: Reported Item
15431542
states:
15441543
ignored: Ignored
@@ -1581,6 +1580,11 @@ en:
15811580
reportable_title:
15821581
diary_comment: "%{entry_title}, comment #%{comment_id}"
15831582
note: "Note #%{note_id}"
1583+
reporters:
1584+
index:
1585+
title: "Issue #%{issue_id} Reporters"
1586+
reporters:
1587+
more_reporters: "and %{count} more"
15841588
issue_comments:
15851589
create:
15861590
comment_created: Your comment was successfully created

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@
375375
# issues and reports
376376
resources :issues do
377377
resources :comments, :controller => :issue_comments
378+
resources :reporters, :module => :issues, :only => :index
378379
member do
379380
post "resolve"
380381
post "assign"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
require "test_helper"
2+
3+
module Issues
4+
class DataControllerTest < ActionDispatch::IntegrationTest
5+
##
6+
# test all routes which lead to this controller
7+
def test_routes
8+
assert_routing(
9+
{ :path => "/issues/1/reporters", :method => :get },
10+
{ :controller => "issues/reporters", :action => "index", :issue_id => "1" }
11+
)
12+
end
13+
14+
def test_index_missing_issue_as_moderator
15+
session_for(create(:moderator_user))
16+
get issue_reporters_path(999111)
17+
18+
assert_redirected_to :controller => "/errors", :action => :not_found
19+
end
20+
21+
def test_index_missing_issue_as_administrator
22+
session_for(create(:administrator_user))
23+
get issue_reporters_path(999111)
24+
25+
assert_redirected_to :controller => "/errors", :action => :not_found
26+
end
27+
28+
def test_index_assigned_to_moderator_as_unauthorized
29+
issue = create(:issue, :assigned_role => "moderator")
30+
31+
get issue_reporters_path(issue)
32+
33+
assert_redirected_to login_path(:referer => issue_reporters_path(issue))
34+
end
35+
36+
def test_index_assigned_to_moderator_as_regular_user
37+
issue = create(:issue, :assigned_role => "moderator")
38+
39+
session_for(create(:user))
40+
get issue_reporters_path(issue)
41+
42+
assert_redirected_to :controller => "/errors", :action => :forbidden
43+
end
44+
45+
def test_index_assigned_to_moderator_as_administrator
46+
issue = create(:issue, :assigned_role => "moderator")
47+
48+
session_for(create(:administrator_user))
49+
get issue_reporters_path(issue)
50+
51+
assert_redirected_to :controller => "/errors", :action => :not_found
52+
end
53+
54+
def test_index_assigned_to_moderator_as_moderator
55+
issue = create(:issue, :assigned_role => "moderator")
56+
57+
session_for(create(:moderator_user))
58+
get issue_reporters_path(issue)
59+
60+
assert_response :success
61+
end
62+
63+
def test_index_assigned_to_administrator_as_unauthorized
64+
issue = create(:issue, :assigned_role => "administrator")
65+
66+
get issue_reporters_path(issue)
67+
68+
assert_redirected_to login_path(:referer => issue_reporters_path(issue))
69+
end
70+
71+
def test_index_assigned_to_administrator_as_regular_user
72+
issue = create(:issue, :assigned_role => "administrator")
73+
74+
session_for(create(:user))
75+
get issue_reporters_path(issue)
76+
77+
assert_redirected_to :controller => "/errors", :action => :forbidden
78+
end
79+
80+
def test_index_assigned_to_administrator_as_moderator
81+
issue = create(:issue, :assigned_role => "administrator")
82+
83+
session_for(create(:moderator_user))
84+
get issue_reporters_path(issue)
85+
86+
assert_redirected_to :controller => "/errors", :action => :not_found
87+
end
88+
89+
def test_index_assigned_to_administrator_as_administrator
90+
issue = create(:issue, :assigned_role => "administrator")
91+
92+
session_for(create(:administrator_user))
93+
get issue_reporters_path(issue)
94+
95+
assert_response :success
96+
end
97+
end
98+
end

0 commit comments

Comments
 (0)