diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-16 15:08:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-16 15:08:40 +0300 |
commit | d43cb0f90723230c4aa617cb17a0cb6fb099f47e (patch) | |
tree | a8116eeba909c07909ccc030e8d40ab40d198aa3 | |
parent | c8278708638ed998a8ecfeac26e7d9561b6125f8 (diff) |
Add latest changes from gitlab-org/gitlab@master
7 files changed, 80 insertions, 7 deletions
diff --git a/app/assets/javascripts/import_entities/import_groups/components/import_table.vue b/app/assets/javascripts/import_entities/import_groups/components/import_table.vue index 6b96fa7c45c..98ee858ca91 100644 --- a/app/assets/javascripts/import_entities/import_groups/components/import_table.vue +++ b/app/assets/javascripts/import_entities/import_groups/components/import_table.vue @@ -78,6 +78,11 @@ export default { type: String, required: true, }, + defaultTargetNamespace: { + type: Number, + required: false, + default: null, + }, }, data() { @@ -433,7 +438,15 @@ export default { return this.importTargets[group.id]; } - const defaultTargetNamespace = this.availableNamespaces[0] ?? ROOT_NAMESPACE; + // If we've reached this Vue application we have at least one potential import destination + const defaultTargetNamespace = + // first option: namespace id was explicitly provided + this.availableNamespaces.find((ns) => ns.id === this.defaultTargetNamespace) ?? + // second option: first available namespace + this.availableNamespaces[0] ?? + // last resort: if no namespaces are available - suggest creating new namespace at root + ROOT_NAMESPACE; + let importTarget; if (group.lastImportTarget) { const targetNamespace = [ROOT_NAMESPACE, ...this.availableNamespaces].find( diff --git a/app/assets/javascripts/import_entities/import_groups/index.js b/app/assets/javascripts/import_entities/import_groups/index.js index 02af0db7f9a..5d7e7911f5a 100644 --- a/app/assets/javascripts/import_entities/import_groups/index.js +++ b/app/assets/javascripts/import_entities/import_groups/index.js @@ -15,9 +15,10 @@ export function mountImportGroupsApp(mountElement) { availableNamespacesPath, createBulkImportPath, jobsPath, + historyPath, + defaultTargetNamespace, sourceUrl, groupPathRegex, - historyPath, } = mountElement.dataset; const apolloProvider = new VueApollo({ defaultClient: createApolloClient({ @@ -40,6 +41,7 @@ export function mountImportGroupsApp(mountElement) { jobsPath, groupPathRegex: new RegExp(`^(${groupPathRegex})$`), historyPath, + defaultTargetNamespace: parseInt(defaultTargetNamespace, 10) || null, }, }); }, diff --git a/app/controllers/import/bulk_imports_controller.rb b/app/controllers/import/bulk_imports_controller.rb index 34f12aebb91..2d607fb7ff7 100644 --- a/app/controllers/import/bulk_imports_controller.rb +++ b/app/controllers/import/bulk_imports_controller.rb @@ -17,7 +17,7 @@ class Import::BulkImportsController < ApplicationController session[access_token_key] = configure_params[access_token_key]&.strip session[url_key] = configure_params[url_key] - redirect_to status_import_bulk_imports_url + redirect_to status_import_bulk_imports_url(namespace_id: params[:namespace_id]) end def status @@ -35,6 +35,12 @@ class Import::BulkImportsController < ApplicationController render json: json_response end format.html do + if params[:namespace_id] + @namespace = Namespace.find_by_id(params[:namespace_id]) + + render_404 unless current_user.can?(:create_subgroup, @namespace) + end + @source_url = session[url_key] end end diff --git a/app/views/groups/_import_group_from_another_instance_panel.html.haml b/app/views/groups/_import_group_from_another_instance_panel.html.haml index 654ee70dbee..a9234753aa2 100644 --- a/app/views/groups/_import_group_from_another_instance_panel.html.haml +++ b/app/views/groups/_import_group_from_another_instance_panel.html.haml @@ -1,4 +1,4 @@ -= form_with url: configure_import_bulk_imports_path, class: 'group-form gl-show-field-errors' do |f| += form_with url: configure_import_bulk_imports_path(namespace_id: params[:parent_id]), class: 'group-form gl-show-field-errors' do |f| .gl-border-l-solid.gl-border-r-solid.gl-border-gray-100.gl-border-1.gl-p-5 .gl-display-flex.gl-align-items-center %h4.gl-display-flex diff --git a/app/views/import/bulk_imports/status.html.haml b/app/views/import/bulk_imports/status.html.haml index 71866bab30b..1c8de23f28f 100644 --- a/app/views/import/bulk_imports/status.html.haml +++ b/app/views/import/bulk_imports/status.html.haml @@ -4,6 +4,7 @@ #import-groups-mount-element{ data: { status_path: status_import_bulk_imports_path(format: :json), available_namespaces_path: import_available_namespaces_path(format: :json), + default_target_namespace: @namespace&.id, create_bulk_import_path: import_bulk_imports_path(format: :json), jobs_path: realtime_changes_import_bulk_imports_path(format: :json), source_url: @source_url, diff --git a/spec/controllers/import/bulk_imports_controller_spec.rb b/spec/controllers/import/bulk_imports_controller_spec.rb index a7089005abf..7177c8c10a6 100644 --- a/spec/controllers/import/bulk_imports_controller_spec.rb +++ b/spec/controllers/import/bulk_imports_controller_spec.rb @@ -48,15 +48,25 @@ RSpec.describe Import::BulkImportsController do expect(session[:bulk_import_gitlab_access_token]).to eq(token) expect(controller).to redirect_to(status_import_bulk_imports_url) end + + it 'passes namespace_id to status' do + namespace_id = 5 + token = 'token' + url = 'https://gitlab.example' + + post :configure, params: { bulk_import_gitlab_access_token: token, bulk_import_gitlab_url: url, namespace_id: namespace_id } + + expect(controller).to redirect_to(status_import_bulk_imports_url(namespace_id: namespace_id)) + end end describe 'GET status' do - def get_status(params_override = {}) + def get_status(params_override = {}, format = :json) params = { page: 1, per_page: 20, filter: '' }.merge(params_override) get :status, params: params, - format: :json, + format: format, session: { bulk_import_gitlab_url: 'https://gitlab.example.com', bulk_import_gitlab_access_token: 'demo-pat' @@ -169,6 +179,25 @@ RSpec.describe Import::BulkImportsController do end end end + + context 'when namespace_id is provided' do + let_it_be(:group) { create(:group) } + + it 'renders 404 if user does not have access to namespace' do + get_status({ namespace_id: group.id }, :html) + + expect(response).to have_gitlab_http_status(:not_found) + end + + it 'passes namespace to template' do + group.add_owner(user) + + get_status({ namespace_id: group.id }, :html) + + expect(response).to have_gitlab_http_status(:ok) + expect(assigns(:namespace)).to eq(group) + end + end end context 'when connection error occurs' do diff --git a/spec/frontend/import_entities/import_groups/components/import_table_spec.js b/spec/frontend/import_entities/import_groups/components/import_table_spec.js index 24881237b85..cdc508a0033 100644 --- a/spec/frontend/import_entities/import_groups/components/import_table_spec.js +++ b/spec/frontend/import_entities/import_groups/components/import_table_spec.js @@ -56,7 +56,7 @@ describe('import table', () => { const selectRow = (idx) => wrapper.findAll('tbody td input[type=checkbox]').at(idx).setChecked(true); - const createComponent = ({ bulkImportSourceGroups, importGroups }) => { + const createComponent = ({ bulkImportSourceGroups, importGroups, defaultTargetNamespace }) => { apolloProvider = createMockApollo([], { Query: { availableNamespaces: () => availableNamespacesFixture, @@ -73,6 +73,7 @@ describe('import table', () => { jobsPath: '/fake_job_path', sourceUrl: SOURCE_URL, historyPath: '/fake_history_path', + defaultTargetNamespace, }, apolloProvider, }); @@ -165,6 +166,27 @@ describe('import table', () => { expect(targetNamespaceDropdownButton.text()).toBe('No parent'); }); + it('respects default namespace if provided', async () => { + const targetNamespace = availableNamespacesFixture[1]; + + createComponent({ + bulkImportSourceGroups: () => ({ + nodes: FAKE_GROUPS, + pageInfo: FAKE_PAGE_INFO, + versionValidation: FAKE_VERSION_VALIDATION, + }), + defaultTargetNamespace: targetNamespace.id, + }); + + await waitForPromises(); + + const firstRow = wrapper.find('tbody tr'); + const targetNamespaceDropdownButton = findTargetNamespaceDropdown(firstRow).find( + '[aria-haspopup]', + ); + expect(targetNamespaceDropdownButton.text()).toBe(targetNamespace.fullPath); + }); + it('does not render status string when result list is empty', async () => { createComponent({ bulkImportSourceGroups: jest.fn().mockResolvedValue({ |