Commit 52352dcc authored by Grzegorz Bizon's avatar Grzegorz Bizon

Move badge implementation to builds controller

parent 442a49db
class Projects::BuildsController < Projects::ApplicationController class Projects::BuildsController < Projects::ApplicationController
before_action :build, except: [:index, :cancel_all] before_action :build, except: [:index, :cancel_all]
before_action :authorize_read_build!, except: [:cancel, :cancel_all, :retry] before_action :authorize_read_build!, except: [:cancel, :cancel_all, :retry]
before_action :authorize_update_build!, except: [:index, :show, :status] before_action :authorize_update_build!, except: [:index, :show, :status]
layout 'project'
layout "project" # Skip authentication for status badge only
skip_before_action :authenticate_user!, :reject_blocked!, :project,
:repository, :authorize_manage_builds!, :build, only: [:badge]
def index def index
@scope = params[:scope] @scope = params[:scope]
...@@ -24,7 +26,6 @@ class Projects::BuildsController < Projects::ApplicationController ...@@ -24,7 +26,6 @@ class Projects::BuildsController < Projects::ApplicationController
def cancel_all def cancel_all
@project.builds.running_or_pending.each(&:cancel) @project.builds.running_or_pending.each(&:cancel)
redirect_to namespace_project_builds_path(project.namespace, project) redirect_to namespace_project_builds_path(project.namespace, project)
end end
...@@ -47,7 +48,6 @@ class Projects::BuildsController < Projects::ApplicationController ...@@ -47,7 +48,6 @@ class Projects::BuildsController < Projects::ApplicationController
end end
build = Ci::Build.retry(@build) build = Ci::Build.retry(@build)
redirect_to build_path(build) redirect_to build_path(build)
end end
...@@ -57,10 +57,15 @@ class Projects::BuildsController < Projects::ApplicationController ...@@ -57,10 +57,15 @@ class Projects::BuildsController < Projects::ApplicationController
def cancel def cancel
@build.cancel @build.cancel
redirect_to build_path(@build) redirect_to build_path(@build)
end end
def badge
project = Project.find_with_namespace("#{params[:namespace_id]}/#{params[:project_id]}")
image = Ci::ImageForBuildService.new.execute(project, ref: params[:ref])
send_file(image.path, filename: image.name, disposition: 'inline', type: 'image/svg+xml')
end
private private
def build def build
......
...@@ -10,11 +10,6 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -10,11 +10,6 @@ class Projects::CommitController < Projects::ApplicationController
before_action :commit before_action :commit
before_action :define_show_vars, only: [:show, :builds] before_action :define_show_vars, only: [:show, :builds]
# Skip authentication for status badge only
skip_before_action :authenticate_user!, :reject_blocked!, :project,
:repository, :require_non_empty_project, :authorize_download_code!,
:commit, only: [:badge]
def show def show
return git_not_found! unless @commit return git_not_found! unless @commit
...@@ -62,12 +57,6 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -62,12 +57,6 @@ class Projects::CommitController < Projects::ApplicationController
render layout: false render layout: false
end end
def badge
project = Project.find_with_namespace("#{params[:namespace_id]}/#{params[:project_id]}")
image = Ci::ImageForBuildService.new.execute(project, ref: params[:id])
send_file(image.path, filename: image.name, disposition: 'inline', type: 'image/svg+xml')
end
private private
def commit def commit
......
...@@ -493,13 +493,6 @@ Rails.application.routes.draw do ...@@ -493,13 +493,6 @@ Rails.application.routes.draw do
constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ }, constraints: { id: /(?:[^.]|\.(?!atom$))+/, format: /atom/ },
as: :commits as: :commits
) )
get(
'/status/*id/badge',
to: 'commit#badge',
constraints: { format: /png/ },
as: :build_badge
)
end end
resource :avatar, only: [:show, :destroy] resource :avatar, only: [:show, :destroy]
...@@ -615,9 +608,11 @@ Rails.application.routes.draw do ...@@ -615,9 +608,11 @@ Rails.application.routes.draw do
resource :variables, only: [:show, :update] resource :variables, only: [:show, :update]
resources :triggers, only: [:index, :create, :destroy] resources :triggers, only: [:index, :create, :destroy]
resources :builds, only: [:index, :show] do resources :builds, only: [:index, :show], constraints: { id: /\d+/ } do
collection do collection do
post :cancel_all post :cancel_all
get :badge, path: 'status/*ref/badge',
constraints: { ref: Gitlab::Regex.git_reference_regex, format: /svg/ }
end end
member do member do
......
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