summaryrefslogtreecommitdiffstats
path: root/app/models/user.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-01-07 11:40:09 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-01-07 11:40:09 +0000
commit3deb70d4aab992c00b5048630033d6614aea97c1 (patch)
tree6afa66b87956fafdc7a5f1f77c32094edcd27d5a /app/models/user.rb
parent79c2e42889913a2f4ec583b4bbc9fbe256d92e7e (diff)
downloadredmine-3deb70d4aab992c00b5048630033d6614aea97c1.tar.gz
redmine-3deb70d4aab992c00b5048630033d6614aea97c1.zip
Don't preload projects and roles on Principal#memberships association (#23519).
Patch by Ondřej Ezr. git-svn-id: http://svn.redmine.org/redmine/trunk@16153 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/user.rb')
-rw-r--r--app/models/user.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/app/models/user.rb b/app/models/user.rb
index 9192032f0..53e0ab4d5 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -546,6 +546,10 @@ class User < Principal
@membership_by_project_id[project_id]
end
+ def roles
+ @roles ||= Role.joins(members: :project).where(["#{Project.table_name}.status <> ?", Project::STATUS_ARCHIVED]).where(Member.arel_table[:user_id].eq(id)).uniq
+ end
+
# Returns the user's bult-in role
def builtin_role
@builtin_role ||= Role.non_member
@@ -673,9 +677,9 @@ class User < Principal
return true if admin?
# authorize if user has at least one role that has this permission
- roles = memberships.collect {|m| m.roles}.flatten.uniq
- roles << (self.logged? ? Role.non_member : Role.anonymous)
- roles.any? {|role|
+ rls = self.roles.to_a
+ rls << builtin_role
+ rls.any? {|role|
role.allowed_to?(action) &&
(block_given? ? yield(role, self) : true)
}