Sha256: b4f49160d3f6722bdfa90d1e25065748b179929555907ca9f2f9ead5b1b33939

Contents?: true

Size: 1.27 KB

Versions: 12

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    module Admin
      # A command with all the business logic when updating initiatives
      # settings in admin area.
      class UpdateInitiativesSettings < Decidim::Command
        # Public: Initializes the command.
        #
        # initiatives_settings - A initiatives settings object to update.
        # form - A form object with the params.
        def initialize(initiatives_settings, form)
          @initiatives_settings = initiatives_settings
          @form = form
        end

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

          update_initiatives_settings!

          broadcast(:ok)
        end

        private

        attr_reader :form, :initiatives_settings

        def update_initiatives_settings!
          Decidim.traceability.update!(
            @initiatives_settings,
            form.current_user,
            initiatives_order: form.initiatives_order
          )
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-initiatives-0.27.9 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.8 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.7 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.6 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.5 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.4 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.3 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.2 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.1 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.0 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.0.rc2 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb
decidim-initiatives-0.27.0.rc1 app/commands/decidim/initiatives/admin/update_initiatives_settings.rb