Commit d06e9696 authored by Dmytro Zaporozhets (DZ)'s avatar Dmytro Zaporozhets (DZ)

Merge branch 'georgekoltsov/add-group-import-filtering' into 'master'

Add Group Migration filtering

See merge request gitlab-org/gitlab!49963
parents cc99141a a8d7e5a7
# frozen_string_literal: true
class Import::BulkImportsController < ApplicationController
include ActionView::Helpers::SanitizeHelper
before_action :ensure_group_import_enabled
before_action :verify_blocked_uri, only: :status
......@@ -43,7 +45,22 @@ class Import::BulkImportsController < ApplicationController
end
def importable_data
client.get('groups', top_level_only: true).parsed_response
client.get('groups', query_params).parsed_response
end
# Default query string params used to fetch groups from GitLab source instance
#
# top_level_only: fetch only top level groups (subgroups are fetched during import itself)
# min_access_level: fetch only groups user has maintainer or above permissions
# search: optional search param to search user's groups by a keyword
def query_params
query_params = {
top_level_only: true,
min_access_level: Gitlab::Access::MAINTAINER
}
query_params[:search] = sanitized_filter_param if sanitized_filter_param
query_params
end
def client
......@@ -131,4 +148,8 @@ class Import::BulkImportsController < ApplicationController
access_token: session[access_token_key]
}
end
def sanitized_filter_param
@filter ||= sanitize(params[:filter])&.downcase
end
end
......@@ -63,9 +63,16 @@ RSpec.describe Import::BulkImportsController do
)
end
let(:client_params) do
{
top_level_only: true,
min_access_level: Gitlab::Access::MAINTAINER
}
end
before do
allow(controller).to receive(:client).and_return(client)
allow(client).to receive(:get).with('groups', top_level_only: true).and_return(client_response)
allow(client).to receive(:get).with('groups', client_params).and_return(client_response)
end
it 'returns serialized group data' do
......@@ -73,6 +80,17 @@ RSpec.describe Import::BulkImportsController do
expect(json_response).to eq({ importable_data: client_response.parsed_response }.as_json)
end
context 'when filtering' do
it 'returns filtered result' do
filter = 'test'
search_params = client_params.merge(search: filter)
expect(client).to receive(:get).with('groups', search_params).and_return(client_response)
get :status, format: :json, params: { filter: filter }
end
end
end
context 'when host url is local or not http' do
......
......@@ -24,7 +24,7 @@ RSpec.describe 'Import/Export - Connect to another instance', :js do
pat = 'demo-pat'
stub_path = 'stub-group'
stub_request(:get, "%{url}/api/v4/groups?page=1&per_page=30&top_level_only=true" % { url: source_url }).to_return(
stub_request(:get, "%{url}/api/v4/groups?page=1&per_page=30&top_level_only=true&min_access_level=40" % { url: source_url }).to_return(
body: [{
id: 2595438,
web_url: 'https://gitlab.com/groups/auto-breakfast',
......
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