Class: Decidim::Budgets::LineItemsController

Inherits:
ApplicationController show all
Includes:
NeedsCurrentOrder
Defined in:
decidim-budgets/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?

Methods inherited from Components::BaseController

#current_component, #current_manifest, #current_participatory_space, #permission_class_chain, #permission_scope, #redirect_unless_feature_private, #set_component_breadcrumb_item

Methods included from RegistersPermissions

register_permissions

Methods inherited from ApplicationController

#store_share_token

Methods included from UserBlockedChecker

#check_user_block_status, #check_user_not_blocked

Methods included from NeedsSnippets

#snippets

Methods included from Headers::HttpCachingDisabler

#disable_http_caching

Methods included from HasStoredPath

#skip_store_location?, #store_current_location

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Methods included from NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject



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

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



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

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