Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions lib/custom_wizard/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
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.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
Expand Down
68 changes: 61 additions & 7 deletions spec/components/custom_wizard/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading