diff --git a/app/models/member_role.rb b/app/models/member_role.rb index 286659fc..9c28d413 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 4accf5a7..490c290b 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 3702d6ef..a7ee94e8 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 e0fc6d06..7ddcb878 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 504d64f2..f4d39fb8 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 f1dcb341..c1fc8433 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