Skip to content
Snippets Groups Projects
Commit 90d11a8e authored by Rémy Coutable's avatar Rémy Coutable :red_circle:
Browse files

Merge branch 'xanf-respect-namespace-id-fogbugz' into 'master'

Respect namespace_id in fogbugz importer

See merge request !90819
parents 48bac4a9 6a9e5446
No related branches found
No related tags found
1 merge request!90819Respect namespace_id in fogbugz importer
Pipeline #575012884 passed
......@@ -22,7 +22,7 @@ def callback
session[:fogbugz_token] = res.get_token
session[:fogbugz_uri] = params[:uri]
redirect_to new_user_map_import_fogbugz_path
redirect_to new_user_map_import_fogbugz_path(namespace_id: params[:namespace_id])
end
def new_user_map
......@@ -41,12 +41,12 @@ def create_user_map
flash[:notice] = _('The user map has been saved. Continue by selecting the projects you want to import.')
redirect_to status_import_fogbugz_path
redirect_to status_import_fogbugz_path(namespace_id: params[:namespace_id])
end
def status
unless client.valid?
return redirect_to new_import_fogbugz_path
return redirect_to new_import_fogbugz_path(namespace_id: params[:namespace_id])
end
super
......@@ -106,7 +106,7 @@ def user_map
end
def fogbugz_unauthorized(exception)
redirect_to new_import_fogbugz_path, alert: exception.message
redirect_to new_import_fogbugz_path(namespace_id: params[:namespace_id]), alert: exception.message
end
def import_params
......
......@@ -8,7 +8,7 @@
= _('Import projects from FogBugz')
%hr
= form_tag callback_import_fogbugz_path do
= form_tag callback_import_fogbugz_path(namespace_id: params[:namespace_id]) do
%p
= _("To get started you enter your FogBugz URL and login information below. In the next steps, you'll be able to map users and select the projects you want to import.")
.form-group.row
......
......@@ -8,7 +8,7 @@
= _('Import projects from FogBugz')
%hr
= form_tag create_user_map_import_fogbugz_path do
= form_tag create_user_map_import_fogbugz_path(namespace_id: params[:namespace_id]) do
%p
= _("Customize how FogBugz email addresses and usernames are imported into GitLab. In the next step, you'll be able to select the projects you want to import.")
%p
......
......@@ -8,4 +8,4 @@
- link_to_customize = link_to('customize', new_user_map_import_fogbugz_path)
= _('Optionally, you can %{link_to_customize} how FogBugz email addresses and usernames are imported into GitLab.').html_safe % { link_to_customize: link_to_customize }
%hr
= render 'import/githubish_status', provider: 'fogbugz', filterable: false
= render 'import/githubish_status', provider: 'fogbugz', filterable: false, default_namespace: @namespace
......@@ -46,7 +46,7 @@
- if fogbugz_import_enabled?
%div
= link_to new_import_fogbugz_path, class: 'gl-button btn-default btn import_fogbugz js-import-project-btn', data: { platform: 'fogbugz', **tracking_attrs_data(track_label, 'click_button', 'fogbugz') } do
= link_to new_import_fogbugz_path(namespace_id: namespace_id), class: 'gl-button btn-default btn import_fogbugz js-import-project-btn', data: { platform: 'fogbugz', **tracking_attrs_data(track_label, 'click_button', 'fogbugz') } do
.gl-button-icon
= sprite_icon('bug')
FogBugz
......
......@@ -8,6 +8,7 @@
let(:user) { create(:user) }
let(:token) { FFaker::Lorem.characters(8) }
let(:uri) { 'https://example.com' }
let(:namespace_id) { 5 }
before do
sign_in(user)
......@@ -16,9 +17,11 @@
describe 'POST #callback' do
let(:xml_response) { %Q(<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><token><![CDATA[#{token}]]></token></response>) }
it 'attempts to contact Fogbugz server' do
before do
stub_request(:post, "https://example.com/api.asp").to_return(status: 200, body: xml_response, headers: {})
end
it 'attempts to contact Fogbugz server' do
post :callback, params: { uri: uri, email: 'test@example.com', password: 'mypassword' }
expect(session[:fogbugz_token]).to eq(token)
......@@ -26,6 +29,20 @@
expect(response).to redirect_to(new_user_map_import_fogbugz_path)
end
it 'preserves namespace_id query param' do
post :callback, params: { uri: uri, email: 'test@example.com', password: 'mypassword', namespace_id: namespace_id }
expect(response).to redirect_to(new_user_map_import_fogbugz_path(namespace_id: namespace_id))
end
it 'redirects to new page form when client raises authentication exception' do
allow(::Gitlab::FogbugzImport::Client).to receive(:new).and_raise(::Fogbugz::AuthenticationException)
post :callback, params: { uri: uri, email: 'test@example.com', password: 'mypassword' }
expect(response).to redirect_to(new_import_fogbugz_url)
end
context 'verify url' do
shared_examples 'denies local request' do |reason|
it 'does not allow requests' do
......@@ -76,6 +93,16 @@
expect(session[:fogbugz_user_map]).to eq(user_map)
expect(response).to redirect_to(status_import_fogbugz_path)
end
it 'preserves namespace_id query param' do
client = double(user_map: {})
expect(controller).to receive(:client).and_return(client)
post :create_user_map, params: { users: user_map, namespace_id: namespace_id }
expect(session[:fogbugz_user_map]).to eq(user_map)
expect(response).to redirect_to(status_import_fogbugz_path(namespace_id: namespace_id))
end
end
describe 'GET status' do
......@@ -84,11 +111,19 @@
id: 'demo', name: 'vim', safe_name: 'vim', path: 'vim')
end
before do
stub_client(valid?: true)
it 'redirects to new page form when client is invalid' do
stub_client(valid?: false)
get :status
expect(response).to redirect_to(new_import_fogbugz_path)
end
it_behaves_like 'import controller status' do
before do
stub_client(valid?: true)
end
let(:repo_id) { repo.id }
let(:import_source) { repo.name }
let(:provider_name) { 'fogbugz' }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment