Sha256: 5c91f50dca5f62c641de135f37a35d107f424024d37885c361ff746cd328a99c

Contents?: true

Size: 1.81 KB

Versions: 25

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module Decidim
  module ParticipatoryProcesses
    module Admin
      # A command with all the business logic when creating a new participatory
      # process in the system.
      class UpdateParticipatoryProcessStep < Rectify::Command
        attr_reader :step

        # Public: Initializes the command.
        #
        # step - the ParticipatoryProcessStep to update
        # form - A form object with the params.
        def initialize(step, form)
          @step = step
          @form = form
        end

        # Executes the command. Broadcasts these events:
        #
        # - :ok when everything is valid.
        # - :invalid if the form wasn't valid and we couldn't proceed.
        #
        # Returns nothing.
        def call
          return broadcast(:invalid) if form.invalid?

          update_step
          notify_followers
          broadcast(:ok)
        end

        private

        attr_reader :form

        def update_step
          Decidim.traceability.update!(
            step,
            form.current_user,
            attributes
          )
        end

        def attributes
          {
            cta_path: form.cta_path,
            cta_text: form.cta_text,
            title: form.title,
            start_date: form.start_date,
            end_date: form.end_date,
            description: form.description
          }
        end

        def notify_followers
          return unless step.saved_change_to_start_date || step.saved_change_to_end_date

          Decidim::EventsManager.publish(
            event: "decidim.events.participatory_process.step_changed",
            event_class: Decidim::ParticipatoryProcessStepChangedEvent,
            resource: step,
            followers: step.participatory_process.followers
          )
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.26.10 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.9 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.8 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.7 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.5 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.4 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.3 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.2 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.0.rc2 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.26.0.rc1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.25.2 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.25.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.25.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.25.0.rc4 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.25.0.rc3 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.25.0.rc2 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.25.0.rc1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.24.3 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb