Sha256: 007d3d94e56d47f962793c42975c48d7d44a3f07dc80fb1bb11be1f753446286
Contents?: true
Size: 1.53 KB
Versions: 7
Compression:
Stored size: 1.53 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, event_class: 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 # rubocop:enable Style/DoubleNegation end end end
Version data entries
7 entries across 7 versions & 1 rubygems