Fixed that issues can be moved to projects with issue tracking disabled (#10467).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9267 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2012-03-25 19:32:05 +00:00
parent 5663ca89fa
commit 1294f72175
2 changed files with 10 additions and 28 deletions

View File

@ -800,18 +800,7 @@ class Issue < ActiveRecord::Base
# Returns an array of projects that user can move issues to # Returns an array of projects that user can move issues to
def self.allowed_target_projects_on_move(user=User.current) def self.allowed_target_projects_on_move(user=User.current)
projects = [] Project.all(:conditions => Project.allowed_to_condition(user, :move_issues))
if user.admin?
# admin is allowed to move issues to any active (visible) project
projects = Project.visible(user).all
elsif user.logged?
if Role.non_member.allowed_to?(:move_issues)
projects = Project.visible(user).all
else
user.memberships.each {|m| projects << m.project if m.roles.detect {|r| r.allowed_to?(:move_issues)}}
end
end
projects
end end
private private

View File

@ -530,6 +530,15 @@ class IssueTest < ActiveSupport::TestCase
assert issue.save assert issue.save
end end
def test_allowed_target_projects_on_move_should_include_projects_with_issue_tracking_enabled
assert_include Project.find(2), Issue.allowed_target_projects_on_move(User.find(2))
end
def test_allowed_target_projects_on_move_should_not_include_projects_with_issue_tracking_disabled
Project.find(2).disable_module! :issue_tracking
assert_not_include Project.find(2), Issue.allowed_target_projects_on_move(User.find(2))
end
def test_move_to_another_project_with_same_category def test_move_to_another_project_with_same_category
issue = Issue.find(1) issue = Issue.find(1)
issue.project = Project.find(2) issue.project = Project.find(2)
@ -1172,22 +1181,6 @@ class IssueTest < ActiveSupport::TestCase
assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i} assert_equal 2, groups.inject(0) {|sum, group| sum + group['total'].to_i}
end end
context ".allowed_target_projects_on_move" do
should "return all active projects for admin users" do
User.current = User.find(1)
assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size
end
should "return allowed projects for non admin users" do
User.current = User.find(2)
Role.non_member.remove_permission! :move_issues
assert_equal 3, Issue.allowed_target_projects_on_move.size
Role.non_member.add_permission! :move_issues
assert_equal Project.active.count, Issue.allowed_target_projects_on_move.size
end
end
def test_recently_updated_with_limit_scopes def test_recently_updated_with_limit_scopes
#should return the last updated issue #should return the last updated issue
assert_equal 1, Issue.recently_updated.with_limit(1).length assert_equal 1, Issue.recently_updated.with_limit(1).length