Sha256: f60948cb0b410e6a9d9dde3956de3e74ca62d15d7634e5ed26d06dd007c86494
Contents?: true
Size: 1.53 KB
Versions: 6
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
6 entries across 6 versions & 1 rubygems