debian-mirror-gitlab/app/controllers/projects/releases_controller.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
2.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2015-11-26 14:37:03 +05:30
class Projects::ReleasesController < Projects::ApplicationController
# Authorize
2019-12-26 22:10:19 +05:30
before_action :require_non_empty_project, except: [:index]
2020-04-08 14:13:33 +05:30
before_action :release, only: %i[edit show update downloads]
2019-02-15 15:39:39 +05:30
before_action :authorize_read_release!
2019-12-26 22:10:19 +05:30
before_action :authorize_update_release!, only: %i[edit update]
2020-07-28 23:09:34 +05:30
before_action :authorize_create_release!, only: :new
2022-05-07 20:08:51 +05:30
before_action :validate_suffix_path, :fetch_latest_tag, only: :latest_permalink
2015-11-26 14:37:03 +05:30
2023-04-23 21:23:45 +05:30
prepend_before_action(only: [:downloads]) do
authenticate_sessionless_user!(:download)
end
2021-01-03 14:25:43 +05:30
feature_category :release_orchestration
2022-07-16 23:28:13 +05:30
urgency :low
2021-01-03 14:25:43 +05:30
2019-02-15 15:39:39 +05:30
def index
2019-12-26 22:10:19 +05:30
respond_to do |format|
format.html do
require_non_empty_project
end
2022-07-16 23:28:13 +05:30
format.json do
2022-07-23 23:45:48 +05:30
render json: ReleaseSerializer.new.represent(releases)
2022-07-16 23:28:13 +05:30
end
2019-12-26 22:10:19 +05:30
end
end
2020-04-08 14:13:33 +05:30
def downloads
redirect_to link.url
end
2022-05-07 20:08:51 +05:30
def latest_permalink
unless @latest_tag.present?
return render_404
end
query_parameters_except_order_by = request.query_parameters.except(:order_by)
redirect_url = project_release_url(@project, @latest_tag)
redirect_url += "/#{params[:suffix_path]}" if params[:suffix_path]
redirect_url += "?#{query_parameters_except_order_by.compact.to_param}" if query_parameters_except_order_by.present?
redirect_to redirect_url
end
2020-07-28 23:09:34 +05:30
private
2019-12-26 22:10:19 +05:30
2022-05-07 20:08:51 +05:30
def releases(params = {})
ReleasesFinder.new(@project, current_user, params).execute
2019-12-26 22:10:19 +05:30
end
def authorize_update_release!
access_denied! unless can?(current_user, :update_release, release)
end
def release
2022-07-23 23:45:48 +05:30
@release ||= project.releases.find_by_tag!(params[:tag])
2019-12-26 22:10:19 +05:30
end
2020-04-08 14:13:33 +05:30
def link
2022-07-23 23:45:48 +05:30
release.links.find_by_filepath!("/#{params[:filepath]}")
2015-11-26 14:37:03 +05:30
end
2022-05-07 20:08:51 +05:30
# Default order_by is 'released_at', which is set in ReleasesFinder.
# Also if the passed order_by is invalid, we reject and default to 'released_at'.
def fetch_latest_tag
allowed_values = ['released_at']
params.reject! { |key, value| key.to_sym == :order_by && !allowed_values.any?(value) }
@latest_tag = releases(order_by: params[:order_by]).first&.tag
end
def validate_suffix_path
Gitlab::Utils.check_path_traversal!(params[:suffix_path]) if params[:suffix_path]
end
2015-11-26 14:37:03 +05:30
end