Commit 343dcedd authored by Dylan Griffith's avatar Dylan Griffith

Fix nested Array issue with Elasticsearch query

This fixes an issue in Elasticsearch 7.7+ versions
(https://gitlab.com/gitlab-org/gitlab/-/issues/218324). Previously the
query parser was forgiving about nested arrays and would just
automatically flatten them for you but now we need to flatten them
ourselves.
parent 365316ed
---
title: Fix Elasticsearch query error for ES 7.7
merge_request: 32813
author:
type: fixed
......@@ -134,18 +134,18 @@ module Elastic
# anonymous users.
# Pick private, internal and public projects the user is a member of.
# Pick all private projects for admins & auditors.
conditions = [pick_projects_by_membership(project_ids, user, features)]
conditions = pick_projects_by_membership(project_ids, user, features)
if public_and_internal_projects
# Skip internal projects for anonymous and external users.
# Others are given access to all internal projects. Admins & auditors
# get access to internal projects where the feature is private.
conditions << pick_projects_by_visibility(Project::INTERNAL, user, features) if user && !user.external?
conditions += pick_projects_by_visibility(Project::INTERNAL, user, features) if user && !user.external?
# All users, including anonymous, can access public projects.
# Admins & auditors get access to public projects where the feature is
# private.
conditions << pick_projects_by_visibility(Project::PUBLIC, user, features)
conditions += pick_projects_by_visibility(Project::PUBLIC, user, features)
end
{ should: conditions }
......@@ -161,9 +161,9 @@ module Elastic
def pick_projects_by_membership(project_ids, user, features = nil)
if features.nil?
if project_ids == :any
return { term: { visibility_level: Project::PRIVATE } }
return [{ term: { visibility_level: Project::PRIVATE } }]
else
return { terms: { id: project_ids } }
return [{ terms: { id: project_ids } }]
end
end
......@@ -202,7 +202,7 @@ module Elastic
# Always denies access to projects when the features are disabled - even to
# admins & auditors - as stale child documents may be present.
def limit_by_feature(condition, features, include_members_only:)
return condition unless features
return [condition] unless features
features = Array(features)
......
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