fix: dont send noti when editor does not want to

fixes VICE-4499
flag=none

Test plan:
- Create a delayed announcement
- Edit its message and from date so its available
- click save & dont send
- no notification is sent

Change-Id: Ib59b967c913dbf2522a4e896cd623984eab940e7
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/354220
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Ádám Molnár <adam.molnar@instructure.com>
Product-Review: Tamás Balogh <tamas.balogh@instructure.com>
QA-Review: Dora Csolakov <dora.csolakov@instructure.com>
This commit is contained in:
Daniel Vincze 2024-08-02 15:47:01 +02:00 committed by Daniel Matyas Vincze
parent 84e5e57356
commit 57bad90a6e
3 changed files with 41 additions and 3 deletions

View File

@ -81,7 +81,7 @@ class Announcement < DiscussionTopic
dispatch :new_announcement
to { users_with_permissions(active_participants_include_tas_and_teachers(true) - [user]) }
whenever do |record|
is_new_announcement = (record.just_created and !(record.post_delayed? || record.unpublished?)) || record.changed_state(:active, :unpublished) || record.changed_state(:active, :post_delayed)
is_new_announcement = (record.just_created and !(record.post_delayed? || record.unpublished?)) || record.changed_state(:active, :unpublished)
record.send_notification_for_context? && (is_new_announcement || record.notify_users)
end
@ -90,8 +90,9 @@ class Announcement < DiscussionTopic
dispatch :announcement_created_by_you
to { user }
whenever do |record|
record.send_notification_for_context? and
((record.just_created and !(record.post_delayed? || record.unpublished?)) || record.changed_state(:active, :unpublished) || record.changed_state(:active, :post_delayed))
is_new_announcement = (record.just_created and !(record.post_delayed? || record.unpublished?)) || record.changed_state(:active, :unpublished)
record.send_notification_for_context? && is_new_announcement
end
data { course_broadcast_data }
end

View File

@ -980,6 +980,7 @@ class DiscussionTopic < ActiveRecord::Base
state :unpublished
state :post_delayed do
event :delayed_post, transitions_to: :active do
self.notify_users = true
self.last_reply_at = Time.now
self.posted_at = Time.now
end

View File

@ -243,5 +243,41 @@ describe Announcement do
expect(to_users).to include(@student)
expect(to_users).to_not include(other_student)
end
it "does not broadcast if it just got edited to active, if notify_users is false" do
course_with_student(active_all: true)
notification_name = "New Announcement"
Notification.create(name: notification_name, category: "TestImmediately")
announcement_model(user: @teacher, workflow_state: :post_delayed, notify_users: false, context: @course)
expect do
@a.publish!
end.not_to change { @a.messages_sent[notification_name] }
end
it "still broadcasts if it just got edited to active, if notify_users is true" do
course_with_student(active_all: true)
notification_name = "New Announcement"
Notification.create(name: notification_name, category: "TestImmediately")
announcement_model(user: @teacher, workflow_state: :post_delayed, notify_users: true, context: @course)
expect do
@a.publish!
end.to change { @a.messages_sent[notification_name] }
end
it "still broadcasts on delayed_post event even if notify_users was false" do
course_with_student(active_all: true)
notification_name = "New Announcement"
Notification.create(name: notification_name, category: "TestImmediately")
announcement_model(user: @teacher, workflow_state: :post_delayed, notify_users: false, context: @course)
expect do
@a.delayed_post
end.to change { @a.messages_sent[notification_name] }
end
end
end