discourse/app/controllers/form_templates_controller.rb
Linca 1198397c0f
FIX: Process templates before previewing (#33848)
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
2025-07-29 15:09:02 +08:00

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