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

52 lines
1.4 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
class Projects::TemplatesController < Projects::ApplicationController
2019-07-07 11:18:12 +05:30
before_action :authenticate_user!
before_action :authorize_can_read_issuable!
before_action :get_template_class
2016-09-13 17:45:13 +05:30
2021-10-27 15:23:28 +05:30
feature_category :source_code_management
2021-12-11 22:18:48 +05:30
urgency :low, [:names]
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
def index
templates = @template_type.template_subsets(project)
respond_to do |format|
2023-01-13 00:05:48 +05:30
format.json { render json: Gitlab::Json.dump(templates) }
2021-01-29 00:20:46 +05:30
end
end
2016-09-13 17:45:13 +05:30
def show
template = @template_type.find(params[:key], project)
respond_to do |format|
2023-01-13 00:05:48 +05:30
format.json { render json: Gitlab::Json.dump(template) }
2016-09-13 17:45:13 +05:30
end
end
2019-12-21 20:55:43 +05:30
def names
respond_to do |format|
2021-09-04 01:27:46 +05:30
format.json { render json: TemplateFinder.all_template_names(project, params[:template_type].to_s.pluralize) }
2019-12-21 20:55:43 +05:30
end
end
2016-09-13 17:45:13 +05:30
private
2019-07-07 11:18:12 +05:30
# User must have:
# - `read_merge_request` to see merge request templates, or
# - `read_issue` to see issue templates
#
# Note params[:template_type] has a route constraint to limit it to
# `merge_request` or `issue`
def authorize_can_read_issuable!
action = [:read_, params[:template_type]].join
authorize_action!(action)
end
2016-09-13 17:45:13 +05:30
def get_template_class
template_types = { issue: Gitlab::Template::IssueTemplate, merge_request: Gitlab::Template::MergeRequestTemplate }.with_indifferent_access
@template_type = template_types[params[:template_type]]
end
end