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

45 lines
1.1 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-01-03 14:25:43 +05:30
feature_category :templates
2016-09-13 17:45:13 +05:30
def show
template = @template_type.find(params[:key], project)
respond_to do |format|
format.json { render json: template.to_json }
end
end
2019-12-21 20:55:43 +05:30
def names
templates = @template_type.dropdown_names(project)
respond_to do |format|
format.json { render json: templates }
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