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 96e6857..d4e9a3b 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 4dc1637..f9a84ba 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 dd06885..d893a6e 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