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 else
statement_by_role = {} statement_by_role = {}
unless options[:member] unless options[:member]
role = user.logged? ? Role.non_member : Role.anonymous role = user.builtin_role
if role.allowed_to?(permission) if role.allowed_to?(permission)
statement_by_role[role] = "#{Project.table_name}.is_public = #{connection.quoted_true}" statement_by_role[role] = "#{Project.table_name}.is_public = #{connection.quoted_true}"
end end

View File

@ -442,6 +442,15 @@ class User < Principal
@membership_by_project_id[project_id] @membership_by_project_id[project_id]
end 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 # Return user's roles for project
def roles_for_project(project) def roles_for_project(project)
roles = [] roles = []
@ -453,12 +462,10 @@ class User < Principal
if membership if membership
roles = membership.roles roles = membership.roles
else else
@role_non_member ||= Role.non_member roles << builtin_role
roles << @role_non_member
end end
else else
@role_anonymous ||= Role.anonymous roles << builtin_role
roles << @role_anonymous
end end
roles roles
end end