]> source.dussan.org Git - redmine.git/commitdiff
Fixed: cross-project issue list should not show issues of projects for which the...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 25 Sep 2008 18:51:03 +0000 (18:51 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 25 Sep 2008 18:51:03 +0000 (18:51 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1907 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
app/models/query.rb
lib/redmine/access_control.rb
test/fixtures/enabled_modules.yml
test/functional/issues_controller_test.rb
test/unit/lib/redmine/access_control_test.rb [new file with mode: 0644]

index e40af9967f99673c49b310a835bbff166671dba5..d283e269cbc12670d013d5947bbdfd9117a4dfae 100644 (file)
@@ -108,6 +108,12 @@ class Project < ActiveRecord::Base
   def self.allowed_to_condition(user, permission, options={})
     statements = []
     base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}"
+    if perm = Redmine::AccessControl.permission(permission)
+      unless perm.project_module.nil?
+        # If the permission belongs to a project module, make sure the module is enabled
+        base_statement << " AND EXISTS (SELECT em.id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}' AND em.project_id=#{Project.table_name}.id)"
+      end
+    end
     if options[:project]
       project_statement = "#{Project.table_name}.id = #{options[:project].id}"
       project_statement << " OR #{Project.table_name}.parent_id = #{options[:project].id}" if options[:with_subprojects]
index f8c2361455f6b3295d039984e0a8e032a89c51eb..ac8777721b912c855b6485b8b25c9a537435c961 100644 (file)
@@ -277,7 +277,7 @@ class Query < ActiveRecord::Base
     elsif project
       project_clauses << "#{Project.table_name}.id = %d" % project.id
     end
-    project_clauses <<  Project.visible_by(User.current)
+    project_clauses <<  Project.allowed_to_condition(User.current, :view_issues)
     project_clauses.join(' AND ')
   end
 
index f5b25f277cbe67084751264d3a0831734d6281e1..25cf63d613f1eddd4ae6e2e13cf479b9f7d7cf9c 100644 (file)
@@ -30,8 +30,15 @@ module Redmine
         @permissions
       end
       
+      # Returns the permission of given name or nil if it wasn't found
+      # Argument should be a symbol
+      def permission(name)
+        permissions.detect {|p| p.name == name}
+      end
+      
+      # Returns the actions that are allowed by the permission of given name
       def allowed_actions(permission_name)
-        perm = @permissions.detect {|p| p.name == permission_name}
+        perm = permission(permission_name)
         perm ? perm.actions : []
       end
       
@@ -94,6 +101,7 @@ module Redmine
             @actions << "#{controller}/#{actions}"
           end
         end
+        @actions.flatten!
       end
       
       def public?
index da63bad5d93ceccb4f294fd60bb1642a21b24776..6639dfa1addd6fdafabd449528986e351fe170b7 100644 (file)
@@ -43,4 +43,16 @@ enabled_modules_011:
   name: issue_tracking
   project_id: 2
   id: 11
+enabled_modules_012: 
+  name: time_tracking
+  project_id: 3
+  id: 12
+enabled_modules_013: 
+  name: issue_tracking
+  project_id: 3
+  id: 13
+enabled_modules_014: 
+  name: issue_tracking
+  project_id: 5
+  id: 14
   
\ No newline at end of file
index 9e2a9ffd52b33d168fd74cd382a8b4da326ab044..517aee3a85cc15e623af9af24e9ce3d264536579 100644 (file)
@@ -62,6 +62,17 @@ class IssuesControllerTest < Test::Unit::TestCase
     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_should_not_list_issues_when_module_disabled
+    EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
+    get :index
+    assert_response :success
+    assert_template 'index.rhtml'
+    assert_not_nil assigns(:issues)
+    assert_nil assigns(:project)
+    assert_no_tag :tag => 'a', :content => /Can't print recipes/
+    assert_tag :tag => 'a', :content => /Subproject issue/
+  end
 
   def test_index_with_project
     Setting.display_subprojects_issues = 0
diff --git a/test/unit/lib/redmine/access_control_test.rb b/test/unit/lib/redmine/access_control_test.rb
new file mode 100644 (file)
index 0000000..5dd87d2
--- /dev/null
@@ -0,0 +1,49 @@
+# Redmine - project management software
+# Copyright (C) 2006-2008  Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+require File.dirname(__FILE__) + '/../../../test_helper'
+
+class Redmine::AccessControlTest < Test::Unit::TestCase
+  
+  def setup
+    @access_module = Redmine::AccessControl
+  end
+  
+  def test_permissions
+    perms = @access_module.permissions
+    assert perms.is_a?(Array)
+    assert perms.first.is_a?(Redmine::AccessControl::Permission)
+  end
+  
+  def test_module_permission
+    perm = @access_module.permission(:view_issues)
+    assert perm.is_a?(Redmine::AccessControl::Permission)
+    assert_equal :view_issues, perm.name
+    assert_equal :issue_tracking, perm.project_module
+    assert perm.actions.is_a?(Array)
+    assert perm.actions.include?('issues/index')
+  end
+  
+  def test_no_module_permission
+    perm = @access_module.permission(:edit_project)
+    assert perm.is_a?(Redmine::AccessControl::Permission)
+    assert_equal :edit_project, perm.name
+    assert_nil perm.project_module
+    assert perm.actions.is_a?(Array)
+    assert perm.actions.include?('projects/settings')
+  end
+end