BigW Consortium Gitlab

projects_controller.rb 1.19 KB
Newer Older
1 2
module Ci
  class ProjectsController < Ci::ApplicationController
3 4
    before_action :project
    before_action :authorize_read_project!, except: [:badge]
Valery Sizov committed
5
    before_action :no_cache, only: [:badge]
6
    skip_before_action :authenticate_user!, only: [:badge]
7
    protect_from_forgery
8

9 10
    def show
      # Temporary compatibility with CI badges pointing to CI project page
11
      redirect_to namespace_project_path(project.namespace, project)
12 13
    end

14 15
    # Project status badge
    # Image with build status for sha or ref
16 17 18 19
    #
    # This action in DEPRECATED, this is here only for backwards compatibility
    # with projects migrated from GitLab CI.
    #
20
    def badge
21
      return render_404 unless @project
22

23 24 25 26 27 28 29
      image = Ci::ImageForBuildService.new.execute(@project, params)
      send_file image.path, filename: image.name, disposition: 'inline', type:"image/svg+xml"
    end

    protected

    def project
Kamil Trzcinski committed
30
      @project ||= Project.find_by(ci_id: params[:id].to_i)
31 32 33 34 35 36 37 38 39
    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
  end
end