]> source.dussan.org Git - redmine.git/commitdiff
Include issues asigned to user's groups when using "assigned to me" filter (#2964).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 31 Jul 2011 10:22:36 +0000 (10:22 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 31 Jul 2011 10:22:36 +0000 (10:22 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@6332 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
app/views/my/blocks/_issuesassignedtome.rhtml
test/unit/query_test.rb

index ad6a65eb5b985f613edbaf15447ce2268d5e8ee0..7aadce60cd00456bf51dca492e09b9b9b35519a8 100644 (file)
@@ -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+)$/
index 0666a473b9a8fd9f659b80c3c065e355bbca9a2f..28267d69af20ed736b6b4c6cc820434b3d6490d3 100644 (file)
@@ -1,7 +1,7 @@
-<h3><%=l(:label_assigned_to_me_issues)%> (<%= Issue.visible.open.count(:conditions => {:assigned_to_id => User.current.id})%>)</h3>
+<h3><%=l(:label_assigned_to_me_issues)%> (<%= Issue.visible.open.count(:conditions => {:assigned_to_id => ([User.current.id] + User.current.group_ids)})%>)</h3>
 
 <% 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") %>
index 9cba0cd642e55f08dbe7a34b4f4ac07aec09ef39..6ac713b155a1bd0ff40207744d99cea1ab59f8c9 100644 (file)
@@ -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']}})