diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-12-26 16:14:55 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2009-12-26 16:14:55 +0000 |
commit | 04455783a76e1a34e35c575fe3e7839bc1aa0609 (patch) | |
tree | a670bc732a93dd8a7014b5447b8a3b17abb20ee8 | |
parent | c36c924714cbbbf88f825b1513a0d22a3b513332 (diff) | |
download | redmine-04455783a76e1a34e35c575fe3e7839bc1aa0609.tar.gz redmine-04455783a76e1a34e35c575fe3e7839bc1aa0609.zip |
Fixed: project copy doesn't copy group memberships (#3975).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3250 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/member_role.rb | 4 | ||||
-rw-r--r-- | app/models/project.rb | 9 | ||||
-rw-r--r-- | test/fixtures/groups_users.yml | 3 | ||||
-rw-r--r-- | test/fixtures/member_roles.yml | 10 | ||||
-rw-r--r-- | test/fixtures/members.yml | 12 | ||||
-rw-r--r-- | test/unit/project_test.rb | 10 |
6 files changed, 41 insertions, 7 deletions
diff --git a/app/models/member_role.rb b/app/models/member_role.rb index 286659fc3..9c28d413d 100644 --- a/app/models/member_role.rb +++ b/app/models/member_role.rb @@ -30,6 +30,10 @@ class MemberRole < ActiveRecord::Base errors.add :role_id, :invalid if role && !role.member? end + def inherited? + !inherited_from.nil? + end + private def remove_member_if_empty diff --git a/app/models/project.rb b/app/models/project.rb index 4accf5a7c..490c290be 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -23,6 +23,7 @@ class Project < ActiveRecord::Base # Specific overidden Activities has_many :time_entry_activities has_many :members, :include => [:user, :roles], :conditions => "#{User.table_name}.type='User' AND #{User.table_name}.status=#{User::STATUS_ACTIVE}" + has_many :memberships, :class_name => 'Member' has_many :member_principals, :class_name => 'Member', :include => :principal, :conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{User::STATUS_ACTIVE})" @@ -583,10 +584,14 @@ class Project < ActiveRecord::Base # Copies members from +project+ def copy_members(project) - project.members.each do |member| + project.memberships.each do |member| new_member = Member.new new_member.attributes = member.attributes.dup.except("id", "project_id", "created_on") - new_member.role_ids = member.role_ids.dup + # only copy non inherited roles + # inherited roles will be added when copying the group membership + role_ids = member.member_roles.reject(&:inherited?).collect(&:role_id) + next if role_ids.empty? + new_member.role_ids = role_ids new_member.project = self self.members << new_member end diff --git a/test/fixtures/groups_users.yml b/test/fixtures/groups_users.yml index 3702d6efc..a7ee94e86 100644 --- a/test/fixtures/groups_users.yml +++ b/test/fixtures/groups_users.yml @@ -2,4 +2,7 @@ groups_users_001: group_id: 10 user_id: 8 +groups_users_002: + group_id: 11 + user_id: 8
\ No newline at end of file diff --git a/test/fixtures/member_roles.yml b/test/fixtures/member_roles.yml index e0fc6d064..7ddcb878a 100644 --- a/test/fixtures/member_roles.yml +++ b/test/fixtures/member_roles.yml @@ -37,3 +37,13 @@ member_roles_009: role_id: 2 member_id: 7 inherited_from: 7 +member_roles_010: + id: 10 + role_id: 2 + member_id: 9 + inherited_from: +member_roles_011: + id: 11 + role_id: 2 + member_id: 10 + inherited_from: 10 diff --git a/test/fixtures/members.yml b/test/fixtures/members.yml index 504d64f26..f4d39fb8a 100644 --- a/test/fixtures/members.yml +++ b/test/fixtures/members.yml @@ -48,3 +48,15 @@ members_008: id: 8 user_id: 1 mail_notification: true +members_009: + id: 9 + created_on: 2006-07-19 19:35:33 +02:00 + project_id: 2 + user_id: 11 + mail_notification: false +members_010: + id: 10 + created_on: 2006-07-19 19:35:33 +02:00 + project_id: 2 + user_id: 8 + mail_notification: false diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index f1dcb3418..c1fc84330 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -633,15 +633,15 @@ class ProjectTest < ActiveSupport::TestCase assert_not_equal source_relation_cross_project.id, copied_relation.id end - should "copy members" do + should "copy memberships" do assert @project.valid? assert @project.members.empty? assert @project.copy(@source_project) - assert_equal @source_project.members.size, @project.members.size - @project.members.each do |member| - assert member - assert_equal @project, member.project + assert_equal @source_project.memberships.size, @project.memberships.size + @project.memberships.each do |membership| + assert membership + assert_equal @project, membership.project end end |