Skip to content

Internal project snippets are not found when elasticsearch is enabled

Here's an example query:

{:query=>
  {:bool=>
    {:must=>
      [{:simple_query_string=>
         {:fields=>["title", "file_name"],
          :query=>"term",
          :default_operator=>:and}}],
     :filter=>
      {:bool=>
        {:should=>
          [{:term=>{:author_id=>11}},
           {:terms=>{:project_id=>[]}},
           {:bool=>
             {:filter=>{:terms=>{:visibility_level=>[20, 10]}},
              :must_not=>{:exists=>{:field=>"project_id"}}}}]}}}},
 :sort=>[{:updated_at=>{:order=>:desc}}, :_score],
 :highlight=>{:fields=>{:title=>{}, :file_name=>{}}}}

Those filters, in order:

  • Find snippets I authored
  • Finds project snippets in private projects (none, and this is broken in other ways too)
  • Finds personal snippets that are public or internal

There's no filter that selects public or internal project snippets, applying the usual access restrictions to it.

I think app/models/concerns/elastic/snippets_search.rb needs to be refactored to use the project id helpers in application_search.rb to gain support. The SnippetSearchService will also need refactoring - I'd suggest merging it into the Search::{Global,Group,Project}Service classes (and SnippetSearchResults into Gitlab{,::Elastic}::{,Project}SearchResults

/cc @vsizov