summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-03-01 14:48:44 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-03-01 14:48:44 +0100
commit6fdbc22960d36111b501c5feeb33192edf47684f (patch)
treeadfb021246a4c7fe47dcb80cedee3affc8165f28
parent462526280a8996975ab53a61fee4f74e5d2ed7fd (diff)
downloadgitlab-ce-6fdbc22960d36111b501c5feeb33192edf47684f.tar.gz
Remove deprecated legacy CI project status badge
-rw-r--r--app/controllers/ci/projects_controller.rb47
-rw-r--r--app/services/ci/image_for_build_service.rb25
-rw-r--r--config/routes/ci.rb8
-rw-r--r--spec/controllers/ci/projects_controller_spec.rb74
4 files changed, 1 insertions, 153 deletions
diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb
deleted file mode 100644
index ff297d6ff13..00000000000
--- a/app/controllers/ci/projects_controller.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-module Ci
- class ProjectsController < ::ApplicationController
- before_action :project
- before_action :no_cache, only: [:badge]
- before_action :authorize_read_project!, except: [:badge, :index]
- skip_before_action :authenticate_user!, only: [:badge]
- protect_from_forgery
-
- def index
- redirect_to root_path
- end
-
- def show
- # Temporary compatibility with CI badges pointing to CI project page
- redirect_to namespace_project_path(project.namespace, project)
- end
-
- # Project status badge
- # Image with build status for sha or ref
- #
- # This action in DEPRECATED, this is here only for backwards compatibility
- # with projects migrated from GitLab CI.
- #
- def badge
- return render_404 unless @project
-
- image = Ci::ImageForBuildService.new.execute(@project, params)
- send_file image.path, filename: image.name, disposition: 'inline', type: "image/svg+xml"
- end
-
- protected
-
- def project
- @project ||= Project.find_by(ci_id: params[:id].to_i)
- end
-
- def no_cache
- response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
- response.headers["Pragma"] = "no-cache"
- response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
- end
-
- def authorize_read_project!
- return access_denied! unless can?(current_user, :read_project, project)
- end
- end
-end
diff --git a/app/services/ci/image_for_build_service.rb b/app/services/ci/image_for_build_service.rb
deleted file mode 100644
index 240ddabec36..00000000000
--- a/app/services/ci/image_for_build_service.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-module Ci
- class ImageForBuildService
- def execute(project, opts)
- ref = opts[:ref]
- sha = opts[:sha] || ref_sha(project, ref)
- pipelines = project.pipelines.where(sha: sha)
-
- image_name = image_for_status(pipelines.latest_status(ref))
- image_path = Rails.root.join('public/ci', image_name)
-
- OpenStruct.new(path: image_path, name: image_name)
- end
-
- private
-
- def ref_sha(project, ref)
- project.commit(ref).try(:sha) if ref
- end
-
- def image_for_status(status)
- status ||= 'unknown'
- 'build-' + status + ".svg"
- end
- end
-end
diff --git a/config/routes/ci.rb b/config/routes/ci.rb
index 47a049d5b20..8d23aa8fbf6 100644
--- a/config/routes/ci.rb
+++ b/config/routes/ci.rb
@@ -5,11 +5,5 @@ namespace :ci do
resource :lint, only: [:show, :create]
- resources :projects, only: [:index, :show] do
- member do
- get :status, to: 'projects#badge'
- end
- end
-
- root to: 'projects#index'
+ root to: redirect('/')
end
diff --git a/spec/controllers/ci/projects_controller_spec.rb b/spec/controllers/ci/projects_controller_spec.rb
deleted file mode 100644
index 86f01f437a2..00000000000
--- a/spec/controllers/ci/projects_controller_spec.rb
+++ /dev/null
@@ -1,74 +0,0 @@
-require 'spec_helper'
-
-describe Ci::ProjectsController do
- let(:visibility) { :public }
- let!(:project) { create(:empty_project, visibility, ci_id: 1) }
- let(:ci_id) { project.ci_id }
-
- describe '#index' do
- context 'user signed in' do
- before do
- sign_in(create(:user))
- get(:index)
- end
-
- it 'redirects to /' do
- expect(response).to redirect_to(root_path)
- end
- end
-
- context 'user not signed in' do
- before { get(:index) }
-
- it 'redirects to sign in page' do
- expect(response).to redirect_to(new_user_session_path)
- end
- end
- end
-
- ##
- # Specs for *deprecated* CI badge
- #
- describe '#badge' do
- shared_examples 'badge provider' do
- it 'shows badge' do
- expect(response.status).to eq 200
- expect(response.headers)
- .to include('Content-Type' => 'image/svg+xml')
- end
- end
-
- context 'user not signed in' do
- before { get(:badge, id: ci_id) }
-
- context 'project has no ci_id reference' do
- let(:ci_id) { 123 }
-
- it 'returns 404' do
- expect(response.status).to eq 404
- end
- end
-
- context 'project is public' do
- let(:visibility) { :public }
- it_behaves_like 'badge provider'
- end
-
- context 'project is private' do
- let(:visibility) { :private }
- it_behaves_like 'badge provider'
- end
- end
-
- context 'user signed in' do
- let(:user) { create(:user) }
- before { sign_in(user) }
- before { get(:badge, id: ci_id) }
-
- context 'private is internal' do
- let(:visibility) { :internal }
- it_behaves_like 'badge provider'
- end
- end
- end
-end