Sha256: 1071a030a07917e09b122ae6bb7f2608abb25e6787d55ca51329d66c7d4ab742

Contents?: true

Size: 1.48 KB

Versions: 17

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

module Decidim
  module Debates
    class SettingsChangeJob < ApplicationJob
      def perform(component_id, previous_settings, current_settings)
        return if unchanged?(previous_settings, current_settings)

        component = Decidim::Component.find(component_id)

        if debate_creation_enabled?(previous_settings, current_settings)
          event = "decidim.events.debates.creation_enabled"
          event_class = Decidim::Debates::CreationEnabledEvent
        elsif debate_creation_disabled?(previous_settings, current_settings)
          event = "decidim.events.debates.creation_disabled"
          event_class = Decidim::Debates::CreationDisabledEvent
        end

        Decidim::EventsManager.publish(
          event: event,
          event_class: event_class,
          resource: component,
          recipient_ids: component.participatory_space.followers.pluck(:id)
        )
      end

      private

      def unchanged?(previous_settings, current_settings)
        current_settings[:creation_enabled] == previous_settings[:creation_enabled]
      end

      def debate_creation_enabled?(previous_settings, current_settings)
        current_settings[:creation_enabled] == true &&
          previous_settings[:creation_enabled] == false
      end

      def debate_creation_disabled?(previous_settings, current_settings)
        current_settings[:creation_enabled] == false &&
          previous_settings[:creation_enabled] == true
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
decidim-debates-0.15.2 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.15.1 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.15.0 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.14.4 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.14.3 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.14.2 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.14.1 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.13.1 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.12.2 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.13.0 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.12.1 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.13.0.pre1 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.12.0 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.11.2 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.12.0.pre app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.11.1 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.11.0.pre1 app/jobs/decidim/debates/settings_change_job.rb