Don't notify while bubbles are still drafted

This commit is contained in:
Kevin McConnell
2025-01-15 11:42:35 +00:00
parent 731f93b55a
commit 056d853cc8
3 changed files with 32 additions and 3 deletions
+10 -1
View File
@@ -14,8 +14,8 @@ module NotificationsHelper
case notification.event.action
when "assigned" then "#{name} assigned to you"
when "published" then "Added by #{name}"
when "popped" then "Popped by by #{name}"
when "published" then notification_bubble_created_message(notification)
else name
end
end
@@ -24,4 +24,13 @@ module NotificationsHelper
link_to notification.resource, id: dom_id(notification), class: "notification border-radius",
data: { turbo_frame: "_top" }, &
end
private
def notification_bubble_created_message(notification)
if notification.bubble.assigned_to?(notification.user)
"#{notification.creator.name} assigned to you"
else
"Added by #{notification.creator.name}"
end
end
end
+8 -2
View File
@@ -10,8 +10,10 @@ class Notifier
end
def generate
recipients.map do |recipient|
Notification.create! user: recipient, event: event, bubble: bubble, resource: resource
if should_notify?
recipients.map do |recipient|
Notification.create! user: recipient, event: event, bubble: bubble, resource: resource
end
end
end
@@ -20,6 +22,10 @@ class Notifier
@event = event
end
def should_notify?
bubble.published?
end
def recipients
bubble.bucket.users.without(creator)
end
+14
View File
@@ -12,4 +12,18 @@ class NotifierTest < ActiveSupport::TestCase
end
end
end
test "generate creates notifications for the event recipients" do
assert_difference -> { Notification.count }, +2 do
Notifier.for(events(:logo_published)).generate
end
end
test "generate does not create notifications if the bubble is not published" do
bubbles(:logo).drafted!
assert_no_difference -> { Notification.count } do
Notifier.for(events(:logo_published)).generate
end
end
end