blob: 2e2272a2ef50cdc85a08499a5fc3f8a1dc5e3adb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# frozen_string_literal: true
module Preloaders
# This class preloads the max access level (role) for the user within the given projects and
# stores the values in requests store via the ProjectTeam class.
class UserMaxAccessLevelInProjectsPreloader
def initialize(projects, user)
@projects = if projects.is_a?(Array)
Project.where(id: projects)
else
# Push projects base query in to a sub-select to avoid
# table name clashes. Performs better than aliasing.
Project.where(id: projects.reselect(:id))
end
@user = user
end
def execute
project_authorizations = ProjectAuthorization.arel_table
auths = @projects
.select(
Project.default_select_columns,
project_authorizations[:user_id],
project_authorizations[:access_level]
)
.joins(project_auth_join)
auths.each do |project|
access_level = project.access_level || Gitlab::Access::NO_ACCESS
ProjectTeam.new(project).write_member_access_for_user_id(@user.id, access_level)
end
end
private
def project_auth_join
project_authorizations = ProjectAuthorization.arel_table
projects = Project.arel_table
projects
.join(
project_authorizations.as(project_authorizations.name),
Arel::Nodes::OuterJoin
)
.on(
project_authorizations[:project_id].eq(projects[:id])
.and(project_authorizations[:user_id].eq(@user.id))
)
.join_sources
end
end
end
|