Inline event notifiers
This commit is contained in:
+4
-1
@@ -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,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
|
||||
|
||||
@@ -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
|
||||
@@ -1,6 +0,0 @@
|
||||
class Notifier::Events::Assigned < Notifier::Events::Base
|
||||
private
|
||||
def recipients
|
||||
source.assignees.excluding(card.collection.access_only_users)
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
@@ -1,2 +0,0 @@
|
||||
class Notifier::Events::Closed < Notifier::Events::Base
|
||||
end
|
||||
@@ -1,6 +0,0 @@
|
||||
class Notifier::Events::Commented < Notifier::Events::Base
|
||||
private
|
||||
def resource
|
||||
source.comment
|
||||
end
|
||||
end
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user