]> source.dussan.org Git - redmine.git/commitdiff
Fixed: private subprojects are listed on the issues view (#1217).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 14 May 2008 18:19:37 +0000 (18:19 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 14 May 2008 18:19:37 +0000 (18:19 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1432 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/query.rb
test/functional/issues_controller_test.rb

index d9a7208125e9923b69a27ad62876652c89b3ec5e..f25b5c401d3204e4e21bba669d7c128409e033be 100644 (file)
@@ -265,7 +265,7 @@ class Query < ActiveRecord::Base
 
   def statement
     # project/subprojects clause
-    clause = ''
+    project_clauses = []
     if project && !@project.active_children.empty?
       ids = [project.id]
       if has_filter?("subproject_id")
@@ -277,17 +277,16 @@ class Query < ActiveRecord::Base
           # main project only
         else
           # all subprojects
-          ids += project.active_children.collect{|p| p.id}
+          ids += project.child_ids
         end
       elsif Setting.display_subprojects_issues?
-        ids += project.active_children.collect{|p| p.id}
+        ids += project.child_ids
       end
-      clause << "#{Issue.table_name}.project_id IN (%s)" % ids.join(',')
+      project_clauses << "#{Issue.table_name}.project_id IN (%s)" % ids.join(',')
     elsif project
-      clause << "#{Issue.table_name}.project_id = %d" % project.id
-    else
-      clause << Project.visible_by(User.current)
+      project_clauses << "#{Issue.table_name}.project_id = %d" % project.id
     end
+    project_clauses <<  Project.visible_by(User.current)
     
     # filters clauses
     filters_clauses = []
@@ -365,8 +364,6 @@ class Query < ActiveRecord::Base
       filters_clauses << sql
     end if filters and valid?
     
-    clause << ' AND ' unless clause.empty?
-    clause << filters_clauses.join(' AND ') unless filters_clauses.empty?
-    clause
+    (project_clauses + filters_clauses).join(' AND ')
   end
 end
index a6d2ca6e3a641da239bcae0348a00987289a6eb4..c4389fedd54d32e61d5b684e3d8fc20571e2027b 100644 (file)
@@ -53,13 +53,44 @@ class IssuesControllerTest < Test::Unit::TestCase
     assert_template 'index.rhtml'
     assert_not_nil assigns(:issues)
     assert_nil assigns(:project)
+    assert_tag :tag => 'a', :content => /Can't print recipes/
+    assert_tag :tag => 'a', :content => /Subproject issue/
+    # private projects hidden
+    assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
+    assert_no_tag :tag => 'a', :content => /Issue on project 2/
   end
 
   def test_index_with_project
+    Setting.display_subprojects_issues = 0
     get :index, :project_id => 1
     assert_response :success
     assert_template 'index.rhtml'
     assert_not_nil assigns(:issues)
+    assert_tag :tag => 'a', :content => /Can't print recipes/
+    assert_no_tag :tag => 'a', :content => /Subproject issue/
+  end
+  
+  def test_index_with_project_and_subprojects
+    Setting.display_subprojects_issues = 1
+    get :index, :project_id => 1
+    assert_response :success
+    assert_template 'index.rhtml'
+    assert_not_nil assigns(:issues)
+    assert_tag :tag => 'a', :content => /Can't print recipes/
+    assert_tag :tag => 'a', :content => /Subproject issue/
+    assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
+  end
+  
+  def test_index_with_project_and_subprojects_should_show_private_subprojects
+    @request.session[:user_id] = 2
+    Setting.display_subprojects_issues = 1
+    get :index, :project_id => 1
+    assert_response :success
+    assert_template 'index.rhtml'
+    assert_not_nil assigns(:issues)
+    assert_tag :tag => 'a', :content => /Can't print recipes/
+    assert_tag :tag => 'a', :content => /Subproject issue/
+    assert_tag :tag => 'a', :content => /Issue of a private subproject/
   end
   
   def test_index_with_project_and_filter