Class: Decidim::Proposals::SettingsChangeJob

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

Instance Method Summary collapse

Instance Method Details

#perform(feature_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
28
# File 'app/jobs/decidim/proposals/settings_change_job.rb', line 6

def perform(feature_id, previous_settings, current_settings)
  feature = Decidim::Feature.find(feature_id)

  if creation_enabled?(previous_settings, current_settings)
    event = "decidim.events.proposals.creation_enabled"
    event_class = Decidim::Proposals::CreationEnabledEvent
  elsif voting_enabled?(previous_settings, current_settings)
    event = "decidim.events.proposals.voting_enabled"
    event_class = Decidim::Proposals::VotingEnabledEvent
  elsif endorsing_enabled?(previous_settings, current_settings)
    event = "decidim.events.proposals.endorsing_enabled"
    event_class = Decidim::Proposals::EndorsingEnabledEvent
  end

  return unless event && event_class

  Decidim::EventsManager.publish(
    event: event,
    event_class: event_class,
    resource: feature,
    recipient_ids: feature.participatory_space.followers.pluck(:id)
  )
end