0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 01:10:28 +01:00

Add email address support to send_message recipients

See further https://coop.pavilion.tech/t/custom-wizard-pm-access-and-send-copy-of-submission-for-guest-users/3600
Dieser Commit ist enthalten in:
Angus McLeod 2024-07-08 11:58:24 +02:00
Ursprung 247a3d551c
Commit 441ad49bf6
2 geänderte Dateien mit 41 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -119,20 +119,22 @@ class CustomWizard::Action
params[:target_group_names] = [] params[:target_group_names] = []
params[:target_usernames] = [] params[:target_usernames] = []
params[:target_emails] = []
[*targets].each do |target| [*targets].each do |target|
if Group.find_by(name: target) if Group.find_by(name: target)
params[:target_group_names] << target params[:target_group_names] << target
elsif User.find_by_username(target) elsif User.find_by_username(target)
params[:target_usernames] << target params[:target_usernames] << target
else elsif target.match(/@/) # Compare discourse/discourse/app/controllers/posts_controller.rb#L922-L923
# params[:target_emails] << target
end end
end end
if params[:title].present? && if params[:title].present? &&
params[:raw].present? && params[:raw].present? &&
(params[:target_usernames].present? || (params[:target_usernames].present? ||
params[:target_group_names].present?) params[:target_group_names].present? ||
params[:target_emails].present?)
params[:archetype] = Archetype.private_message params[:archetype] = Archetype.private_message

Datei anzeigen

@ -333,7 +333,7 @@ describe CustomWizard::Action do
expect(user2.reload.notifications.count).to eq(1) expect(user2.reload.notifications.count).to eq(1)
end end
it "send_message works with guests are permitted" do it "send_message works when guests are permitted" do
wizard_template["permitted"] = guests_permitted["permitted"] wizard_template["permitted"] = guests_permitted["permitted"]
wizard_template.delete("actions") wizard_template.delete("actions")
wizard_template['actions'] = [send_message] wizard_template['actions'] = [send_message]
@ -354,6 +354,41 @@ describe CustomWizard::Action do
expect(topic.first.topic_allowed_users.second.user.username).to eq(Discourse.system_user.username) expect(topic.first.topic_allowed_users.second.user.username).to eq(Discourse.system_user.username)
expect(post.exists?).to eq(true) expect(post.exists?).to eq(true)
end end
it "send_message works when guests are permitted and the target is an email address" do
Jobs.run_immediately!
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"
}
]
wizard_template['actions'] = [send_message]
update_template(wizard_template)
NotificationEmailer.expects(:process_notification).once
wizard = CustomWizard::Builder.new(wizard_template["id"], nil, CustomWizard::Wizard.generate_guest_id).build
wizard.create_updater(wizard.steps[0].id, step_1_field_1: "guest@email.com").update
updater = wizard.create_updater(wizard.steps[1].id, {})
updater.update
topic = Topic.where(archetype: Archetype.private_message, title: "Message title")
post = Post.where(topic_id: topic.pluck(:id))
expect(topic.exists?).to eq(true)
expect(topic.first.topic_allowed_users.first.user.staged).to eq(true)
expect(topic.first.topic_allowed_users.first.user.primary_email.email).to eq('guest@email.com')
expect(topic.first.topic_allowed_users.second.user.username).to eq(Discourse.system_user.username)
expect(post.exists?).to eq(true)
end
end end
context "business subscription actions" do context "business subscription actions" do