Sha256: 5ee1b0a0e8eade7696050c7695e91169998cf587003e4014b9e44f96b40a4f90

Contents?: true

Size: 1.07 KB

Versions: 19

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    module Admin
      # This command is executed when the user creates an Budget
      # from the admin panel.
      class CreateBudget < Decidim::Command
        def initialize(form)
          @form = form
        end

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

          create_budget!

          broadcast(:ok, budget)
        end

        private

        attr_reader :form, :budget

        def create_budget!
          attributes = {
            component: form.current_component,
            scope: form.scope,
            title: form.title,
            weight: form.weight,
            description: form.description,
            total_budget: form.total_budget
          }

          @budget = Decidim.traceability.create!(
            Budget,
            form.current_user,
            attributes,
            visibility: "all"
          )
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-budgets-0.28.4 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.9 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.28.3 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.8 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.28.2 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.7 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.28.1 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.6 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.28.0 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.5 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.28.0.rc5 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.28.0.rc4 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.4 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.3 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.2 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.1 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.0 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.0.rc2 app/commands/decidim/budgets/admin/create_budget.rb
decidim-budgets-0.27.0.rc1 app/commands/decidim/budgets/admin/create_budget.rb