Class: Activity::AssignmentNotificationHandler
- Inherits:
-
Object
- Object
- Activity::AssignmentNotificationHandler
- Defined in:
- app/subscribers/activity/assignment_notification_handler.rb
Overview
Sends an internal email notification to the employee assigned to an activity,
after the activity has been persisted and the transaction commits.
Subscribes to: Events::ActivityCreated, Events::ActivityUpdated
On create: notifies whenever the activity is open, the type requires
notifications, and the assigned resource is not the Heatwave assistant.
On update: same conditions PLUS the assigned_resource_id must have changed
(captured at callback time via dirty tracking and stored in event data).
Behavioural invariants:
- Never notifies the Heatwave assistant (Activity.heatwave_assistant_id).
- Never notifies a closed activity.
- Never notifies when assigned_resource has no email address.
Instance Method Summary collapse
Instance Method Details
#call(event) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/subscribers/activity/assignment_notification_handler.rb', line 19 def call(event) activity = Activity.find_by(id: event.data[:activity_id]) return unless activity return unless activity.open? return unless activity.activity_type&.notify_assigned_resource return if activity.assigned_resource_id == Activity.heatwave_assistant_id return unless activity.assigned_resource&.email if event.is_a?(Events::ActivityUpdated) return unless event.data[:assigned_resource_id_changed] end InternalMailer.notify_of_activity_assigned(activity.assigned_resource, activity).deliver_later end |