From: Jean-Philippe Lang Date: Sun, 31 Jul 2011 10:22:36 +0000 (+0000) Subject: Include issues asigned to user's groups when using "assigned to me" filter (#2964). X-Git-Tag: 1.3.0~1611 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7f77744e86e0db306083a43a2da4b8ab508da7e1;p=redmine.git Include issues asigned to user's groups when using "assigned to me" filter (#2964). git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6332 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/query.rb b/app/models/query.rb index ad6a65eb5..7aadce60c 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -487,7 +487,14 @@ class Query < ActiveRecord::Base # "me" value subsitution if %w(assigned_to_id author_id watcher_id).include?(field) - v.push(User.current.logged? ? User.current.id.to_s : "0") if v.delete("me") + if v.delete("me") + if User.current.logged? + v.push(User.current.id.to_s) + v += User.current.group_ids.map(&:to_s) if field == 'assigned_to_id' + else + v.push("0") + end + end end if field =~ /^cf_(\d+)$/ diff --git a/app/views/my/blocks/_issuesassignedtome.rhtml b/app/views/my/blocks/_issuesassignedtome.rhtml index 0666a473b..28267d69a 100644 --- a/app/views/my/blocks/_issuesassignedtome.rhtml +++ b/app/views/my/blocks/_issuesassignedtome.rhtml @@ -1,7 +1,7 @@ -

<%=l(:label_assigned_to_me_issues)%> (<%= Issue.visible.open.count(:conditions => {:assigned_to_id => User.current.id})%>)

+

<%=l(:label_assigned_to_me_issues)%> (<%= Issue.visible.open.count(:conditions => {:assigned_to_id => ([User.current.id] + User.current.group_ids)})%>)

<% assigned_issues = Issue.visible.open.find(:all, - :conditions => {:assigned_to_id => User.current.id}, + :conditions => {:assigned_to_id => ([User.current.id] + User.current.group_ids)}, :limit => 10, :include => [ :status, :project, :tracker, :priority ], :order => "#{IssuePriority.table_name}.position DESC, #{Issue.table_name}.updated_on DESC") %> diff --git a/test/unit/query_test.rb b/test/unit/query_test.rb index 9cba0cd64..6ac713b15 100644 --- a/test/unit/query_test.rb +++ b/test/unit/query_test.rb @@ -336,6 +336,24 @@ class QueryTest < ActiveSupport::TestCase find_issues_with_query(query) end + def test_filter_assigned_to_me + user = User.find(2) + group = Group.find(10) + User.current = user + i1 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => user) + i2 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => group) + i3 = Issue.generate!(:project_id => 1, :tracker_id => 1, :assigned_to => Group.find(11)) + group.users << user + + query = Query.new(:name => '_', :filters => { 'assigned_to_id' => {:operator => '=', :values => ['me']}}) + result = query.issues + assert_equal Issue.visible.all(:conditions => {:assigned_to_id => ([2] + user.reload.group_ids)}).sort_by(&:id), result.sort_by(&:id) + + assert result.include?(i1) + assert result.include?(i2) + assert !result.include?(i3) + end + def test_filter_watched_issues User.current = User.find(1) query = Query.new(:name => '_', :filters => { 'watcher_id' => {:operator => '=', :values => ['me']}})