]> source.dussan.org Git - redmine.git/commitdiff
Merged r15750 (#23655).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 31 Aug 2016 16:52:01 +0000 (16:52 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 31 Aug 2016 16:52:01 +0000 (16:52 +0000)
git-svn-id: http://svn.redmine.org/redmine/branches/3.2-stable@15766 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/project.rb
test/unit/issue_test.rb

index 197f45ec1e2d7998818d8c2a69c2bce08fa15bc6..ee24056edf51e4f8d3b2f9fcc6faa5efae367d36 100644 (file)
@@ -197,7 +197,9 @@ class Project < ActiveRecord::Base
         if role.allowed_to?(permission)
           s = "#{Project.table_name}.is_public = #{connection.quoted_true}"
           if user.id
-            s = "(#{s} AND #{Project.table_name}.id NOT IN (SELECT project_id FROM #{Member.table_name} WHERE user_id = #{user.id}))"
+            group = role.anonymous? ? Group.anonymous : Group.non_member
+            principal_ids = [user.id, group.id].compact
+            s = "(#{s} AND #{Project.table_name}.id NOT IN (SELECT project_id FROM #{Member.table_name} WHERE user_id IN (#{principal_ids.join(',')})))"
           end
           statement_by_role[role] = s
         end
index 510b0eb3b8c3db7db8b905731200eb1d6ca81d21..318f31156a0f4cb8b4c291ba6d4ed009b16c9e47 100644 (file)
@@ -319,6 +319,28 @@ class IssueTest < ActiveSupport::TestCase
     assert_equal false, Issue.where(:project_id => 1).first.visible?(user)
   end
 
+  def test_visible_scope_with_custom_non_member_role_having_restricted_permission
+    role = Role.generate!(:permissions => [:view_project])
+    assert Role.non_member.has_permission?(:view_issues)
+    user = User.generate!
+    Member.create!(:principal => Group.non_member, :project_id => 1, :roles => [role])
+
+    issues = Issue.visible(user).to_a
+    assert issues.any?
+    assert_nil issues.detect {|issue| issue.project_id == 1}
+  end
+
+  def test_visible_scope_with_custom_non_member_role_having_extended_permission
+    role = Role.generate!(:permissions => [:view_project, :view_issues])
+    Role.non_member.remove_permission!(:view_issues)
+    user = User.generate!
+    Member.create!(:principal => Group.non_member, :project_id => 1, :roles => [role])
+
+    issues = Issue.visible(user).to_a
+    assert issues.any?
+    assert_not_nil issues.detect {|issue| issue.project_id == 1}
+  end
+
   def test_visible_scope_for_member_with_groups_should_return_assigned_issues
     user = User.find(8)
     assert user.groups.any?