Slight optimization in User#role_for_project.

git-svn-id: http://redmine.rubyforge.org/svn/trunk@928 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2007-11-24 15:14:32 +00:00
parent fde4a42e2a
commit f80f04e379
1 changed files with 9 additions and 7 deletions

View File

@ -178,14 +178,16 @@ class User < ActiveRecord::Base
def role_for_project(project)
# No role on archived projects
return nil unless project && project.active?
if logged?
# Find project membership
membership = memberships.detect {|m| m.project_id == project.id}
if membership
membership.role
elsif logged?
Role.non_member
else
Role.anonymous
@role_non_member ||= Role.non_member
end
else
@role_anonymous ||= Role.anonymous
end
end