]> git.openstreetmap.org Git - rails.git/commitdiff
Show issues based on all the users roles
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 6 Dec 2017 18:56:27 +0000 (18:56 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 6 Dec 2017 18:56:27 +0000 (18:56 +0000)
Previously you were prevented from seeing moderator issues if you
were also an administrator.

app/controllers/issues_controller.rb
app/views/issues/index.html.erb
app/views/issues/show.html.erb
test/system/issues_test.rb

index 3f28ec44f1626a2917672430ace78ea221259315..b636b981c21543555f9cf8ffaba5b1338bceed28 100644 (file)
@@ -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 :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?
 
   def index
     if current_user.moderator?
@@ -17,7 +16,7 @@ class IssuesController < ApplicationController
       @users = User.joins(:roles).where(:user_roles => { :role => "administrator" })
     end
 
       @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?
 
     # 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
     @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
 
     @new_comment = IssueComment.new(:issue => @issue)
   end
 
@@ -130,11 +129,6 @@ class IssuesController < ApplicationController
     @moderator_issues = %w[Changeset Note]
   end
 
     @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
   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
index 521b53ec0e09c23716b755b4d9a0bd308e1732f0..431158c38a19017ba1a2a51d4a18d4af64d2e4b6 100644 (file)
@@ -1,5 +1,5 @@
 <% content_for :heading do %>
 <% content_for :heading do %>
-  <h1>List of <%= @user_role %> issues:</h1>
+  <h1>List of issues:</h1>
 <% end %>
 
 <%= form_tag(issues_path, :method => :get) do %>
 <% end %>
 
 <%= form_tag(issues_path, :method => :get) do %>
index e9d68d27cefca0c7dbb99d5a23f6666988c139bf..5ce3bf168d82b714bb7d176d24209a8919e9df91 100644 (file)
@@ -3,7 +3,11 @@
 <p><%= report_type(@issue.reportable_type) %> : <%= reportable_url(@issue.reportable) %></p>
 <p class="deemphasize">
   <small>
 <p><%= report_type(@issue.reportable_type) %> : <%= reportable_url(@issue.reportable) %></p>
 <p class="deemphasize">
   <small>
-    <%= @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 %>
   </small>
 </p>
 <p>
   </small>
 </p>
 <p>
index 5ff1a529425c74c349247a93d73aa47d695fb270..545074c3040c223113b128915c795ffc3096a916 100644 (file)
@@ -78,4 +78,20 @@ class IssuesTest < ApplicationSystemTestCase
     issue.reload
     assert_equal "moderator", issue.assigned_role
   end
     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
 end