FEATURE: Cleanup notifications when reassigning (#394)

If a topic is initially assigned to user A then reassigned to user B,
this change will make it so that notifications sent to user A are
removed. This matches the plugin's behaviour when unassigning a topic.
This commit is contained in:
Penar Musaraj 2022-11-24 10:42:19 -05:00 committed by GitHub
parent 1f2dfafcde
commit 4b8afc301a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -271,6 +271,15 @@ class ::Assigner
skip_small_action_post = skip_small_action_post || no_assignee_change?(assign_to)
if topic.assignment.present?
Jobs.enqueue(
:unassign_notification,
topic_id: topic.id,
assigned_to_id: topic.assignment.assigned_to_id,
assigned_to_type: topic.assignment.assigned_to_type,
)
end
@target.assignment&.destroy!
assignment =

View File

@ -43,6 +43,19 @@ RSpec.describe Assigner do
)
end
it "deletes notification for original assignee when reassigning" do
Jobs.run_immediately!
expect {
described_class.new(topic, admin).assign(moderator)
}.to change { moderator.notifications.count }.by(1)
expect {
described_class.new(topic, admin).assign(moderator_2)
}.to change { moderator.notifications.count }.by(-1)
.and change { moderator_2.notifications.count }.by(1)
end
it "can assign with note" do
assigner.assign(moderator, note: "tomtom best mom")