2015-12-18 07:41:16 +00:00
|
|
|
class Projects::ArtifactsController < Projects::ApplicationController
|
2015-12-17 13:24:43 +00:00
|
|
|
layout 'project'
|
|
|
|
before_action :authorize_download_build_artifacts!
|
|
|
|
|
|
|
|
def download
|
|
|
|
unless artifacts_file.file_storage?
|
|
|
|
return redirect_to artifacts_file.url
|
|
|
|
end
|
|
|
|
|
|
|
|
unless artifacts_file.exists?
|
|
|
|
return not_found!
|
|
|
|
end
|
|
|
|
|
|
|
|
send_file artifacts_file.path, disposition: 'attachment'
|
|
|
|
end
|
|
|
|
|
2015-12-18 07:41:16 +00:00
|
|
|
def browse
|
2015-12-28 10:43:15 +00:00
|
|
|
return render_404 unless build.artifacts?
|
2016-01-04 12:08:49 +00:00
|
|
|
@path = build.artifacts_metadata_string_path(params[:path] || './')
|
2016-01-04 13:18:06 +00:00
|
|
|
return render_404 unless @path.exists?
|
2015-12-17 14:17:00 +00:00
|
|
|
end
|
|
|
|
|
2015-12-17 13:24:43 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def build
|
|
|
|
@build ||= project.builds.unscoped.find_by!(id: params[:build_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def artifacts_file
|
|
|
|
@artifacts_file ||= build.artifacts_file
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_download_build_artifacts!
|
|
|
|
unless can?(current_user, :download_build_artifacts, @project)
|
|
|
|
if current_user.nil?
|
|
|
|
return authenticate_user!
|
|
|
|
else
|
|
|
|
return render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|