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