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) def role_for_project(project)
# No role on archived projects # No role on archived projects
return nil unless project && project.active? return nil unless project && project.active?
# Find project membership if logged?
membership = memberships.detect {|m| m.project_id == project.id} # Find project membership
if membership membership = memberships.detect {|m| m.project_id == project.id}
membership.role if membership
elsif logged? membership.role
Role.non_member else
@role_non_member ||= Role.non_member
end
else else
Role.anonymous @role_anonymous ||= Role.anonymous
end end
end end