A platform for community discussion. Free, open, simple.
FIX: Use topic email template for bulk topic invites (#44642)
Penar Musarajd150e372cad5
diff --git a/app/jobs/regular/bulk_invite.rb b/app/jobs/regular/bulk_invite.rbindex c4422d0d37c..e7ced018386 100644--- a/app/jobs/regular/bulk_invite.rb+++ b/app/jobs/regular/bulk_invite.rb@@ -179,6 +179,7 @@ module Jobsinvite_opts = {email: email,topic: topic,+ invite_to_topic: topic.present?,group_ids: groups.map(&:id),skip_email: @skip_email,}diff --git a/app/jobs/regular/process_bulk_invite_emails.rb b/app/jobs/regular/process_bulk_invite_emails.rbindex 26152b8a873..7b270140e1e 100644--- a/app/jobs/regular/process_bulk_invite_emails.rb+++ b/app/jobs/regular/process_bulk_invite_emails.rb@@ -13,7 +13,14 @@ module JobsInvite.where(id: pending_invite_ids).update_all(emailed_status: Invite.emailed_status_types[:sending],)- pending_invite_ids.each { |invite_id| ::Jobs.enqueue(:invite_email, invite_id: invite_id) }+ topic_invite_ids = TopicInvite.where(invite_id: pending_invite_ids).pluck(:invite_id).to_set+ pending_invite_ids.each do |invite_id|+ ::Jobs.enqueue(+ :invite_email,+ invite_id: invite_id,+ invite_to_topic: topic_invite_ids.include?(invite_id),+ )+ end::Jobs.enqueue_in(1.minute, :process_bulk_invite_emails)endenddiff --git a/spec/jobs/bulk_invite_spec.rb b/spec/jobs/bulk_invite_spec.rbindex ceca0ab0d49..51c03d0e187 100644--- a/spec/jobs/bulk_invite_spec.rb+++ b/spec/jobs/bulk_invite_spec.rb@@ -59,6 +59,32 @@ RSpec.describe Jobs::BulkInvite doexpect(post.raw).to include("1 error")end+ it "selects topic invitation emails only for rows with a valid topic" do+ described_class.new.execute(+ current_user_id: admin.id,+ invites: [+ { email: "[email protected]", topic_id: topic.id },+ { email: "[email protected]" },+ { email: "[email protected]", topic_id: -1 },+ ],+ )++ expect(Jobs::InviteEmail.jobs.map { |job| job["args"].first }).to contain_exactly(+ hash_including(+ "invite_id" => Invite.find_by!(email: "[email protected]").id,+ "invite_to_topic" => true,+ ),+ hash_including(+ "invite_id" => Invite.find_by!(email: "[email protected]").id,+ "invite_to_topic" => false,+ ),+ hash_including(+ "invite_id" => Invite.find_by!(email: "[email protected]").id,+ "invite_to_topic" => false,+ ),+ )+ end+it "handles daylight savings time correctly" do# EDT (-04:00) transitions to EST (-05:00) on the first Sunday in November.# Freeze time to the last Day of October, so that the creation and expiration date will be in different time zones.diff --git a/spec/jobs/process_bulk_invite_emails_spec.rb b/spec/jobs/process_bulk_invite_emails_spec.rbindex 021dcb0b34e..4957e7aaf09 100644--- a/spec/jobs/process_bulk_invite_emails_spec.rb+++ b/spec/jobs/process_bulk_invite_emails_spec.rb@@ -12,5 +12,18 @@ RSpec.describe Jobs::ProcessBulkInviteEmails doexpect(Jobs::InviteEmail.jobs.size).to eq(1)expect(Jobs::ProcessBulkInviteEmails.jobs.size).to eq(1)end++ it "selects topic invitation emails for pending invites with a topic" do+ topic_invite = Fabricate(:invite, emailed_status: Invite.emailed_status_types[:bulk_pending])+ topic_invite.topics << Fabricate(:topic)+ forum_invite = Fabricate(:invite, emailed_status: Invite.emailed_status_types[:bulk_pending])++ described_class.new.execute({})++ expect(Jobs::InviteEmail.jobs.map { |job| job["args"].first }).to contain_exactly(+ hash_including("invite_id" => topic_invite.id, "invite_to_topic" => true),+ hash_including("invite_id" => forum_invite.id, "invite_to_topic" => false),+ )+ endendend