diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-04-08 12:21:06 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2011-04-08 12:21:06 +0000 |
commit | fee9d605a353ad34487c0c353a73473b325d52fa (patch) | |
tree | 4dcb8d7f8f922a0a070c51d7d45a1e243eea4629 /app | |
parent | 3bc9972d5e42691cf68ce1edcd73f8d53d5cfe24 (diff) | |
download | redmine-fee9d605a353ad34487c0c353a73473b325d52fa.tar.gz redmine-fee9d605a353ad34487c0c353a73473b325d52fa.zip |
Adds visibility condition to Issue.by_* count methods.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5365 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/models/issue.rb | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 943626686..aca68b1ae 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -647,14 +647,16 @@ class Issue < ActiveRecord::Base def self.by_subproject(project) ActiveRecord::Base.connection.select_all("select s.id as status_id, s.is_closed as closed, - i.project_id as project_id, - count(i.id) as total + #{Issue.table_name}.project_id as project_id, + count(#{Issue.table_name}.id) as total from - #{Issue.table_name} i, #{IssueStatus.table_name} s + #{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s where - i.status_id=s.id - and i.project_id IN (#{project.descendants.active.collect{|p| p.id}.join(',')}) - group by s.id, s.is_closed, i.project_id") if project.descendants.active.any? + #{Issue.table_name}.status_id=s.id + and #{Issue.table_name}.project_id = #{Project.table_name}.id + and #{visible_condition(User.current, :project => project, :with_subprojects => true)} + and #{Issue.table_name}.project_id <> #{project.id} + group by s.id, s.is_closed, #{Issue.table_name}.project_id") if project.descendants.active.any? end # End ReportsController extraction @@ -864,20 +866,19 @@ class Issue < ActiveRecord::Base select_field = options.delete(:field) joins = options.delete(:joins) - where = "i.#{select_field}=j.id" + where = "#{Issue.table_name}.#{select_field}=j.id" ActiveRecord::Base.connection.select_all("select s.id as status_id, s.is_closed as closed, j.id as #{select_field}, - count(i.id) as total + count(#{Issue.table_name}.id) as total from - #{Issue.table_name} i, #{IssueStatus.table_name} s, #{joins} j + #{Issue.table_name}, #{Project.table_name}, #{IssueStatus.table_name} s, #{joins} j where - i.status_id=s.id + #{Issue.table_name}.status_id=s.id and #{where} - and i.project_id=#{project.id} + and #{Issue.table_name}.project_id=#{Project.table_name}.id + and #{visible_condition(User.current, :project => project)} group by s.id, s.is_closed, j.id") end - - end |