Adds User#builtin_role.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11965 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-06-12 19:38:43 +00:00
parent cd716e311a
commit e978b3ace0
2 changed files with 12 additions and 5 deletions

View File

@ -186,7 +186,7 @@ class Project < ActiveRecord::Base
else
statement_by_role = {}
unless options[:member]
role = user.logged? ? Role.non_member : Role.anonymous
role = user.builtin_role
if role.allowed_to?(permission)
statement_by_role[role] = "#{Project.table_name}.is_public = #{connection.quoted_true}"
end

View File

@ -442,6 +442,15 @@ class User < Principal
@membership_by_project_id[project_id]
end
# Returns the user's bult-in role
def builtin_role
if logged?
@role_non_member ||= Role.non_member
else
@role_anonymous ||= Role.anonymous
end
end
# Return user's roles for project
def roles_for_project(project)
roles = []
@ -453,12 +462,10 @@ class User < Principal
if membership
roles = membership.roles
else
@role_non_member ||= Role.non_member
roles << @role_non_member
roles << builtin_role
end
else
@role_anonymous ||= Role.anonymous
roles << @role_anonymous
roles << builtin_role
end
roles
end