Commit 71488731 authored by charlie ablett's avatar charlie ablett

Merge branch 'jprovazn-exclude2' into 'master'

Exclude project namespaces from autocomplete routes finder

See merge request gitlab-org/gitlab!72862
parents 301d5651 33db529c
...@@ -30,7 +30,7 @@ module Autocomplete ...@@ -30,7 +30,7 @@ module Autocomplete
class NamespacesOnly < self class NamespacesOnly < self
def routables def routables
return Namespace.all if current_user.admin? return Namespace.without_project_namespaces if current_user.admin?
current_user.namespaces current_user.namespaces
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Autocomplete::RoutesFinder do
describe '#execute' do
let_it_be(:user) { create(:user, username: 'user_path') }
let_it_be(:admin) { create(:admin) }
let_it_be(:group) { create(:group, path: 'path1') }
let_it_be(:group2) { create(:group, path: 'path2') }
let_it_be(:group3) { create(:group, path: 'not-matching') }
let_it_be(:project) { create(:project, path: 'path3', namespace: user.namespace) }
let_it_be(:project2) { create(:project, path: 'path4') }
let_it_be(:project_namespace) { create(:project_namespace, parent: group, path: 'path5') }
let(:current_user) { user }
let(:search) { 'path' }
before do
group.add_owner(user)
end
context 'for NamespacesOnly' do
subject { Autocomplete::RoutesFinder::NamespacesOnly.new(current_user, search: search).execute }
let(:user_route) { Route.find_by_path(user.username) }
it 'finds only user namespace and groups matching the search excluding project namespaces' do
is_expected.to match_array([group.route, user_route])
end
context 'when user is admin' do
let(:current_user) { admin }
it 'finds all namespaces matching the search excluding project namespaces' do
is_expected.to match_array([group.route, group2.route, user_route])
end
end
end
context 'for ProjectsOnly' do
subject { Autocomplete::RoutesFinder::ProjectsOnly.new(current_user, search: 'path').execute }
it 'finds only matching projects the user has access to' do
is_expected.to match_array([project.route])
end
context 'when user is admin' do
let(:current_user) { admin }
it 'finds all projects matching the search' do
is_expected.to match_array([project.route, project2.route])
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