Mercurial > hg > soundsoftware-site
comparison app/models/member_role.rb @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children | e248c7af89ec |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | 2 # Copyright (C) 2006-2013 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
19 belongs_to :member | 19 belongs_to :member |
20 belongs_to :role | 20 belongs_to :role |
21 | 21 |
22 after_destroy :remove_member_if_empty | 22 after_destroy :remove_member_if_empty |
23 | 23 |
24 after_create :add_role_to_group_users | 24 after_create :add_role_to_group_users, :add_role_to_subprojects |
25 after_destroy :remove_role_from_group_users | 25 after_destroy :remove_inherited_roles |
26 | 26 |
27 validates_presence_of :role | 27 validates_presence_of :role |
28 validate :validate_role_member | 28 validate :validate_role_member |
29 | 29 |
30 def validate_role_member | 30 def validate_role_member |
42 member.destroy | 42 member.destroy |
43 end | 43 end |
44 end | 44 end |
45 | 45 |
46 def add_role_to_group_users | 46 def add_role_to_group_users |
47 if member.principal.is_a?(Group) | 47 if member.principal.is_a?(Group) && !inherited? |
48 member.principal.users.each do |user| | 48 member.principal.users.each do |user| |
49 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) | 49 user_member = Member.find_or_new(member.project_id, user.id) |
50 user_member.member_roles << MemberRole.new(:role => role, :inherited_from => id) | 50 user_member.member_roles << MemberRole.new(:role => role, :inherited_from => id) |
51 user_member.save! | 51 user_member.save! |
52 end | 52 end |
53 end | 53 end |
54 end | 54 end |
55 | 55 |
56 def remove_role_from_group_users | 56 def add_role_to_subprojects |
57 MemberRole.find(:all, :conditions => { :inherited_from => id }).group_by(&:member).each do |member, member_roles| | 57 member.project.children.each do |subproject| |
58 member_roles.each(&:destroy) | 58 if subproject.inherit_members? |
59 if member && member.user | 59 child_member = Member.find_or_new(subproject.id, member.user_id) |
60 Watcher.prune(:user => member.user, :project => member.project) | 60 child_member.member_roles << MemberRole.new(:role => role, :inherited_from => id) |
61 child_member.save! | |
61 end | 62 end |
62 end | 63 end |
63 end | 64 end |
65 | |
66 def remove_inherited_roles | |
67 MemberRole.where(:inherited_from => id).all.group_by(&:member).each do |member, member_roles| | |
68 member_roles.each(&:destroy) | |
69 end | |
70 end | |
64 end | 71 end |