Add option to search by fullpath on Namespaces REST API
Needed for Add `Namespace` filter to shared Vue components (#541501 - closed)
Add a new boolean parameter full_path_search to the Namespaces REST API. When enabled, the search filter is matched against the namespace's full path (e.g., group/subgroup/project).
For example, search=foo/bar should return the following:
/foo/bar/baz/foo/bar
Implementation Plan
Index: lib/api/namespaces.rb
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/lib/api/namespaces.rb b/lib/api/namespaces.rb
--- a/lib/api/namespaces.rb (revision 732f11bff3b0612536cd0f1bad4eae40e930cfb7)
+++ b/lib/api/namespaces.rb (date 1750747614249)
@@ -35,6 +35,7 @@
optional :search, type: String, desc: 'Returns a list of namespaces the user is authorized to view based on the search criteria'
optional :owned_only, type: Boolean, desc: 'In GitLab 14.2 and later, returns a list of owned namespaces only'
optional :top_level_only, type: Boolean, default: false, desc: 'Only include top level namespaces'
+ optional :full_path_search, type: Boolean, default: false, desc: "When true, `search` parameter matches against the namespace's full path"
use :pagination
use :optional_list_params_ee
@@ -50,7 +51,7 @@
namespaces = namespaces.include_gitlab_subscription_with_hosted_plan if Gitlab.ee?
- namespaces = namespaces.search(params[:search]) if params[:search].present?
+ namespaces = namespaces.search(params[:search], include_parents: params[:full_path_search]) if params[:search].present?
options = { with: Entities::Namespace, current_user: current_user }
Edited by Shane Maglangit