From 0fe050fcb8d85901af0fff9ed287cc396c18bc25 Mon Sep 17 00:00:00 2001 From: Tahsina Islam Date: Tue, 25 Nov 2025 12:45:15 -0600 Subject: [PATCH 1/2] Stop suspended hub users from receiving emails --- app/services/interaction_tracking_service.rb | 2 +- spec/services/interaction_tracking_service_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/services/interaction_tracking_service.rb b/app/services/interaction_tracking_service.rb index 0a84855b3f..954e384cfb 100644 --- a/app/services/interaction_tracking_service.rb +++ b/app/services/interaction_tracking_service.rb @@ -10,7 +10,7 @@ def self.record_incoming_interaction(client, set_flag: true, **attrs) should_record_interaction = interaction_type.present? && interaction_type != 'unfilled' if should_record_interaction && Flipper.enabled?(:hub_email_notifications) users_to_contact = client.tax_returns.pluck(:assigned_user_id).compact - users_to_contact = User.where(id: users_to_contact, "#{interaction_type}_notification" => "yes") + users_to_contact = User.active.where(id: users_to_contact, "#{interaction_type}_notification" => "yes") unless users_to_contact.empty? email_attrs = { received_at: attrs[:received_at] || interaction.created_at diff --git a/spec/services/interaction_tracking_service_spec.rb b/spec/services/interaction_tracking_service_spec.rb index a244695d77..9ca78c58b1 100644 --- a/spec/services/interaction_tracking_service_spec.rb +++ b/spec/services/interaction_tracking_service_spec.rb @@ -152,6 +152,17 @@ expect(job).not_to have_received(:perform_later) end end + + context "user that has been suspended" do + let!(:suspended_user) { create(:admin_user, new_client_message_notification: "yes", suspended_at: 1.day.ago) } + let!(:tax_return_3) { create(:tax_return, assigned_user_id: suspended_user.id, year: Rails.configuration.product_year-2, client: client) } + + it "doesn't send a message to suspended user" do + described_class.record_incoming_interaction(client, received_at: fake_time, interaction_type: "new_client_message") + expect(job).not_to have_received(:perform_later).with(anything, suspended_user, hash_including(received_at: fake_time)) + expect(job).to have_received(:perform_later).with(anything, user, hash_including(received_at: fake_time)) + end + end end describe "#record_internal_interaction" do From 3b943bad4c17d523ee8d250532e985ea4b82f8ec Mon Sep 17 00:00:00 2001 From: Tahsina Islam Date: Tue, 25 Nov 2025 12:55:26 -0600 Subject: [PATCH 2/2] fix the tagg in note email --- app/services/interaction_tracking_service.rb | 2 +- spec/services/interaction_tracking_service_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/services/interaction_tracking_service.rb b/app/services/interaction_tracking_service.rb index 954e384cfb..e0da5254af 100644 --- a/app/services/interaction_tracking_service.rb +++ b/app/services/interaction_tracking_service.rb @@ -45,7 +45,7 @@ def self.record_internal_interaction(client, **attrs) if interaction_type == "tagged_in_note" user = attrs[:user] - if user&.tagged_in_note_notification_yes? && Flipper.enabled?(:hub_email_notifications) + if user&.tagged_in_note_notification_yes? && Flipper.enabled?(:hub_email_notifications) && user&.active? internal_email = InternalEmail.create!( mail_class: UserMailer, mail_method: :internal_interaction_notification_email, diff --git a/spec/services/interaction_tracking_service_spec.rb b/spec/services/interaction_tracking_service_spec.rb index 9ca78c58b1..9940d2ff76 100644 --- a/spec/services/interaction_tracking_service_spec.rb +++ b/spec/services/interaction_tracking_service_spec.rb @@ -225,6 +225,15 @@ expect(SendInternalEmailJob).not_to have_received(:perform_later) end end + + context "user has been suspended" do + let(:user) { create(:admin_user, tagged_in_note_notification: "yes", suspended_at: 1.day.ago) } + + it "doesn't send a message" do + described_class.record_internal_interaction(client, interaction_type: "tagged_in_note", user: user, received_at: received_at) + expect(SendInternalEmailJob).not_to have_received(:perform_later) + end + end end end end