From 442a49db2bc5e3f6cea827879fa4f5c532a5f6f1 Mon Sep 17 00:00:00 2001 From: Grzegorz Bizon Date: Fri, 5 Feb 2016 14:42:01 +0100 Subject: Skip authentication when requesting commit status badge --- app/controllers/projects/commit_controller.rb | 8 +++++++- config/routes.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 36fef1740e2..493cd332d9f 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -10,6 +10,11 @@ class Projects::CommitController < Projects::ApplicationController before_action :commit 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 return git_not_found! unless @commit @@ -58,7 +63,8 @@ class Projects::CommitController < Projects::ApplicationController end def badge - image = Ci::ImageForBuildService.new.execute(@project, ref: params[:id]) + 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 diff --git a/config/routes.rb b/config/routes.rb index 152a04061f2..6b710bc45ea 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -498,7 +498,7 @@ Rails.application.routes.draw do '/status/*id/badge', to: 'commit#badge', constraints: { format: /png/ }, - as: :commit_badge + as: :build_badge ) end -- cgit v1.2.1