Sha256: ea5300fbb556e62e2dae474c1f0253505359f747d9ecb1ce17227fa0fb04a8b0

Contents?: true

Size: 941 Bytes

Versions: 19

Compression:

Stored size: 941 Bytes

Contents

# frozen_string_literal: true

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

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

          destroy_budget!

          broadcast(:ok, budget)
        end

        private

        attr_reader :budget, :current_user

        def destroy_budget!
          Decidim.traceability.perform_action!(
            :delete,
            budget,
            current_user,
            visibility: "all"
          ) do
            budget.destroy!
          end
        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/destroy_budget.rb
decidim-budgets-0.27.9 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.28.3 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.8 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.28.2 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.7 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.28.1 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.6 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.28.0 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.5 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.28.0.rc5 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.28.0.rc4 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.4 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.3 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.2 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.1 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.0 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.0.rc2 app/commands/decidim/budgets/admin/destroy_budget.rb
decidim-budgets-0.27.0.rc1 app/commands/decidim/budgets/admin/destroy_budget.rb