Sha256: a39aeaf12cf059ad14d8eadf802ef528c4c18420ffc8211e4b19ab9c28e9e360

Contents?: true

Size: 1.6 KB

Versions: 58

Compression:

Stored size: 1.6 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

        return unless event && event_class

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

      private

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

      # rubocop:disable Style/DoubleNegation
      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
      # rubocop:enable Style/DoubleNegation
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
decidim-debates-0.27.9 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.8 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.7 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.6 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.26.10 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.26.9 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.5 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.26.8 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.4 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.3 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.26.7 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.26.5 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.2 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.1 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.26.4 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.0 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.26.3 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.0.rc2 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.27.0.rc1 app/jobs/decidim/debates/settings_change_job.rb
decidim-debates-0.26.2 app/jobs/decidim/debates/settings_change_job.rb