Sha256: c2cc8867c476fb171e71aff3ef8ec36087b172d632d0de2a38f002d5c311f711

Contents?: true

Size: 1.04 KB

Versions: 33

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    module Admin
      # This command is executed when the user updates a Budget
      # from the admin panel.
      class UpdateBudget < Rectify::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

Version data entries

33 entries across 33 versions & 1 rubygems

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