From e978b3ace0e8632bec90d3894c0a2dc1de13a4ea Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Wed, 12 Jun 2013 19:38:43 +0000 Subject: [PATCH] Adds User#builtin_role. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11965 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/project.rb | 2 +- app/models/user.rb | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index d83b4758f..e2b7a9d9e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 5c1a98866..b5d600395 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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