Sha256: 64b384961ef8d64732a44d582d6f7ed7e088eb9f45756e5ece99f831cc17437b

Contents?: true

Size: 941 Bytes

Versions: 33

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 < Rectify::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

33 entries across 33 versions & 1 rubygems

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