Sha256: 86c6a7a455159b63e0d4ff1d155f1044024ba8d951a3f9ce9bf1243034037afc

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module Sufia
  module Workflow
    class AbstractNotification
      def self.send_notification(entity:, comment:, user:, recipients:)
        new(entity, comment, user, recipients).call
      end

      attr_reader :work_id, :title, :comment, :user, :recipients

      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 : ''
        @recipients = recipients
        @user = user
      end

      def call
        user.send_message(users_to_notify.uniq, message, subject)
      end

      protected

        def subject
          raise NotImplementedError, "Implement #subject in a child class"
        end

        def message
          "#{title} (#{work_id}) was advanced in the workflow by #{user.user_key} and is awaiting approval #{comment}"
        end

      private

        def users_to_notify
          recipients.fetch('to', []) + recipients.fetch('cc', [])
        end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sufia-7.3.0.rc3 app/services/sufia/workflow/abstract_notification.rb
sufia-7.3.0.rc2 app/services/sufia/workflow/abstract_notification.rb
sufia-7.3.0.rc1 app/services/sufia/workflow/abstract_notification.rb