Sha256: 380b494f30e561865b6b2a43edae8500083e279b749b674460756327db604f95

Contents?: true

Size: 1.81 KB

Versions: 21

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

21 entries across 21 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.23.6 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.23.5 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.23.4 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.23.3 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.23.2 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.23.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.23.1.rc1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.23.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.22.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.21.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.20.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.20.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.19.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.18.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.19.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.17.2 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.18.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.17.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.16.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.17.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb