diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /app/finders/environment_names_finder.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'app/finders/environment_names_finder.rb')
-rw-r--r-- | app/finders/environment_names_finder.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/app/finders/environment_names_finder.rb b/app/finders/environment_names_finder.rb index a92998921c7..e9063ef4c90 100644 --- a/app/finders/environment_names_finder.rb +++ b/app/finders/environment_names_finder.rb @@ -13,7 +13,7 @@ class EnvironmentNamesFinder attr_reader :project_or_group, :current_user - def initialize(project_or_group, current_user) + def initialize(project_or_group, current_user = nil) @project_or_group = project_or_group @current_user = current_user end @@ -31,14 +31,24 @@ class EnvironmentNamesFinder end def namespace_environments - projects = - project_or_group.all_projects.public_or_visible_to_user(current_user) + # We assume reporter access is needed for the :read_environment permission + # here. This expection is also present in + # IssuableFinder::Params#min_access_level, which is used for filtering out + # merge requests that don't have the right permissions. + # + # We use this approach so we don't need to load every project into memory + # just to verify if we can see their environments. Doing so would not be + # efficient, and possibly mess up pagination if certain projects are not + # meant to be visible. + projects = project_or_group + .all_projects + .public_or_visible_to_user(current_user, Gitlab::Access::REPORTER) Environment.for_project(projects) end def project_environments - if current_user.can?(:read_environment, project_or_group) + if Ability.allowed?(current_user, :read_environment, project_or_group) project_or_group.environments else Environment.none |