debian-mirror-gitlab/app/controllers/ci/projects_controller.rb

48 lines
1.4 KiB
Ruby
Raw Normal View History

2015-09-25 12:07:36 +05:30
module Ci
class ProjectsController < Ci::ApplicationController
2016-04-02 18:10:28 +05:30
before_action :project
2015-09-25 12:07:36 +05:30
before_action :no_cache, only: [:badge]
2016-06-02 11:05:42 +05:30
before_action :authorize_read_project!, except: [:badge, :index]
2016-04-02 18:10:28 +05:30
skip_before_action :authenticate_user!, only: [:badge]
2015-10-24 18:46:33 +05:30
protect_from_forgery
2015-09-25 12:07:36 +05:30
2016-06-02 11:05:42 +05:30
def index
redirect_to root_path
end
2015-09-25 12:07:36 +05:30
def show
2015-10-24 18:46:33 +05:30
# Temporary compatibility with CI badges pointing to CI project page
2015-12-23 02:04:40 +05:30
redirect_to namespace_project_path(project.namespace, project)
2015-09-25 12:07:36 +05:30
end
# Project status badge
# Image with build status for sha or ref
2016-04-02 18:10:28 +05:30
#
# This action in DEPRECATED, this is here only for backwards compatibility
# with projects migrated from GitLab CI.
#
2015-09-25 12:07:36 +05:30
def badge
2016-04-02 18:10:28 +05:30
return render_404 unless @project
2015-09-25 12:07:36 +05:30
2016-04-02 18:10:28 +05:30
image = Ci::ImageForBuildService.new.execute(@project, params)
2015-09-25 12:07:36 +05:30
send_file image.path, filename: image.name, disposition: 'inline', type:"image/svg+xml"
end
protected
def project
2015-12-23 02:04:40 +05:30
@project ||= Project.find_by(ci_id: params[:id].to_i)
2015-09-25 12:07:36 +05:30
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
2016-06-02 11:05:42 +05:30
def authorize_read_project!
return access_denied! unless can?(current_user, :read_project, project)
end
2015-09-25 12:07:36 +05:30
end
end