2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-05 10:16:41 +00:00
|
|
|
class Projects::ReleasesController < Projects::ApplicationController
|
|
|
|
# Authorize
|
2019-10-28 21:06:24 +00:00
|
|
|
before_action :require_non_empty_project, except: [:index]
|
2020-03-04 12:07:52 +00:00
|
|
|
before_action :release, only: %i[edit show update downloads]
|
2018-12-13 11:08:53 +00:00
|
|
|
before_action :authorize_read_release!
|
2019-10-16 00:06:16 +00:00
|
|
|
before_action do
|
2020-09-15 15:10:08 +00:00
|
|
|
push_frontend_feature_flag(:graphql_release_data, project, default_enabled: true)
|
|
|
|
push_frontend_feature_flag(:graphql_milestone_stats, project, default_enabled: true)
|
2020-09-18 15:09:22 +00:00
|
|
|
push_frontend_feature_flag(:graphql_releases_page, project, default_enabled: true)
|
2020-10-19 21:09:06 +00:00
|
|
|
push_frontend_feature_flag(:graphql_individual_release_page, project, default_enabled: true)
|
2019-10-16 00:06:16 +00:00
|
|
|
end
|
2019-11-01 03:06:26 +00:00
|
|
|
before_action :authorize_update_release!, only: %i[edit update]
|
2020-06-24 18:09:03 +00:00
|
|
|
before_action :authorize_create_release!, only: :new
|
2018-12-10 12:03:00 +00:00
|
|
|
|
2020-10-08 18:08:32 +00:00
|
|
|
feature_category :release_orchestration
|
|
|
|
|
2018-12-10 12:03:00 +00:00
|
|
|
def index
|
2019-10-28 21:06:24 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
require_non_empty_project
|
|
|
|
end
|
|
|
|
format.json { render json: releases }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-09 15:08:59 +00:00
|
|
|
def new
|
2020-08-11 03:11:00 +00:00
|
|
|
unless Feature.enabled?(:new_release_page, project, default_enabled: true)
|
2020-07-11 00:09:17 +00:00
|
|
|
redirect_to(new_project_tag_path(@project))
|
2020-01-29 18:08:47 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-04 12:07:52 +00:00
|
|
|
def downloads
|
|
|
|
redirect_to link.url
|
|
|
|
end
|
|
|
|
|
2020-07-09 15:08:59 +00:00
|
|
|
private
|
2019-10-28 21:06:24 +00:00
|
|
|
|
|
|
|
def releases
|
|
|
|
ReleasesFinder.new(@project, current_user).execute
|
2018-12-10 12:03:00 +00:00
|
|
|
end
|
2019-11-01 03:06:26 +00:00
|
|
|
|
|
|
|
def authorize_update_release!
|
|
|
|
access_denied! unless can?(current_user, :update_release, release)
|
|
|
|
end
|
|
|
|
|
|
|
|
def release
|
|
|
|
@release ||= project.releases.find_by_tag!(sanitized_tag_name)
|
|
|
|
end
|
|
|
|
|
2020-03-04 12:07:52 +00:00
|
|
|
def link
|
|
|
|
release.links.find_by_filepath!(sanitized_filepath)
|
|
|
|
end
|
|
|
|
|
|
|
|
def sanitized_filepath
|
2020-11-12 15:09:09 +00:00
|
|
|
"/#{CGI.unescape(params[:filepath])}"
|
2020-03-04 12:07:52 +00:00
|
|
|
end
|
|
|
|
|
2019-11-01 03:06:26 +00:00
|
|
|
def sanitized_tag_name
|
|
|
|
CGI.unescape(params[:tag])
|
|
|
|
end
|
2015-11-05 10:16:41 +00:00
|
|
|
end
|