Commit 71d50990 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch '341823_exclude_prpoject_namesapce_from_namespaces_api' into 'master'

Exclude project namespace from namespaces API

See merge request gitlab-org/gitlab!73296
parents de0aa461 ced433ec
......@@ -70,7 +70,7 @@ module API
get ':namespace/exists', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
namespace_path = params[:namespace]
exists = Namespace.by_parent(params[:parent_id]).filter_by_path(namespace_path).exists?
exists = Namespace.without_project_namespaces.by_parent(params[:parent_id]).filter_by_path(namespace_path).exists?
suggestions = exists ? [Namespace.clean_path(namespace_path)] : []
present :exists, exists
......
......@@ -272,6 +272,16 @@ RSpec.describe API::Namespaces do
expect(response).to have_gitlab_http_status(:unauthorized)
end
context 'when requesting project_namespace' do
let(:namespace_id) { project_namespace.id }
it 'returns authentication error' do
get api("/namespaces/#{project_namespace.path}/exists"), params: { parent_id: group2.id }
expect(response).to have_gitlab_http_status(:unauthorized)
end
end
end
context 'when authenticated' do
......@@ -330,6 +340,18 @@ RSpec.describe API::Namespaces do
expect(response).to have_gitlab_http_status(:ok)
expect(response.body).to eq(expected_json)
end
context 'when requesting project_namespace' do
let(:namespace_id) { project_namespace.id }
it 'returns JSON indicating the namespace does not exist without a suggestion' do
get api("/namespaces/#{project_namespace.path}/exists", user), params: { parent_id: group2.id }
expected_json = { exists: false, suggests: [] }.to_json
expect(response).to have_gitlab_http_status(:ok)
expect(response.body).to eq(expected_json)
end
end
end
end
end
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