mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-05 19:11:00 +08:00
The bare template yaml file provided by the user cannot be directly used for form templates preview, because components such as `TagChooserField` actually rely on a backend process step. This step exists when users actually use the template, but is missing when the admin writes and previews the template. This commit supplements the missing process step, thus fixing the problem that tag-chooser may break ember during admin preview
29 lines
704 B
Ruby
29 lines
704 B
Ruby
# frozen_string_literal: true
|
|
|
|
class FormTemplatesController < ApplicationController
|
|
requires_login
|
|
before_action :ensure_form_templates_enabled
|
|
|
|
def index
|
|
form_templates = FormTemplate.all.order(:id)
|
|
render_serialized(form_templates, FormTemplateSerializer, root: "form_templates")
|
|
end
|
|
|
|
def show
|
|
params.require(:id)
|
|
|
|
template = FormTemplate.find_by(id: params[:id])
|
|
|
|
raise Discourse::NotFound if template.nil?
|
|
|
|
template.process!(guardian)
|
|
|
|
render_serialized(template, FormTemplateSerializer, root: "form_template")
|
|
end
|
|
|
|
private
|
|
|
|
def ensure_form_templates_enabled
|
|
raise Discourse::InvalidAccess.new unless SiteSetting.experimental_form_templates
|
|
end
|
|
end
|