Sha256: 88f8df225711c766d6721c9223569dac9dc8ec478577778a08cbc8e2d28bedbd
Contents?: true
Size: 1.68 KB
Versions: 13
Compression:
Stored size: 1.68 KB
Contents
# frozen_string_literal: true module Decidim module Surveys 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 survey_opened?(previous_settings, current_settings) event = "decidim.events.surveys.survey_opened" event_class = Decidim::Surveys::OpenedSurveyEvent elsif survey_closed?(previous_settings, current_settings) event = "decidim.events.surveys.survey_closed" event_class = Decidim::Surveys::ClosedSurveyEvent end return unless event && event_class Decidim::EventsManager.publish( event:, event_class:, resource: component, followers: component.participatory_space.followers ) end private def unchanged?(previous_settings, current_settings) current_settings[:allow_answers] == previous_settings[:allow_answers] end # rubocop:disable Style/DoubleNegation def survey_opened?(previous_settings, current_settings) current_settings[:allow_answers] == true && !!previous_settings[:allow_answers] == false end def survey_closed?(previous_settings, current_settings) !!current_settings[:allow_answers] == false && previous_settings[:allow_answers] == true end def clean_after_publish_changed?(previous_settings, current_settings) current_settings[:clean_after_publish] != previous_settings[:clean_after_publish] end # rubocop:enable Style/DoubleNegation end end end
Version data entries
13 entries across 13 versions & 1 rubygems