Commit 1e0d5ffb authored by charlie ablett's avatar charlie ablett

Merge branch '218324-fix-nested-array-elasticsearch-syntax-error' into 'master'

Fix nested Array issue with Elasticsearch query

Closes #218324

See merge request gitlab-org/gitlab!32813
parents a91f7e32 343dcedd
---
title: Fix Elasticsearch query error for ES 7.7
merge_request: 32813
author:
type: fixed
...@@ -134,18 +134,18 @@ module Elastic ...@@ -134,18 +134,18 @@ module Elastic
# anonymous users. # anonymous users.
# Pick private, internal and public projects the user is a member of. # Pick private, internal and public projects the user is a member of.
# Pick all private projects for admins & auditors. # 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 if public_and_internal_projects
# Skip internal projects for anonymous and external users. # Skip internal projects for anonymous and external users.
# Others are given access to all internal projects. Admins & auditors # Others are given access to all internal projects. Admins & auditors
# get access to internal projects where the feature is private. # 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. # All users, including anonymous, can access public projects.
# Admins & auditors get access to public projects where the feature is # Admins & auditors get access to public projects where the feature is
# private. # private.
conditions << pick_projects_by_visibility(Project::PUBLIC, user, features) conditions += pick_projects_by_visibility(Project::PUBLIC, user, features)
end end
{ should: conditions } { should: conditions }
...@@ -161,9 +161,9 @@ module Elastic ...@@ -161,9 +161,9 @@ module Elastic
def pick_projects_by_membership(project_ids, user, features = nil) def pick_projects_by_membership(project_ids, user, features = nil)
if features.nil? if features.nil?
if project_ids == :any if project_ids == :any
return { term: { visibility_level: Project::PRIVATE } } return [{ term: { visibility_level: Project::PRIVATE } }]
else else
return { terms: { id: project_ids } } return [{ terms: { id: project_ids } }]
end end
end end
...@@ -202,7 +202,7 @@ module Elastic ...@@ -202,7 +202,7 @@ module Elastic
# Always denies access to projects when the features are disabled - even to # Always denies access to projects when the features are disabled - even to
# admins & auditors - as stale child documents may be present. # admins & auditors - as stale child documents may be present.
def limit_by_feature(condition, features, include_members_only:) def limit_by_feature(condition, features, include_members_only:)
return condition unless features return [condition] unless features
features = Array(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