summaryrefslogtreecommitdiffstats
path: root/test/unit/issue_test.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2016-06-06 09:41:50 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2016-06-06 09:41:50 +0000
commit6e68d008c4dc50f46585e30aabaa5bc9859bee0f (patch)
treedddbcaecd80051789282556982fad7270c2e5b9d /test/unit/issue_test.rb
parent7a974437e6414682d6b318a3b1130d728f51907a (diff)
downloadredmine-6e68d008c4dc50f46585e30aabaa5bc9859bee0f.tar.gz
redmine-6e68d008c4dc50f46585e30aabaa5bc9859bee0f.zip
Merged 15430, 15464 to 15469, 15475, 15476 (#285, #7839).
git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@15478 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/issue_test.rb')
-rw-r--r--test/unit/issue_test.rb153
1 files changed, 151 insertions, 2 deletions
diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb
index d7c7d231b..3b7391a3c 100644
--- a/test/unit/issue_test.rb
+++ b/test/unit/issue_test.rb
@@ -342,6 +342,69 @@ class IssueTest < ActiveSupport::TestCase
assert_include issue, issues
end
+ def test_visible_scope_for_member_with_limited_tracker_ids
+ role = Role.find(1)
+ role.set_permission_trackers :view_issues, [2]
+ role.save!
+ user = User.find(2)
+
+ issues = Issue.where(:project_id => 1).visible(user).to_a
+ assert issues.any?
+ assert_equal [2], issues.map(&:tracker_id).uniq
+
+ assert Issue.where(:project_id => 1).all? {|issue| issue.visible?(user) ^ issue.tracker_id != 2}
+ end
+
+ def test_visible_scope_should_consider_tracker_ids_on_each_project
+ user = User.generate!
+
+ project1 = Project.generate!
+ role1 = Role.generate!
+ role1.add_permission! :view_issues
+ role1.set_permission_trackers :view_issues, :all
+ role1.save!
+ User.add_to_project(user, project1, role1)
+
+ project2 = Project.generate!
+ role2 = Role.generate!
+ role2.add_permission! :view_issues
+ role2.set_permission_trackers :view_issues, [2]
+ role2.save!
+ User.add_to_project(user, project2, role2)
+
+ visible_issues = [
+ Issue.generate!(:project => project1, :tracker_id => 1),
+ Issue.generate!(:project => project1, :tracker_id => 2),
+ Issue.generate!(:project => project2, :tracker_id => 2)
+ ]
+ hidden_issue = Issue.generate!(:project => project2, :tracker_id => 1)
+
+ issues = Issue.where(:project_id => [project1.id, project2.id]).visible(user)
+ assert_equal visible_issues.map(&:id), issues.ids.sort
+
+ assert visible_issues.all? {|issue| issue.visible?(user)}
+ assert !hidden_issue.visible?(user)
+ end
+
+ def test_visible_scope_should_not_consider_roles_without_view_issues_permission
+ user = User.generate!
+ role1 = Role.generate!
+ role1.remove_permission! :view_issues
+ role1.set_permission_trackers :view_issues, :all
+ role1.save!
+ role2 = Role.generate!
+ role2.add_permission! :view_issues
+ role2.set_permission_trackers :view_issues, [2]
+ role2.save!
+ User.add_to_project(user, Project.find(1), [role1, role2])
+
+ issues = Issue.where(:project_id => 1).visible(user).to_a
+ assert issues.any?
+ assert_equal [2], issues.map(&:tracker_id).uniq
+
+ assert Issue.where(:project_id => 1).all? {|issue| issue.visible?(user) ^ issue.tracker_id != 2}
+ end
+
def test_visible_scope_for_admin
user = User.find(1)
user.members.each(&:destroy)
@@ -737,9 +800,10 @@ class IssueTest < ActiveSupport::TestCase
target = Tracker.find(2)
target.core_fields = %w(assigned_to_id due_date)
target.save!
+ user = User.find(2)
- issue = Issue.new(:tracker => source)
- issue.safe_attributes = {'tracker_id' => 2, 'due_date' => '2012-07-14'}
+ issue = Issue.new(:project => Project.find(1), :tracker => source)
+ issue.send :safe_attributes=, {'tracker_id' => 2, 'due_date' => '2012-07-14'}, user
assert_equal target, issue.tracker
assert_equal Date.parse('2012-07-14'), issue.due_date
end
@@ -1437,6 +1501,91 @@ class IssueTest < ActiveSupport::TestCase
assert_not_include project, Issue.allowed_target_projects(User.find(1))
end
+ def test_allowed_target_trackers_with_one_role_allowed_on_all_trackers
+ user = User.generate!
+ role = Role.generate!
+ role.add_permission! :add_issues
+ role.set_permission_trackers :add_issues, :all
+ role.save!
+ User.add_to_project(user, Project.find(1), role)
+
+ assert_equal [1, 2, 3], Issue.new(:project => Project.find(1)).allowed_target_trackers(user).ids.sort
+ end
+
+ def test_allowed_target_trackers_with_one_role_allowed_on_some_trackers
+ user = User.generate!
+ role = Role.generate!
+ role.add_permission! :add_issues
+ role.set_permission_trackers :add_issues, [1, 3]
+ role.save!
+ User.add_to_project(user, Project.find(1), role)
+
+ assert_equal [1, 3], Issue.new(:project => Project.find(1)).allowed_target_trackers(user).ids.sort
+ end
+
+ def test_allowed_target_trackers_with_two_roles_allowed_on_some_trackers
+ user = User.generate!
+ role1 = Role.generate!
+ role1.add_permission! :add_issues
+ role1.set_permission_trackers :add_issues, [1]
+ role1.save!
+ role2 = Role.generate!
+ role2.add_permission! :add_issues
+ role2.set_permission_trackers :add_issues, [3]
+ role2.save!
+ User.add_to_project(user, Project.find(1), [role1, role2])
+
+ assert_equal [1, 3], Issue.new(:project => Project.find(1)).allowed_target_trackers(user).ids.sort
+ end
+
+ def test_allowed_target_trackers_with_two_roles_allowed_on_all_trackers_and_some_trackers
+ user = User.generate!
+ role1 = Role.generate!
+ role1.add_permission! :add_issues
+ role1.set_permission_trackers :add_issues, :all
+ role1.save!
+ role2 = Role.generate!
+ role2.add_permission! :add_issues
+ role2.set_permission_trackers :add_issues, [1, 3]
+ role2.save!
+ User.add_to_project(user, Project.find(1), [role1, role2])
+
+ assert_equal [1, 2, 3], Issue.new(:project => Project.find(1)).allowed_target_trackers(user).ids.sort
+ end
+
+ def test_allowed_target_trackers_should_not_consider_roles_without_add_issues_permission
+ user = User.generate!
+ role1 = Role.generate!
+ role1.remove_permission! :add_issues
+ role1.set_permission_trackers :add_issues, :all
+ role1.save!
+ role2 = Role.generate!
+ role2.add_permission! :add_issues
+ role2.set_permission_trackers :add_issues, [1, 3]
+ role2.save!
+ User.add_to_project(user, Project.find(1), [role1, role2])
+
+ assert_equal [1, 3], Issue.new(:project => Project.find(1)).allowed_target_trackers(user).ids.sort
+ end
+
+ def test_allowed_target_trackers_without_project_should_be_empty
+ issue = Issue.new
+ assert_nil issue.project
+ assert_equal [], issue.allowed_target_trackers(User.find(2)).ids
+ end
+
+ def test_allowed_target_trackers_should_include_current_tracker
+ user = User.generate!
+ role = Role.generate!
+ role.add_permission! :add_issues
+ role.set_permission_trackers :add_issues, [3]
+ role.save!
+ User.add_to_project(user, Project.find(1), role)
+
+ issue = Issue.generate!(:project => Project.find(1), :tracker => Tracker.find(1))
+ assert_equal [1, 3], issue.allowed_target_trackers(user).ids.sort
+ end
+
def test_move_to_another_project_with_same_category
issue = Issue.find(1)
issue.project = Project.find(2)