Additional roles of a user who belongs to a group are not always copied when copying the project (#7213).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4615 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
2e1bcb2abf
commit
ce8113dea2
|
@ -740,7 +740,12 @@ class Project < ActiveRecord::Base
|
||||||
|
|
||||||
# Copies members from +project+
|
# Copies members from +project+
|
||||||
def copy_members(project)
|
def copy_members(project)
|
||||||
project.memberships.each do |member|
|
# Copy users first, then groups to handle members with inherited and given roles
|
||||||
|
members_to_copy = []
|
||||||
|
members_to_copy += project.memberships.select {|m| m.principal.is_a?(User)}
|
||||||
|
members_to_copy += project.memberships.select {|m| !m.principal.is_a?(User)}
|
||||||
|
|
||||||
|
members_to_copy.each do |member|
|
||||||
new_member = Member.new
|
new_member = Member.new
|
||||||
new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
|
new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on")
|
||||||
# only copy non inherited roles
|
# only copy non inherited roles
|
||||||
|
|
|
@ -770,6 +770,22 @@ class ProjectTest < ActiveSupport::TestCase
|
||||||
assert_equal @project, membership.project
|
assert_equal @project, membership.project
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "copy memberships with groups and additional roles" do
|
||||||
|
group = Group.create!(:lastname => "Copy group")
|
||||||
|
user = User.find(7)
|
||||||
|
group.users << user
|
||||||
|
# group role
|
||||||
|
Member.create!(:project_id => @source_project.id, :principal => group, :role_ids => [2])
|
||||||
|
member = Member.find_by_user_id_and_project_id(user.id, @source_project.id)
|
||||||
|
# additional role
|
||||||
|
member.role_ids = [1]
|
||||||
|
|
||||||
|
assert @project.copy(@source_project)
|
||||||
|
member = Member.find_by_user_id_and_project_id(user.id, @project.id)
|
||||||
|
assert_not_nil member
|
||||||
|
assert_equal [1, 2], member.role_ids.sort
|
||||||
|
end
|
||||||
|
|
||||||
should "copy project specific queries" do
|
should "copy project specific queries" do
|
||||||
assert @project.valid?
|
assert @project.valid?
|
||||||
|
|
Loading…
Reference in New Issue