2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-05 05:16:41 -05:00
|
|
|
class Projects::ReleasesController < Projects::ApplicationController
|
|
|
|
# Authorize
|
2019-10-28 17:06:24 -04:00
|
|
|
before_action :require_non_empty_project, except: [:index]
|
2020-03-04 07:07:52 -05:00
|
|
|
before_action :release, only: %i[edit show update downloads]
|
2018-12-13 06:08:53 -05:00
|
|
|
before_action :authorize_read_release!
|
2019-10-15 20:06:16 -04:00
|
|
|
before_action do
|
2019-11-08 07:06:32 -05:00
|
|
|
push_frontend_feature_flag(:release_issue_summary, project)
|
2020-01-16 16:08:24 -05:00
|
|
|
push_frontend_feature_flag(:release_evidence_collection, project, default_enabled: true)
|
2020-03-05 22:08:08 -05:00
|
|
|
push_frontend_feature_flag(:release_show_page, project, default_enabled: true)
|
2019-10-15 20:06:16 -04:00
|
|
|
end
|
2019-10-31 23:06:26 -04:00
|
|
|
before_action :authorize_update_release!, only: %i[edit update]
|
2020-01-02 16:07:38 -05:00
|
|
|
before_action :authorize_read_release_evidence!, only: [:evidence]
|
2018-12-10 07:03:00 -05:00
|
|
|
|
|
|
|
def index
|
2019-10-28 17:06:24 -04:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
require_non_empty_project
|
|
|
|
end
|
|
|
|
format.json { render json: releases }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-11-19 04:06:16 -05:00
|
|
|
def evidence
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: release.evidence_summary
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-29 13:08:47 -05:00
|
|
|
def show
|
2020-03-05 22:08:08 -05:00
|
|
|
return render_404 unless Feature.enabled?(:release_show_page, project, default_enabled: true)
|
2020-01-29 13:08:47 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
render :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-04 07:07:52 -05:00
|
|
|
def downloads
|
|
|
|
redirect_to link.url
|
|
|
|
end
|
|
|
|
|
2019-10-28 17:06:24 -04:00
|
|
|
protected
|
|
|
|
|
|
|
|
def releases
|
|
|
|
ReleasesFinder.new(@project, current_user).execute
|
2018-12-10 07:03:00 -05:00
|
|
|
end
|
2019-10-31 23:06:26 -04:00
|
|
|
|
|
|
|
def edit
|
|
|
|
respond_to do |format|
|
2020-01-29 13:08:47 -05:00
|
|
|
format.html do
|
|
|
|
render :edit
|
|
|
|
end
|
2019-10-31 23:06:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def authorize_update_release!
|
|
|
|
access_denied! unless can?(current_user, :update_release, release)
|
|
|
|
end
|
|
|
|
|
2020-01-02 16:07:38 -05:00
|
|
|
def authorize_read_release_evidence!
|
|
|
|
access_denied! unless Feature.enabled?(:release_evidence, project, default_enabled: true)
|
|
|
|
access_denied! unless can?(current_user, :read_release_evidence, release)
|
|
|
|
end
|
|
|
|
|
2019-10-31 23:06:26 -04:00
|
|
|
def release
|
|
|
|
@release ||= project.releases.find_by_tag!(sanitized_tag_name)
|
|
|
|
end
|
|
|
|
|
2020-03-04 07:07:52 -05:00
|
|
|
def link
|
|
|
|
release.links.find_by_filepath!(sanitized_filepath)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sanitized_filepath
|
|
|
|
CGI.unescape(params[:filepath])
|
|
|
|
end
|
|
|
|
|
2019-10-31 23:06:26 -04:00
|
|
|
def sanitized_tag_name
|
|
|
|
CGI.unescape(params[:tag])
|
|
|
|
end
|
2015-11-05 05:16:41 -05:00
|
|
|
end
|