Sha256: 007ae0b540f19257095a9cdc4062cc6a0b6def05158d0f20435059fdacafa224

Contents?: true

Size: 1.75 KB

Versions: 16

Compression:

Stored size: 1.75 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
          {
            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,
            recipient_ids: step.participatory_process.followers.pluck(:id)
          )
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
decidim-participatory_processes-0.14.4 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.14.3 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.14.2 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.14.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.13.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.12.2 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.13.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.12.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.13.0.pre1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.12.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.11.2 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.12.0.pre app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.11.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.11.0.pre1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.10.1 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb
decidim-participatory_processes-0.10.0 app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb