Commit e65bc0f1 authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent bc3493f9
class Projects::ArtifactsController < Projects::ApplicationController class Projects::ArtifactsController < Projects::ApplicationController
include ExtractsPath
layout 'project' layout 'project'
before_action :authorize_read_build! before_action :authorize_read_build!
before_action :authorize_update_build!, only: [:keep] before_action :authorize_update_build!, only: [:keep]
...@@ -35,7 +37,8 @@ class Projects::ArtifactsController < Projects::ApplicationController ...@@ -35,7 +37,8 @@ class Projects::ArtifactsController < Projects::ApplicationController
end end
def latest_succeeded def latest_succeeded
target_path = artifacts_action_path(params[:path], project, build) path = ref_name_and_path.last
target_path = artifacts_action_path(path, project, build)
if target_path if target_path
redirect_to(target_path) redirect_to(target_path)
...@@ -59,13 +62,18 @@ class Projects::ArtifactsController < Projects::ApplicationController ...@@ -59,13 +62,18 @@ class Projects::ArtifactsController < Projects::ApplicationController
end end
def build_from_ref def build_from_ref
if params[:ref_name] if params[:ref_name_and_path]
builds = project.latest_successful_builds_for(params[:ref_name]) ref_name = ref_name_and_path.first
builds = project.latest_successful_builds_for(ref_name)
builds.find_by(name: params[:job]) builds.find_by(name: params[:job])
end end
end end
def ref_name_and_path
@ref_name_and_path ||= extract_ref(params[:ref_name_and_path])
end
def artifacts_file def artifacts_file
@artifacts_file ||= build.artifacts_file @artifacts_file ||= build.artifacts_file
end end
......
...@@ -153,9 +153,10 @@ module GitlabRoutingHelper ...@@ -153,9 +153,10 @@ module GitlabRoutingHelper
# Artifacts # Artifacts
def artifacts_action_path(path, project, build) def artifacts_action_path(path, project, build)
args = [project.namespace, project, build] action, path_params = path.split('/', 2)
args = [project.namespace, project, build, path_params]
case path case action
when 'download' when 'download'
download_namespace_project_build_artifacts_path(*args) download_namespace_project_build_artifacts_path(*args)
when 'browse' when 'browse'
......
...@@ -787,9 +787,8 @@ Rails.application.routes.draw do ...@@ -787,9 +787,8 @@ Rails.application.routes.draw do
resources :artifacts, only: [] do resources :artifacts, only: [] do
collection do collection do
get :latest_succeeded, get :latest_succeeded,
path: ':ref_name/*path', path: '*ref_name_and_path',
format: false, format: false
constraints: { ref_name: /.+/ } # could have /
end end
end end
end end
......
...@@ -26,8 +26,7 @@ describe Projects::ArtifactsController do ...@@ -26,8 +26,7 @@ describe Projects::ArtifactsController do
latest_succeeded_namespace_project_artifacts_path( latest_succeeded_namespace_project_artifacts_path(
project.namespace, project.namespace,
project, project,
ref, [ref, path].join('/'),
path,
job: job) job: job)
end end
...@@ -94,6 +93,25 @@ describe Projects::ArtifactsController do ...@@ -94,6 +93,25 @@ describe Projects::ArtifactsController do
it_behaves_like 'redirect to the build' it_behaves_like 'redirect to the build'
end end
context 'with branch name and path containing slashes' do
before do
pipeline.update(ref: 'improve/awesome',
sha: project.commit('improve/awesome').sha)
get path_from_ref('improve/awesome', build.name, 'file/README.md')
end
it 'redirects' do
path = file_namespace_project_build_artifacts_path(
project.namespace,
project,
build,
'README.md')
expect(response).to redirect_to(path)
end
end
end 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