Sha256: edab68ecf8c12c3ec91ba5a25167fbded53ffaecc9372759e92db1717410e2d6

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module Decidim
  module Lausanne
    module Budgets
      module Admin
        # This command is executed when the user updates a Budget
        # from the admin panel.
        class UpdateBudget < Decidim::Lausanne::Budgets::Command
          def initialize(form, budget)
            @form = form
            @budget = budget
          end

          # Updates the budget if valid.
          #
          # Broadcasts :ok if successful, :invalid otherwise.
          def call
            return broadcast(:invalid) if form.invalid?

            update_budget!

            broadcast(:ok, budget)
          end

          private

            attr_reader :form, :budget

            def update_budget!
              attributes = {
                scope: form.scope,
                title: form.title,
                weight: form.weight,
                description: form.description,
                total_budget: form.total_budget
              }

              Decidim.traceability.update!(
                budget,
                form.current_user,
                attributes,
                visibility: "all"
              )
            end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
decidim-lausanne-budgets-0.1.0 app/commands/decidim/lausanne/budgets/admin/update_budget.rb