-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #273 from paviliondev/fix-wizard-topic-creation
FIX: Fix Topic Creation Restriction in Wizard
- Loading branch information
Showing
2 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# frozen_string_literal: true | ||
# name: discourse-custom-wizard | ||
# about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. | ||
# version: 2.4.23 | ||
# version: 2.4.24 | ||
# authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Juan Marcos Gutierrez Ramos | ||
# url: https://github.com/paviliondev/discourse-custom-wizard | ||
# contact_emails: [email protected] | ||
|
@@ -239,10 +239,11 @@ | |
|
||
on(:before_create_topic) do |topic_params, user| | ||
category = topic_params.category | ||
if category&.custom_fields&.[]('create_topic_wizard').present? | ||
wizard_submission_id = topic_params.custom_fields&.[]('wizard_submission_id') | ||
if category&.custom_fields&.[]('create_topic_wizard').present? && wizard_submission_id.blank? | ||
raise Discourse::InvalidParameters.new( | ||
I18n.t('wizard.error_messages.wizard_replacing_composer') | ||
) | ||
I18n.t('wizard.error_messages.wizard_replacing_composer') | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -450,4 +450,29 @@ def update_template(template) | |
expect(action.result.success?).to eq(true) | ||
expect(Topic.find(action.result.output).custom_fields["topic_custom_field"]).to eq("t") | ||
end | ||
|
||
context 'creating a topic when there are multiple actions' do | ||
it 'works' do | ||
wizard_template['actions'] << create_topic | ||
wizard_template['actions'] << send_message | ||
update_template(wizard_template) | ||
wizard = CustomWizard::Builder.new(@template[:id], user).build | ||
wizard.create_updater( | ||
wizard.steps.first.id, | ||
step_1_field_1: 'Topic Title', | ||
step_1_field_2: 'topic body' | ||
).update | ||
wizard.create_updater(wizard.steps.second.id, {}).update | ||
wizard.create_updater(wizard.steps.last.id, step_3_field_3: category.id) | ||
.update | ||
User.create(username: 'angus1', email: '[email protected]') | ||
wizard.create_updater(wizard.steps[0].id, {}).update | ||
wizard.create_updater(wizard.steps[1].id, {}).update | ||
topic = Topic.where(title: 'Topic Title', category_id: category.id) | ||
expect(topic.exists?).to eq(true) | ||
expect( | ||
Post.where(topic_id: topic.pluck(:id), raw: 'topic body').exists? | ||
).to eq(true) | ||
end | ||
end | ||
end |