]> source.dussan.org Git - redmine.git/commitdiff
Additional roles of a user who belongs to a group are not always copied when copying...
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Jan 2011 11:38:35 +0000 (11:38 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 2 Jan 2011 11:38:35 +0000 (11:38 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4615 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index 4af77d1d9e26fabafac50198c09f5f759bbfdbfd..891db8b8cde16176788239cf91f6c5d1b9e93b07 100644 (file)
@@ -740,7 +740,12 @@ class Project < ActiveRecord::Base
 
   # Copies members from +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.attributes = member.attributes.dup.except("id", "project_id", "created_on")
       # only copy non inherited roles
index 61ae3be32e31496bae99dbd8435534319d803966..8eb79fdaa0fd48143f5589834dd0362e641aeab9 100644 (file)
@@ -770,6 +770,22 @@ class ProjectTest < ActiveSupport::TestCase
         assert_equal @project, membership.project
       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
       assert @project.valid?