Class: Decidim::Debates::SettingsChangeJob

Inherits:
ApplicationJob
  • Object
show all
Defined in:
app/jobs/decidim/debates/settings_change_job.rb

Instance Method Summary collapse

Instance Method Details

#perform(component_id, previous_settings, current_settings) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/jobs/decidim/debates/settings_change_job.rb', line 6

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_class:,
    resource: component,
    followers: component.participatory_space.followers
  )
end