Class: Decidim::Initiatives::InitiativeVotesController

Inherits:
ApplicationController show all
Includes:
FormFactory, NeedsInitiative
Defined in:
decidim-initiatives/app/controllers/decidim/initiatives/initiative_votes_controller.rb

Overview

Exposes the initiative vote resource so users can vote initiatives.

Instance Method Summary collapse

Methods inherited from ApplicationController

#permission_class_chain, #permission_scope, #permissions_context

Methods included from RegistersPermissions

register_permissions

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 NeedsOrganization

enhance_controller, extended, included

Instance Method Details

#createObject

POST /initiatives/:initiative_id/initiative_vote



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

def create
  enforce_permission_to :vote, :initiative, initiative: current_initiative

  @form = form(Decidim::Initiatives::VoteForm).from_params(
    initiative: current_initiative,
    signer: current_user
  )

  VoteInitiative.call(@form) do
    on(:ok) do
      current_initiative.reload
      render :update_buttons_and_counters
    end

    on(:invalid) do
      render json: {
        error: I18n.t("initiative_votes.create.error", scope: "decidim.initiatives")
      }, status: :unprocessable_entity
    end
  end
end

#destroyObject

DELETE /initiatives/:initiative_id/initiative_vote



38
39
40
41
42
43
44
45
46
47
# File 'decidim-initiatives/app/controllers/decidim/initiatives/initiative_votes_controller.rb', line 38

def destroy
  enforce_permission_to :unvote, :initiative, initiative: current_initiative

  UnvoteInitiative.call(current_initiative, current_user) do
    on(:ok) do
      current_initiative.reload
      render :update_buttons_and_counters
    end
  end
end