Commit 6483a4c7 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix/13367-redirect-to-project-page-if-no-import' into 'master'

Redirect /import to project page if no importing at all and repo exists


Fixes gitlab-org/gitlab-ce#13367.

See merge request !2857
parents 28d42a33 3d3ac87a
......@@ -3,6 +3,7 @@ class Projects::ImportsController < Projects::ApplicationController
before_action :authorize_admin_project!
before_action :require_no_repo, only: [:new, :create]
before_action :redirect_if_progress, only: [:new, :create]
before_action :redirect_if_no_import, only: :show
def new
end
......@@ -63,14 +64,19 @@ class Projects::ImportsController < Projects::ApplicationController
def require_no_repo
if @project.repository_exists?
redirect_to(namespace_project_path(@project.namespace, @project))
redirect_to namespace_project_path(@project.namespace, @project)
end
end
def redirect_if_progress
if @project.import_in_progress?
redirect_to namespace_project_import_path(@project.namespace, @project) &&
return
redirect_to namespace_project_import_path(@project.namespace, @project)
end
end
def redirect_if_no_import
if @project.repository_exists? && @project.no_import?
redirect_to namespace_project_path(@project.namespace, @project)
end
end
end
......@@ -382,6 +382,10 @@ class Project < ActiveRecord::Base
external_import? || forked?
end
def no_import?
import_status == 'none'
end
def external_import?
import_url.present?
end
......
......@@ -104,6 +104,18 @@ describe Projects::ImportsController do
end
end
end
context 'when import never happened' do
before do
project.update_attribute(:import_status, :none)
end
it 'redirects to namespace_project_path' do
get :show, namespace_id: project.namespace.to_param, project_id: project.to_param
expect(response).to redirect_to namespace_project_path(project.namespace, project)
end
end
end
end
end
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