From 875e588348984b6e8c7bb8c5cc847ff86e1f2db3 Mon Sep 17 00:00:00 2001 From: Andy Allan Date: Wed, 6 Dec 2017 18:56:27 +0000 Subject: [PATCH] Show issues based on all the users roles Previously you were prevented from seeing moderator issues if you were also an administrator. --- app/controllers/issues_controller.rb | 10 ++-------- app/views/issues/index.html.erb | 2 +- app/views/issues/show.html.erb | 6 +++++- test/system/issues_test.rb | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 3f28ec44f..b636b981c 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -6,7 +6,6 @@ class IssuesController < ApplicationController before_action :set_issues before_action :check_permission, :only => [:index, :show, :resolve, :open, :ignore, :comment] before_action :find_issue, :only => [:show, :resolve, :reopen, :ignore] - before_action :setup_user_role, :only => [:show, :index] def index if current_user.moderator? @@ -17,7 +16,7 @@ class IssuesController < ApplicationController @users = User.joins(:roles).where(:user_roles => { :role => "administrator" }) end - @issues = Issue.where(:assigned_role => @user_role) + @issues = Issue.where(:assigned_role => current_user.roles.map(&:role)) # If search if params[:search_by_user] && params[:search_by_user].present? @@ -55,7 +54,7 @@ class IssuesController < ApplicationController @read_reports = @issue.read_reports @unread_reports = @issue.unread_reports @comments = @issue.comments - @related_issues = @issue.reported_user.issues.where(:assigned_role => @user_role) + @related_issues = @issue.reported_user.issues.where(:assigned_role => current_user.roles.map(&:role)) @new_comment = IssueComment.new(:issue => @issue) end @@ -130,11 +129,6 @@ class IssuesController < ApplicationController @moderator_issues = %w[Changeset Note] end - def setup_user_role - # Get user role - @user_role = current_user.administrator? ? "administrator" : "moderator" - end - def check_if_updated if @issue.reportable && (@issue.ignored? || @issue.resolved?) && @issue.reportable.has_attribute?(:updated_by) && @issue.reportable.updated_at > @last_report.updated_at true diff --git a/app/views/issues/index.html.erb b/app/views/issues/index.html.erb index 521b53ec0..431158c38 100644 --- a/app/views/issues/index.html.erb +++ b/app/views/issues/index.html.erb @@ -1,5 +1,5 @@ <% content_for :heading do %> -

List of <%= @user_role %> issues:

+

List of issues:

<% end %> <%= form_tag(issues_path, :method => :get) do %> diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index e9d68d27c..5ce3bf168 100644 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -3,7 +3,11 @@

<%= report_type(@issue.reportable_type) %> : <%= reportable_url(@issue.reportable) %>

- <%= @issue.reports.count %> reports | First reported: <%= l @issue.created_at.to_datetime, :format => :friendly %> <%= "| Last resolved at #{l(@issue.resolved_at.to_datetime, :format =>:friendly)}" if @issue.resolved_at? %> <%= "| Last updated at #{l(@issue.updated_at.to_datetime, :format => :friendly)} by #{@issue.user_updated.display_name}" if @issue.user_updated %> + <%= @issue.assigned_role %> + | <%= @issue.reports.count %> reports + | First reported: <%= l @issue.created_at.to_datetime, :format => :friendly %> + <%= "| Last resolved at #{l(@issue.resolved_at.to_datetime, :format =>:friendly)}" if @issue.resolved_at? %> + <%= "| Last updated at #{l(@issue.updated_at.to_datetime, :format => :friendly)} by #{@issue.user_updated.display_name}" if @issue.user_updated %>

diff --git a/test/system/issues_test.rb b/test/system/issues_test.rb index 5ff1a5294..545074c30 100644 --- a/test/system/issues_test.rb +++ b/test/system/issues_test.rb @@ -78,4 +78,20 @@ class IssuesTest < ApplicationSystemTestCase issue.reload assert_equal "moderator", issue.assigned_role end + + def test_issue_index_with_multiple_roles + user1 = create(:user) + user2 = create(:user) + issue1 = create(:issue, :reportable => user1, :assigned_role => "administrator") + issue2 = create(:issue, :reportable => user2, :assigned_role => "moderator") + + user = create(:administrator_user) + create(:user_role, :user => user, :role => "moderator") + sign_in_as(user) + + visit issues_path + + assert page.has_link?(user1.display_name, :href => issue_path(issue1)) + assert page.has_link?(user2.display_name, :href => issue_path(issue2)) + end end -- 2.39.5