Sha256: a6fd8a109453c5118fdfcd9b9792243860b60e31edd308f42499d2386d37cae8

Contents?: true

Size: 1.43 KB

Versions: 58

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module Decidim
  module Initiatives
    # Exposes the initiative vote resource so users can vote initiatives.
    class InitiativeVotesController < Decidim::Initiatives::ApplicationController
      include Decidim::Initiatives::NeedsInitiative
      include Decidim::FormFactory

      before_action :authenticate_user!

      helper InitiativeHelper

      # POST /initiatives/:initiative_id/initiative_vote
      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

      # DELETE /initiatives/:initiative_id/initiative_vote
      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
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
decidim-initiatives-0.29.1 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.28.4 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.27.9 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.29.0 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.28.3 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.27.8 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.29.0.rc4 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.29.0.rc3 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.29.0.rc2 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.29.0.rc1 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.28.2 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.27.7 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.28.1 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.27.6 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.26.10 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.26.9 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.28.0 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.27.5 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.28.0.rc5 app/controllers/decidim/initiatives/initiative_votes_controller.rb
decidim-initiatives-0.28.0.rc4 app/controllers/decidim/initiatives/initiative_votes_controller.rb