Inline event notifiers

This commit is contained in:
Jorge Manrubia
2025-04-23 11:06:43 +02:00
parent b510ca0318
commit ab54cafd84
9 changed files with 32 additions and 38 deletions
+4 -1
View File
@@ -16,7 +16,10 @@ class Event < ApplicationRecord
action == "assigned" || initial_assignment?
end
# E.g: completed? is true if action == "completed"
def action
super.inquiry
end
def method_missing(method_name, *args, &block)
if method_name.to_s.end_with?("?")
action == method_name.to_s.chomp("?")
+4 -4
View File
@@ -4,10 +4,10 @@ class Notifier
class << self
def for(source)
case source
when Event
"Notifier::Events::#{source.action.classify}".safe_constantize&.new(source)
when ::Mention
Notifier::Mention.new(source)
when ::Event
Notifier::Event.new(source)
when ::Mention
Notifier::Mention.new(source)
end
end
end
+23
View File
@@ -0,0 +1,23 @@
class Notifier::Event < Notifier
delegate :card, :creator, to: :source
private
def resource
if source.action.commented?
source.comment
else
card
end
end
def recipients
case source.action
when "assigned"
source.assignees.excluding(card.collection.access_only_users)
when "published"
card.watchers_and_subscribers(include_only_watching: true).without(creator)
else
card.watchers_and_subscribers.without(creator)
end
end
end
-6
View File
@@ -1,6 +0,0 @@
class Notifier::Events::Assigned < Notifier::Events::Base
private
def recipients
source.assignees.excluding(card.collection.access_only_users)
end
end
-12
View File
@@ -1,12 +0,0 @@
class Notifier::Events::Base < Notifier
delegate :card, :creator, to: :source
private
def resource
card
end
def recipients
card.watchers_and_subscribers.without(creator)
end
end
-2
View File
@@ -1,2 +0,0 @@
class Notifier::Events::Closed < Notifier::Events::Base
end
-6
View File
@@ -1,6 +0,0 @@
class Notifier::Events::Commented < Notifier::Events::Base
private
def resource
source.comment
end
end
-6
View File
@@ -1,6 +0,0 @@
class Notifier::Events::Published < Notifier::Events::Base
private
def recipients
card.watchers_and_subscribers(include_only_watching: true).without(creator)
end
end
+1 -1
View File
@@ -2,7 +2,7 @@ require "test_helper"
class NotifierTest < ActiveSupport::TestCase
test "for returns the matching notifier class for the event" do
assert_kind_of Notifier::Events::Published, Notifier.for(events(:logo_published))
assert_kind_of Notifier::Event, Notifier.for(events(:logo_published))
end
test "generate does not create notifications if the event was system-generated" do