GitLab wurde aktualisiert. Dank regelmäßiger Updates bleibt das THM GitLab sicher und Sie profitieren von den neuesten Funktionen. Vielen Dank für Ihre Geduld.

Commit 481e07a2 authored by jplang's avatar jplang
Browse files

Fixed User#project_ids_by_role when first called within chained scopes (#26376).

git-svn-id: e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 66406d6e
......@@ -603,6 +603,9 @@ class User < Principal
# Includes the projects that the user is a member of and the projects
# that grant custom permissions to the builtin groups.
def project_ids_by_role
# Clear project condition for when called from chained scopes
# eg. project.children.visible(user)
Project.unscoped do
return @project_ids_by_role if @project_ids_by_role
group_class = anonymous? ? GroupAnonymous : GroupNonMember
......@@ -634,6 +637,7 @@ class User < Principal
@project_ids_by_role = result
# Returns the ids of visible projects
def visible_project_ids
......@@ -952,6 +952,14 @@ class UserTest < ActiveSupport::TestCase
assert_equal [2], user.projects_by_role[Role.find(2)].collect(&:id).sort
def test_project_ids_by_role_should_not_poison_cache_when_first_called_from_chained_scopes
user = User.find(2)
project = Project.find(1)
assert_equal [1, 2, 5], user.project_ids_by_role.values.flatten.sort
def test_accessing_projects_by_role_with_no_projects_should_return_an_empty_array
user = User.find(2)
assert_equal [], user.projects_by_role[Role.find(3)]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment