summaryrefslogtreecommitdiffstats
path: root/app/models/member_role.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-02-02 12:50:45 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-02-02 12:50:45 +0000
commit0f29e265fcf1ac2ccba26be51e2866903c0db0b5 (patch)
tree726433b3e87ede1f55cb9c851b9e26d5d6c3b09e /app/models/member_role.rb
parent137aa1cf6636ad2ae3d42eb554bfac377f0cac6d (diff)
downloadredmine-0f29e265fcf1ac2ccba26be51e2866903c0db0b5.tar.gz
redmine-0f29e265fcf1ac2ccba26be51e2866903c0db0b5.zip
Optionaly inherit members from parent project (#5605).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11298 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/member_role.rb')
-rw-r--r--app/models/member_role.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/app/models/member_role.rb b/app/models/member_role.rb
index 4f97e35af..f344696be 100644
--- a/app/models/member_role.rb
+++ b/app/models/member_role.rb
@@ -21,8 +21,8 @@ class MemberRole < ActiveRecord::Base
after_destroy :remove_member_if_empty
- after_create :add_role_to_group_users
- after_destroy :remove_role_from_group_users
+ after_create :add_role_to_group_users, :add_role_to_subprojects
+ after_destroy :remove_inherited_roles
validates_presence_of :role
validate :validate_role_member
@@ -44,16 +44,26 @@ class MemberRole < ActiveRecord::Base
end
def add_role_to_group_users
- if member.principal.is_a?(Group)
+ if member.principal.is_a?(Group) && !inherited?
member.principal.users.each do |user|
- user_member = Member.find_by_project_id_and_user_id(member.project_id, user.id) || Member.new(:project_id => member.project_id, :user_id => user.id)
+ user_member = Member.find_or_new(member.project_id, user.id)
user_member.member_roles << MemberRole.new(:role => role, :inherited_from => id)
user_member.save!
end
end
end
- def remove_role_from_group_users
+ def add_role_to_subprojects
+ member.project.children.each do |subproject|
+ if subproject.inherit_members?
+ child_member = Member.find_or_new(subproject.id, member.user_id)
+ child_member.member_roles << MemberRole.new(:role => role, :inherited_from => id)
+ child_member.save!
+ end
+ end
+ end
+
+ def remove_inherited_roles
MemberRole.where(:inherited_from => id).all.group_by(&:member).each do |member, member_roles|
member_roles.each(&:destroy)
if member && member.user