Sha256: e0982d6288e004feea566d1d37e0ebcffb4bfeb57ade1605847ac8c72a8107a7

Contents?: true

Size: 1.37 KB

Versions: 28

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    # Exposes the order resource so users can checkout it.
    class OrdersController < Decidim::Budgets::ApplicationController
      include NeedsCurrentOrder

      def checkout
        enforce_permission_to :vote, :project, order: current_order, budget: budget, workflow: current_workflow

        Checkout.call(current_order) do
          on(:ok) do
            flash[:notice] = I18n.t("orders.checkout.success", scope: "decidim")
            redirect_to budgets_path
          end

          on(:invalid) do
            flash.now[:alert] = I18n.t("orders.checkout.error", scope: "decidim")
            redirect_to budgets_path
          end
        end
      end

      def destroy
        CancelOrder.call(current_order) do
          on(:ok) do
            flash[:notice] = I18n.t("orders.destroy.success", scope: "decidim")
            redirect_to redirect_path
          end

          on(:invalid) do
            flash.now[:alert] = I18n.t("orders.destroy.error", scope: "decidim")
            redirect_to redirect_path
          end
        end
      end

      private

      def budget
        @budget ||= Budget.find_by(id: params[:budget_id])
      end

      def redirect_path
        if params[:return_to] == "budget"
          budget_path(budget)
        else
          budgets_path
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
decidim-budgets-0.27.3 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.26.7 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.26.5 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.27.2 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.27.1 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.26.4 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.27.0 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.26.3 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.27.0.rc2 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.27.0.rc1 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.26.2 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.26.1 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.26.0 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.26.0.rc2 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.26.0.rc1 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.25.2 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.25.1 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.25.0 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.25.0.rc4 app/controllers/decidim/budgets/orders_controller.rb
decidim-budgets-0.25.0.rc3 app/controllers/decidim/budgets/orders_controller.rb