]> source.dussan.org Git - redmine.git/commitdiff
Merged r3927 from trunk.
authorEric Davis <edavis@littlestreamsoftware.com>
Thu, 19 Aug 2010 04:32:25 +0000 (04:32 +0000)
committerEric Davis <edavis@littlestreamsoftware.com>
Thu, 19 Aug 2010 04:32:25 +0000 (04:32 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/branches/1.0-stable@3977 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
test/unit/query_test.rb

index fd7aa3477bb17d0f1253540b0ff8af9244e30a24..b1f784528d069ffc37049c88ff9e811513df3590 100644 (file)
@@ -219,6 +219,12 @@ class Query < ActiveRecord::Base
         @available_filters["fixed_version_id"] = { :type => :list_optional, :order => 7, :values => system_shared_versions.sort.collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s] } }
       end
       add_custom_fields_filters(IssueCustomField.find(:all, :conditions => {:is_filter => true, :is_for_all => true}))
+      # project filter
+      project_values = Project.all(:conditions => Project.visible_by(User.current), :order => 'lft').map do |p|
+        pre = (p.level > 0 ? ('--' * p.level + ' ') : '')
+        ["#{pre}#{p.name}",p.id.to_s]
+      end
+      @available_filters["project_id"] = { :type => :list, :order => 1, :values => project_values}
     end
     @available_filters
   end
index 4b11830e8f5989069f91a5197e9654c546cecfbd..12ab5d93267fc42dd0dd9ab65358193f93329a19 100644 (file)
@@ -33,6 +33,15 @@ class QueryTest < ActiveSupport::TestCase
     assert query.available_filters['fixed_version_id'][:values].detect {|v| v.last == '2'}
   end
   
+  def test_project_filter_in_global_queries
+    query = Query.new(:project => nil, :name => '_')
+    project_filter = query.available_filters["project_id"]
+    assert_not_nil project_filter
+    project_ids = project_filter[:values].map{|p| p[1]}
+    assert project_ids.include?("1")  #public project
+    assert !project_ids.include?("2") #private project user cannot see
+  end
+  
   def find_issues_with_query(query)
     Issue.find :all,
       :include => [ :assigned_to, :status, :tracker, :project, :priority ],