]> git.openstreetmap.org Git - rails.git/commitdiff
Only include issues visible to the current user in the count
authorTom Hughes <tom@compton.nu>
Sun, 17 Jun 2018 00:01:24 +0000 (01:01 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 17 Jun 2018 00:01:24 +0000 (01:01 +0100)
app/controllers/issues_controller.rb
app/helpers/issues_helper.rb
app/models/issue.rb

index 96e68573e8e8297421f83de57f583494e2cb9145..d4e9a3bdfa4bec2c7e745b200c67e52a307ff086 100644 (file)
@@ -15,7 +15,7 @@ class IssuesController < ApplicationController
     @issue_types.concat %w[DiaryEntry DiaryComment User] if current_user.administrator?
 
     @users = User.joins(:roles).where(:user_roles => { :role => current_user.roles.map(&:role) }).distinct
-    @issues = Issue.where(:assigned_role => current_user.roles.map(&:role))
+    @issues = Issue.visible_to(current_user)
 
     # If search
     if params[:search_by_user] && params[:search_by_user].present?
index 4dc1637de2cc00bb296570268eff97e22a85bd8e..f9a84ba7dd979bdc71fca2955f4eeafa6eb1f28d 100644 (file)
@@ -26,7 +26,7 @@ module IssuesHelper
   end
 
   def open_issues_count
-    count = Issue.open.limit(100).size
+    count = Issue.visible_to(current_user).open.limit(100).size
     if count > 99
       content_tag(:span, "99+", :class => "count-number")
     elsif count > 0
index dd068859a54dfb8bb8ded4abc4188605c9005a78..d893a6e3a67378296f5b1c70b192dfcaca3e68eb 100644 (file)
@@ -48,6 +48,7 @@ class Issue < ActiveRecord::Base
   before_validation :set_reported_user
 
   scope :with_status, ->(issue_status) { where(:status => statuses[issue_status]) }
+  scope :visible_to, ->(user) { where(:assigned_role => user.roles.map(&:role)) }
 
   def read_reports
     resolved_at.present? ? reports.where("updated_at < ?", resolved_at) : nil