summaryrefslogtreecommitdiffstats
path: root/app/models/member.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.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.rb')
-rw-r--r--app/models/member.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/app/models/member.rb b/app/models/member.rb
index 649edb2eb..5ff31f316 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -97,6 +97,16 @@ class Member < ActiveRecord::Base
@membership
end
+ # Finds or initilizes a Member for the given project and principal
+ def self.find_or_new(project, principal)
+ project_id = project.is_a?(Project) ? project.id : project
+ principal_id = principal.is_a?(Principal) ? principal.id : principal
+
+ member = Member.find_by_project_id_and_user_id(project_id, principal_id)
+ member ||= Member.new(:project_id => project_id, :user_id => principal_id)
+ member
+ end
+
protected
def validate_role