Class: Hyrax::Workflow::AbstractNotification Abstract

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::UrlHelper
Defined in:
app/services/hyrax/workflow/abstract_notification.rb

Overview

This class is abstract.

A notification that happens when a state transition occurs. Subclass AbstractNotification to create a notification.

Examples:

module Hyrax
  module Workflow
    class LocalApprovedNotification < AbstractNotification
      private

        def subject
          "Deposit #{title} has been approved"
        end

        def message
          "#{title} (#{link_to work_id, document_path}) has been approved by #{user.display_name}  #{comment}"
        end

        # Add the user who initiated this action to the list of users being notified
        def users_to_notify
          super << user
        end
    end
  end
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity, comment, user, recipients) ⇒ AbstractNotification

Returns a new instance of AbstractNotification.

Parameters:

  • entity (Sipity::Entity)
    • the Sipity::Entity that is a proxy for the relevant Hyrax work

  • comment (#comment)
    • the comment associated with the action being taken, could be a Sipity::Comment, or anything that responds to a #comment method

  • user (Hyrax::User)
    • the user who has performed the relevant action

  • recipients (Hash)
    • a hash with keys “to” and (optionally) “cc”

Options Hash (recipients):

  • :to (Array<Hyrax::User>)

    a list of users to which to send the notification

  • :cc (Array<Hyrax::User>)

    a list of users to which to copy on the notification


40
41
42
43
44
45
46
47
48
# File 'app/services/hyrax/workflow/abstract_notification.rb', line 40

def initialize(entity, comment, user, recipients)
  @work_id = entity.proxy_for_global_id.sub(/.*\//, '')
  @title = entity.proxy_for.title.first
  @comment = comment.respond_to?(:comment) ? comment.comment.to_s : ''
  # Convert to hash with indifferent access to allow both string and symbol keys
  @recipients = recipients.with_indifferent_access
  @user = user
  @entity = entity
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment


32
33
34
# File 'app/services/hyrax/workflow/abstract_notification.rb', line 32

def comment
  @comment
end

#recipientsObject (readonly)

Returns the value of attribute recipients


32
33
34
# File 'app/services/hyrax/workflow/abstract_notification.rb', line 32

def recipients
  @recipients
end

#titleObject (readonly)

Returns the value of attribute title


32
33
34
# File 'app/services/hyrax/workflow/abstract_notification.rb', line 32

def title
  @title
end

#userObject (readonly)

Returns the value of attribute user


32
33
34
# File 'app/services/hyrax/workflow/abstract_notification.rb', line 32

def user
  @user
end

#work_idObject (readonly)

Returns the value of attribute work_id


32
33
34
# File 'app/services/hyrax/workflow/abstract_notification.rb', line 32

def work_id
  @work_id
end

Class Method Details

.send_notification(entity:, comment:, user:, recipients:) ⇒ Object


28
29
30
# File 'app/services/hyrax/workflow/abstract_notification.rb', line 28

def self.send_notification(entity:, comment:, user:, recipients:)
  new(entity, comment, user, recipients).call
end

Instance Method Details

#callObject


50
51
52
53
54
# File 'app/services/hyrax/workflow/abstract_notification.rb', line 50

def call
  users_to_notify.uniq.each do |recipient|
    Hyrax::MessengerService.deliver(user, recipient, message, subject)
  end
end