diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-02-01 20:07:01 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-02-01 20:07:01 +0000 |
commit | 2808adf99f44d1329b1c12c60ecdb6c4105fca5d (patch) | |
tree | d73a9d0ac58e0af04c8357037eccefad299e3569 /app/models | |
parent | 0154d7477b536387b7e50c441e6931027a596dd1 (diff) | |
download | redmine-2808adf99f44d1329b1c12c60ecdb6c4105fca5d.tar.gz redmine-2808adf99f44d1329b1c12c60ecdb6c4105fca5d.zip |
Adds members of subprojects in assignee and author filters (#10126).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8747 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/principal.rb | 10 | ||||
-rw-r--r-- | app/models/query.rb | 17 |
2 files changed, 20 insertions, 7 deletions
diff --git a/app/models/principal.rb b/app/models/principal.rb index d7814f595..77fe19fe0 100644 --- a/app/models/principal.rb +++ b/app/models/principal.rb @@ -33,6 +33,16 @@ class Principal < ActiveRecord::Base } } + # Principals that are members of a collection of projects + named_scope :member_of, lambda {|projects| + if projects.empty? + {:conditions => "1=0"} + else + ids = projects.map(&:id) + {:conditions => ["#{Principal.table_name}.status = 1 AND #{Principal.table_name}.id IN (SELECT DISTINCT user_id FROM #{Member.table_name} WHERE project_id IN (?))", ids]} + end + } + before_create :set_default_empty_values def name(formatter = nil) diff --git a/app/models/query.rb b/app/models/query.rb index 1cfa952ff..84ab868ff 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -232,11 +232,18 @@ class Query < ActiveRecord::Base principals = [] if project principals += project.principals.sort + unless project.leaf? + subprojects = project.descendants.visible.all + if subprojects.any? + @available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => subprojects.collect{|s| [s.name, s.id.to_s] } } + principals += Principal.member_of(subprojects) + end + end else all_projects = Project.visible.all if all_projects.any? # members of visible projects - principals += Principal.active.find(:all, :conditions => ["#{User.table_name}.id IN (SELECT DISTINCT user_id FROM members WHERE project_id IN (?))", all_projects.collect(&:id)]).sort + principals += Principal.member_of(all_projects) # project filter project_values = [] @@ -250,6 +257,8 @@ class Query < ActiveRecord::Base @available_filters["project_id"] = { :type => :list, :order => 1, :values => project_values} unless project_values.empty? end end + principals.uniq! + principals.sort! users = principals.select {|p| p.is_a?(User)} assigned_to_values = [] @@ -282,12 +291,6 @@ class Query < ActiveRecord::Base unless versions.empty? @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } } end - unless project.leaf? - subprojects = project.descendants.visible.all - unless subprojects.empty? - @available_filters["subproject_id"] = { :type => :list_subprojects, :order => 13, :values => subprojects.collect{|s| [s.name, s.id.to_s] } } - end - end add_custom_fields_filters(project.all_issue_custom_fields) else # global filters for cross project issue list |