Sha256: 7b09ac57113cf65a07697860623f534807c1ab76e23f2eb1defc044883165767

Contents?: true

Size: 1.61 KB

Versions: 15

Compression:

Stored size: 1.61 KB

Contents

# frozen_string_literal: true

module Decidim
  class EventPublisherJob < ApplicationJob
    queue_as :events

    attr_reader :resource

    def perform(event_name, data)
      @resource = data[:resource]

      return unless data[:force_send] || notifiable?

      EmailNotificationGeneratorJob.perform_later(
        event_name,
        data[:event_class],
        data[:resource],
        data[:followers],
        data[:affected_users],
        data[:extra]
      )

      NotificationGeneratorJob.perform_later(
        event_name,
        data[:event_class],
        data[:resource],
        data[:followers],
        data[:affected_users],
        data[:extra]
      )
    end

    private

    # Whether this event should be notified or not. Useful when you want the
    # event to decide based on the params.
    #
    # It returns false when the resource or any element in the chain is a
    # `Decidim::Publicable` and it is not published or participatory_space
    # is a `Decidim::Participable` and the user cannot participate.
    def notifiable?
      return false if resource.is_a?(Decidim::Publicable) && !resource.published?
      return false if participatory_space.is_a?(Decidim::Publicable) && !participatory_space&.published?
      return false if component && !component.published?

      true
    end

    def component
      return resource.component if resource.is_a?(Decidim::HasComponent)
      return resource if resource.is_a?(Decidim::Component)
    end

    def participatory_space
      return resource if resource.is_a?(Decidim::ParticipatorySpaceResourceable)

      component&.participatory_space
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
decidim-core-0.29.2 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.28.5 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.29.1 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.28.4 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.29.0 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.28.3 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.29.0.rc4 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.29.0.rc3 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.29.0.rc2 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.29.0.rc1 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.28.2 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.28.1 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.28.0 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.28.0.rc5 app/jobs/decidim/event_publisher_job.rb
decidim-core-0.28.0.rc4 app/jobs/decidim/event_publisher_job.rb