From 6d4232742b03ffa955fdab19673df22f02619972 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Sat, 7 Nov 2026 15:04:36 +0800 Subject: [PATCH] FIX: Use every input for watch users and categories, and split list values Watch users and watch categories only used their first input. They now follow the same rule as tags and recipients: plain inputs add up, and conditional inputs keep first match wins. A user selector field stores several people as one comma separated value, and a list input stores one entry per line. These values are now split, so they work as recipients, tags, watch users and categories. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DSz8MWXii43sifu8gH46aE --- lib/custom_wizard/action.rb | 17 ++--- plugin.rb | 2 +- spec/components/custom_wizard/action_spec.rb | 74 ++++++++++++++++---- 3 files changed, 67 insertions(+), 26 deletions(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index 9efd792e6..ccfe280d7 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -169,10 +169,7 @@ def watch_tags end def watch_categories - watched_categories = - CustomWizard::Mapper.new(inputs: action["categories"], data: mapper_data, user: user).perform - - watched_categories = [*watched_categories].map(&:to_i) + watched_categories = map_list(action["categories"]).map(&:to_i) notification_level = action["notification_level"] @@ -424,18 +421,18 @@ def map_list(inputs) }, ).perform - Array.wrap(output).flatten.compact_blank + Array + .wrap(output) + .flatten + .flat_map { |value| value.is_a?(String) ? value.split(/[,\n]/).map(&:strip) : value } + .compact_blank end def action_users users = [] if action["usernames"].present? - output = - CustomWizard::Mapper.new(inputs: action["usernames"], data: mapper_data, user: user).perform - values = Array.wrap(output).flatten.flat_map { |value| value.to_s.split(",") } - usernames = values.filter_map { |value| User.normalize_username(value.strip) } - + usernames = map_list(action["usernames"]).map { |value| User.normalize_username(value) } users.push(*User.where(username_lower: usernames)) end diff --git a/plugin.rb b/plugin.rb index 18e974d31..340a37e35 100644 --- a/plugin.rb +++ b/plugin.rb @@ -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.18.10 +# version: 2.18.11 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever, Marcos Gutierrez # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech diff --git a/spec/components/custom_wizard/action_spec.rb b/spec/components/custom_wizard/action_spec.rb index 5b806b0e2..e1a983b4e 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -151,6 +151,14 @@ def topic_tags expect(topic_tags).to contain_exactly(tag.name, tag2.name) end + it "adds each tag of a list input" do + set_tag_inputs(text_input("#{tag.name}\n#{tag2.name}").merge(output_type: "list")) + + complete_wizard + + expect(topic_tags).to contain_exactly(tag.name, tag2.name) + end + it "adds the tags of every input" do set_tag_inputs(tag_field_input, text_input(tag2.name)) @@ -417,6 +425,15 @@ def composer_query context "standard actions" do before { Jobs.run_immediately! } + let(:step_1_field_1_input) do + { + type: "assignment", + output_type: "wizard_field", + output_connector: "set", + output: "step_1_field_1", + } + end + it "watches tags" do watch_tags[:tags][0][:output] = tag.name wizard_template[:actions] << watch_tags @@ -504,6 +521,28 @@ def composer_query ).to match_array([user1.id, user2.id]) end + it "watches the categories of every category input for the users of every user input" do + category2 = Fabricate(:category) + user2 = Fabricate(:user) + + watch_categories[:categories] = [category, category2].map do |c| + { type: "assignment", output_type: "category", output_connector: "set", output: [c.id] } + end + watch_categories[:wizard_user] = false + watch_categories[:usernames] = [user1, user2].map do |u| + { type: "assignment", output_type: "user", output_connector: "set", output: [u.username] } + end + wizard_template[:actions] << watch_categories + update_template(wizard_template) + + wizard = CustomWizard::Builder.new(@template[:id], user).build + wizard.create_updater(wizard.steps[0].id, step_1_field_1: "Text input").update + + expect( + CategoryUser.where(notification_level: 2).pluck(:user_id, :category_id), + ).to match_array([user1, user2].product([category, category2]).map { |u, c| [u.id, c.id] }) + end + it "#send_message" do Jobs.run_immediately! @@ -578,12 +617,7 @@ def composer_query it "#send_message sends to the recipients of every recipient input" do send_message_multi["recipient"] = [ - { - type: "assignment", - output_type: "wizard_field", - output_connector: "set", - output: "step_1_field_1", - }, + step_1_field_1_input, { type: "assignment", output_type: "user", @@ -606,7 +640,24 @@ def composer_query wizard.create_updater(wizard.steps[1].id, {}).update topic = - Topic.find_by(archetype: Archetype.private_message, title: "Multiple Recipients title") + Topic.find_by!(archetype: Archetype.private_message, title: "Multiple Recipients title") + expect(topic.allowed_users).to include(user1) + expect(topic.allowed_groups).to contain_exactly(group) + end + + it "#send_message sends to each recipient in a comma separated value" do + send_message["recipient"] = [step_1_field_1_input] + wizard_template["actions"] << send_message + update_template(wizard_template) + + wizard = CustomWizard::Builder.new(@template[:id], user).build + wizard.create_updater( + wizard.steps[0].id, + step_1_field_1: "#{user1.username},#{group.name}", + ).update + wizard.create_updater(wizard.steps[1].id, {}).update + + topic = Topic.find_by!(archetype: Archetype.private_message, title: "Message title") expect(topic.allowed_users).to include(user1) expect(topic.allowed_groups).to contain_exactly(group) end @@ -714,14 +765,7 @@ def complete_as_guest(email) wizard_template["permitted"] = guests_permitted["permitted"] wizard_template.delete("actions") - send_message["recipient"] = [ - { - type: "assignment", - output: "step_1_field_1", - output_type: "wizard_field", - output_connector: "set", - }, - ] + send_message["recipient"] = [step_1_field_1_input] wizard_template["actions"] = [send_message] update_template(wizard_template)