From 7c2a3dc57d3d628354f35ef886df1051e6b7a7e3 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 15 Mar 2011 16:00:39 +0000 Subject: [PATCH] Adds Issue#visible_condition to build issue visibility statement. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5141 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/issue.rb | 7 ++++++- app/models/query.rb | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 92ab64a8..08d97bcd 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -60,7 +60,7 @@ class Issue < ActiveRecord::Base validates_numericality_of :estimated_hours, :allow_nil => true named_scope :visible, lambda {|*args| { :include => :project, - :conditions => Project.allowed_to_condition(args.first || User.current, :view_issues) } } + :conditions => Issue.visible_condition(args.first || User.current) } } named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status @@ -86,6 +86,11 @@ class Issue < ActiveRecord::Base after_save :reschedule_following_issues, :update_nested_set_attributes, :update_parent_attributes, :create_journal after_destroy :update_parent_attributes + # Returns a SQL conditions string used to find all issues visible by the specified user + def self.visible_condition(user, options={}) + Project.allowed_to_condition(user, :view_issues, options) + end + # Returns true if usr or current user is allowed to view the issue def visible?(usr=nil) (usr || User.current).allowed_to?(:view_issues, self.project) diff --git a/app/models/query.rb b/app/models/query.rb index 1772d68f..a74e16d8 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -411,7 +411,7 @@ class Query < ActiveRecord::Base elsif project project_clauses << "#{Project.table_name}.id = %d" % project.id end - project_clauses << Project.allowed_to_condition(User.current, :view_issues) + project_clauses << Issue.visible_condition(User.current) project_clauses.join(' AND ') end