Commit bc01af28 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Fix transferring to the same namespaces

Fixes redirecting after a failed attempt ate
transferring to the same namespace.

Minor cleanup qa tests

Fix transfer project specs

Stub query limit constant
parent 66dccd28
......@@ -3,7 +3,9 @@ import { GlDropdown, GlDropdownItem, GlDropdownSectionHeader, GlSearchBoxByType
import { __ } from '~/locale';
export const i18n = {
DEFAULT_TEXT: __('Select a namespace'),
DEFAULT_TEXT: __('Select a new namespace'),
GROUPS: __('Groups'),
USERS: __('Users'),
};
const filterByName = (data, searchTerm = '') =>
......@@ -36,10 +38,10 @@ export default {
},
computed: {
hasUserNamespaces() {
return this.data.user.length;
return this.data.user?.length;
},
hasGroupNamespaces() {
return this.data.group.length;
return this.data.group?.length;
},
filteredGroupNamespaces() {
if (!this.hasGroupNamespaces) return [];
......@@ -69,7 +71,7 @@ export default {
</template>
<template v-if="hasGroupNamespaces">
<div class="qa-namespaces-list-groups">
<gl-dropdown-section-header>{{ __('Groups') }}</gl-dropdown-section-header>
<gl-dropdown-section-header>{{ $options.i18n.GROUPS }}</gl-dropdown-section-header>
<gl-dropdown-item
v-for="item in filteredGroupNamespaces"
:key="item.id"
......@@ -81,7 +83,7 @@ export default {
</template>
<template v-if="hasUserNamespaces">
<div class="qa-namespaces-list-users">
<gl-dropdown-section-header>{{ __('Users') }}</gl-dropdown-section-header>
<gl-dropdown-section-header>{{ $options.i18n.USERS }}</gl-dropdown-section-header>
<gl-dropdown-item
v-for="item in filteredUserNamespaces"
:key="item.id"
......
......@@ -119,6 +119,7 @@ class ProjectsController < Projects::ApplicationController
if @project.errors[:new_namespace].present?
flash[:alert] = @project.errors[:new_namespace].first
return redirect_to edit_project_path(@project)
end
render_edit
......
......@@ -31535,9 +31535,6 @@ msgstr ""
msgid "Select a milestone"
msgstr ""
msgid "Select a namespace"
msgstr ""
msgid "Select a new namespace"
msgstr ""
......
......@@ -6,7 +6,6 @@ module QA
module Settings
class Advanced < Page::Base
include Component::ConfirmModal
include Page::Component::DropdownFilter
view 'app/views/projects/edit.html.haml' do
element :project_path_field
......
......@@ -899,7 +899,8 @@ RSpec.describe ProjectsController do
describe '#transfer', :enable_admin_mode do
render_views
let_it_be(:project, reload: true) { create(:project) }
let(:project) { create(:project) }
let_it_be(:admin) { create(:admin) }
let_it_be(:new_namespace) { create(:namespace) }
......@@ -938,10 +939,33 @@ RSpec.describe ProjectsController do
project.reload
expect(project.namespace).to eq(old_namespace)
expect(response).to have_gitlab_http_status(:ok)
expect(response).to redirect_to(edit_project_path(project))
expect(flash[:alert]).to eq s_('TransferProject|Please select a new namespace for your project.')
end
end
context 'when new namespace is the same as the current namespace' do
it 'project namespace is not changed' do
controller.instance_variable_set(:@project, project)
sign_in(admin)
old_namespace = project.namespace
put :transfer,
params: {
namespace_id: project.namespace.path,
new_namespace_id: old_namespace.id,
id: project.path
},
format: :js
project.reload
expect(project.namespace).to eq(old_namespace)
expect(response).to redirect_to(edit_project_path(project))
expect(flash[:alert]).to eq s_('TransferProject|Project is already in this namespace.')
end
end
end
describe "#destroy", :enable_admin_mode do
......
......@@ -8,6 +8,8 @@ RSpec.describe 'Projects > Settings > User transfers a project', :js do
let(:group) { create(:group) }
before do
stub_const('Gitlab::QueryLimiting::Transaction::THRESHOLD', 120)
group.add_owner(user)
sign_in(user)
end
......
......@@ -54,7 +54,7 @@ describe('Namespace Select', () => {
it('splits group and user namespaces', () => {
const headers = findSectionHeaders();
expect(headers).toHaveLength(2);
expect(wrappersText(headers)).toEqual(['Groups', 'Users']);
expect(wrappersText(headers)).toEqual([i18n.GROUPS, i18n.USERS]);
});
it('sets the dropdown to full width', () => {
......
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