Class: Decidim::Budgets::LineItemsController

Inherits:
ApplicationController show all
Includes:
NeedsCurrentOrder
Defined in:
app/controllers/decidim/budgets/line_items_controller.rb

Overview

Exposes the line items resource so users can create and remove from orders.

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_workflow, #voting_finished?, #voting_open?

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/decidim/budgets/line_items_controller.rb', line 11

def create
  enforce_permission_to :vote, :project, project:, budget:, workflow: current_workflow

  respond_to do |format|
    # Note that the user-specific lock here is important in order to
    # prevent multiple simultaneous processes on different machines from
    # creating multiple orders for the same user in case the button is
    # pressed multiple times.
    current_user.with_lock do
      AddLineItem.call(persisted_current_order, project, current_user) do
        on(:ok) do |order|
          self.current_order = order
          format.html { redirect_back(fallback_location: budget_path(budget)) }
          format.js { render "update_budget" }
        end

        on(:invalid) do
          format.js { render "update_budget", status: :unprocessable_entity }
        end
      end
    end
  end
end

#destroyObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/decidim/budgets/line_items_controller.rb', line 35

def destroy
  respond_to do |format|
    RemoveLineItem.call(current_order, project) do
      on(:ok) do |_order|
        format.html { redirect_back(fallback_location: budget_path(budget)) }
        format.js { render "update_budget" }
      end

      on(:invalid) do
        format.js { render "update_budget", status: :unprocessable_entity }
      end
    end
  end
end