From 24d7ca646a425af83cfb8054ef10af18e26ae843 Mon Sep 17 00:00:00 2001 From: jumagura Date: Mon, 2 Oct 2023 18:18:00 -0400 Subject: [PATCH] FIX: Refine Topic Creation Hook to Allow Wizard Multi-Step Functionality --- lib/custom_wizard/action.rb | 1 + plugin.rb | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index ac0799f3..ad261e9a 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -63,6 +63,7 @@ class CustomWizard::Action def create_topic params = basic_topic_params.merge(public_topic_params) + params[:from_wizard] = true callbacks_for(:before_create_topic).each do |acb| params = acb.call(params, @wizard, @action, @submission) diff --git a/plugin.rb b/plugin.rb index 7d3f7679..ed236919 100644 --- a/plugin.rb +++ b/plugin.rb @@ -238,11 +238,13 @@ after_initialize do DiscourseEvent.trigger(:custom_wizard_ready) on(:before_create_topic) do |topic_params, user| - category = topic_params.category - if category&.custom_fields&.[]('create_topic_wizard').present? + next if topic_params[:archetype] == 'message' + + if topic_params[:category]&.custom_fields&.[]('create_topic_wizard').present? && !topic_params[:from_wizard] raise Discourse::InvalidParameters.new( - I18n.t('wizard.error_messages.wizard_replacing_composer') - ) + I18n.t('wizard.error_messages.wizard_replacing_composer') + ) end end + end