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
This commit is contained in:
Jean-Philippe Lang 2009-12-26 16:14:55 +00:00
parent c36c924714
commit 04455783a7
6 changed files with 41 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -2,4 +2,7 @@
groups_users_001:
group_id: 10
user_id: 8
groups_users_002:
group_id: 11
user_id: 8

View File

@ -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

View File

@ -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

View File

@ -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