Skip to content

Commit 8a1f369

Browse files
authored
GYR1-839 Stop suspended hub users from receiving external email notifications (#6117)
1 parent ff589fa commit 8a1f369

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

app/services/interaction_tracking_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def self.record_incoming_interaction(client, set_flag: true, **attrs)
1010
should_record_interaction = interaction_type.present? && interaction_type != 'unfilled'
1111
if should_record_interaction && Flipper.enabled?(:hub_email_notifications)
1212
users_to_contact = client.tax_returns.pluck(:assigned_user_id).compact
13-
users_to_contact = User.where(id: users_to_contact, "#{interaction_type}_notification" => "yes")
13+
users_to_contact = User.active.where(id: users_to_contact, "#{interaction_type}_notification" => "yes")
1414
unless users_to_contact.empty?
1515
email_attrs = {
1616
received_at: attrs[:received_at] || interaction.created_at
@@ -45,7 +45,7 @@ def self.record_internal_interaction(client, **attrs)
4545

4646
if interaction_type == "tagged_in_note"
4747
user = attrs[:user]
48-
if user&.tagged_in_note_notification_yes? && Flipper.enabled?(:hub_email_notifications)
48+
if user&.tagged_in_note_notification_yes? && Flipper.enabled?(:hub_email_notifications) && user&.active?
4949
internal_email = InternalEmail.create!(
5050
mail_class: UserMailer,
5151
mail_method: :internal_interaction_notification_email,

spec/services/interaction_tracking_service_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@
152152
expect(job).not_to have_received(:perform_later)
153153
end
154154
end
155+
156+
context "user that has been suspended" do
157+
let!(:suspended_user) { create(:admin_user, new_client_message_notification: "yes", suspended_at: 1.day.ago) }
158+
let!(:tax_return_3) { create(:tax_return, assigned_user_id: suspended_user.id, year: Rails.configuration.product_year-2, client: client) }
159+
160+
it "doesn't send a message to suspended user" do
161+
described_class.record_incoming_interaction(client, received_at: fake_time, interaction_type: "new_client_message")
162+
expect(job).not_to have_received(:perform_later).with(anything, suspended_user, hash_including(received_at: fake_time))
163+
expect(job).to have_received(:perform_later).with(anything, user, hash_including(received_at: fake_time))
164+
end
165+
end
155166
end
156167

157168
describe "#record_internal_interaction" do
@@ -214,6 +225,15 @@
214225
expect(SendInternalEmailJob).not_to have_received(:perform_later)
215226
end
216227
end
228+
229+
context "user has been suspended" do
230+
let(:user) { create(:admin_user, tagged_in_note_notification: "yes", suspended_at: 1.day.ago) }
231+
232+
it "doesn't send a message" do
233+
described_class.record_internal_interaction(client, interaction_type: "tagged_in_note", user: user, received_at: received_at)
234+
expect(SendInternalEmailJob).not_to have_received(:perform_later)
235+
end
236+
end
217237
end
218238
end
219239
end

0 commit comments

Comments
 (0)