From 3e030ceb4ed06208d099dcc278dcfa3d5ab8f911 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Sat, 7 Nov 2026 14:31:58 +0800 Subject: [PATCH] FIX: Send messages to every recipient input and encode composer tags When recipients were spread over several inputs, only the first input's recipients got the message. Recipients now use the same rule as tags: plain inputs add up, and conditional inputs keep first match wins. Empty inputs are skipped, and a recipient named twice is added once, as core cancels a message that names a recipient twice. The open composer link added tags without encoding them, so a tag with "&" or "#" broke the link or changed other composer settings. Tags are now encoded like the title and body. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DSz8MWXii43sifu8gH46aE --- lib/custom_wizard/action.rb | 19 +++--- plugin.rb | 2 +- spec/components/custom_wizard/action_spec.rb | 68 ++++++++++++++++++-- 3 files changed, 70 insertions(+), 19 deletions(-) diff --git a/lib/custom_wizard/action.rb b/lib/custom_wizard/action.rb index 944965399..9efd792e6 100644 --- a/lib/custom_wizard/action.rb +++ b/lib/custom_wizard/action.rb @@ -74,13 +74,7 @@ def send_message params = basic_topic_params - targets = - CustomWizard::Mapper.new( - inputs: action["recipient"], - data: mapper_data, - user: user, - multiple: true, - ).perform + targets = map_list(action["recipient"]).uniq(&:downcase) if targets.blank? log_error("no recipients", "send_message has no recipients") @@ -90,7 +84,7 @@ def send_message params[:target_group_names] = [] params[:target_usernames] = [] params[:target_emails] = [] - [*targets].each do |target| + targets.each do |target| if Group.find_by(name: target) params[:target_group_names] << target elsif User.find_by_username(target) @@ -257,7 +251,7 @@ def open_composer end if tags = action_tags - url += "&tags=#{tags.join(",")}" + url += "&tags=#{encode_query_param(tags.join(","))}" end route_to = Discourse.base_uri + url @@ -416,7 +410,10 @@ def action_category end def action_tags - inputs = action["tags"] + CustomWizard::TagSearch.tag_names(map_list(action["tags"])).presence || false + end + + def map_list(inputs) output = CustomWizard::Mapper.new( inputs: inputs, @@ -427,7 +424,7 @@ def action_tags }, ).perform - CustomWizard::TagSearch.tag_names(output).presence || false + Array.wrap(output).flatten.compact_blank end def action_users diff --git a/plugin.rb b/plugin.rb index 32c504a9b..18e974d31 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.9 +# version: 2.18.10 # 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 a4b13ed46..5b806b0e2 100644 --- a/spec/components/custom_wizard/action_spec.rb +++ b/spec/components/custom_wizard/action_spec.rb @@ -354,10 +354,7 @@ def topic_tags ) end - it "encodes special characters in the title and body" do - open_composer["title"][0]["output"] = "Title that's special $".dup - open_composer["post_template"] = "Body & more body & more body".dup - + def composer_query wizard = CustomWizard::Wizard.new(@template, user) action = CustomWizard::Action.new( @@ -369,10 +366,32 @@ def topic_tags expect(action.result.success?).to eq(true) - decoded_output = CGI.parse(URI.parse(action.result.output).query) + CGI.parse(URI.parse(action.result.output).query) + end + + it "encodes special characters in the title and body" do + open_composer["title"][0]["output"] = "Title that's special $".dup + open_composer["post_template"] = "Body & more body & more body".dup - expect(decoded_output["title"][0]).to eq("Title that's special $") - expect(decoded_output["body"][0]).to eq("Body & more body & more body") + query = composer_query + + expect(query["title"]).to eq(["Title that's special $"]) + expect(query["body"]).to eq(["Body & more body & more body"]) + end + + it "encodes special characters in tags" do + open_composer["tags"] = [ + { + type: "assignment", + output_type: "text", + output_connector: "set", + output: "#{tag.name},x&category_id=99", + }, + ] + + query = composer_query + + expect(query["tags"]).to eq(["#{tag.name},x&category_id=99"]) end end @@ -557,6 +576,41 @@ def topic_tags expect(user2.reload.notifications.count).to eq(1) end + 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", + }, + { + type: "assignment", + output_type: "user", + output_connector: "set", + output: [user1.username], + }, + { type: "assignment", output_type: "text", output_connector: "set", output: group.name }, + { + type: "assignment", + output_type: "text", + output_connector: "set", + output: user1.username.upcase, + }, + ] + wizard_template["actions"] << send_message_multi + update_template(wizard_template) + + wizard = CustomWizard::Builder.new(@template[:id], user).build + wizard.create_updater(wizard.steps[0].id, {}).update + wizard.create_updater(wizard.steps[1].id, {}).update + + topic = + 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 + context "with a guest" do describe "#create_topic" do before do