From bdd158c71c7dd7abbe7022d0294579358ee16ab7 Mon Sep 17 00:00:00 2001 From: Ion Biziiac Date: Wed, 20 Aug 2014 18:12:23 +0300 Subject: [PATCH 1/2] Fix correct creation of membership associations on project copy --- app/models/project/copy.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models/project/copy.rb b/app/models/project/copy.rb index 11a4895487..d0d25ee1a3 100644 --- a/app/models/project/copy.rb +++ b/app/models/project/copy.rb @@ -209,7 +209,7 @@ module Project::Copy end end - # Copies members from +project+ + # Copies members from +project+ def copy_members(project) # Copy users first, then groups to handle members with inherited and given roles members_to_copy = [] @@ -224,9 +224,15 @@ module Project::Copy next if role_ids.empty? new_member.role_ids = role_ids new_member.project = self - Redmine::Hook.call_hook(:copy_project_add_member, new_member: new_member, member: member) self.memberships << new_member end + + # Update the omitted attributes for the copied memberships + self.memberships.each do |new_member| + member = project.memberships.find_by_user_id(new_member.user_id) + Redmine::Hook.call_hook(:copy_project_add_member, new_member: new_member, member: member) + new_member.save + end end # Copies queries from +project+ From 033b9c49ace6ee66c8f8e6c00cc4bb2934637290 Mon Sep 17 00:00:00 2001 From: Ion Biziiac Date: Wed, 20 Aug 2014 18:13:26 +0300 Subject: [PATCH 2/2] Fix cascade deletion of membership associations on project destroy --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 3676185834..c869e05f7a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -587,7 +587,7 @@ class Project < ActiveRecord::Base def delete_all_members me, mr = Member.table_name, MemberRole.table_name connection.delete("DELETE FROM #{mr} WHERE #{mr}.member_id IN (SELECT #{me}.id FROM #{me} WHERE #{me}.project_id = #{id})") - Member.delete_all(['project_id = ?', id]) + Member.destroy_all(['project_id = ?', id]) end def destroy_all_work_packages