Sha256: fe0174a562c126c25e30d7d7af48078f6b5d7604772de09fd1027f7ad043341c

Contents?: true

Size: 1.83 KB

Versions: 10

Compression:

Stored size: 1.83 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    # Exposes the proposal endorsement resource so that users can endorse proposals.
    class ProposalEndorsementsController < Decidim::Proposals::ApplicationController
      helper_method :proposal

      before_action :authenticate_user!

      def create
        enforce_permission_to :endorse, :proposal, proposal: proposal
        @from_proposals_list = params[:from_proposals_list] == "true"
        user_group_id = params[:user_group_id]

        EndorseProposal.call(proposal, current_user, user_group_id) do
          on(:ok) do
            proposal.reload
            render :update_buttons_and_counters
          end

          on(:invalid) do
            render json: { error: I18n.t("proposal_endorsements.create.error", scope: "decidim.proposals") }, status: 422
          end
        end
      end

      def destroy
        enforce_permission_to :unendorse, :proposal, proposal: proposal
        @from_proposals_list = params[:from_proposals_list] == "true"
        user_group_id = params[:user_group_id]
        user_group = user_groups.find(user_group_id) if user_group_id

        UnendorseProposal.call(proposal, current_user, user_group) do
          on(:ok) do
            proposal.reload
            render :update_buttons_and_counters
          end
        end
      end

      def identities
        enforce_permission_to :endorse, :proposal, proposal: proposal

        @user_verified_groups = Decidim::UserGroups::ManageableUserGroups.for(current_user).verified
        render :identities, layout: false
      end

      private

      def user_groups
        Decidim::UserGroups::ManageableUserGroups.for(current_user).verified
      end

      def proposal
        @proposal ||= Proposal.where(component: current_component).find(params[:proposal_id])
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
decidim-proposals-0.18.1 app/controllers/decidim/proposals/proposal_endorsements_controller.rb
decidim-proposals-0.17.2 app/controllers/decidim/proposals/proposal_endorsements_controller.rb
decidim-proposals-0.18.0 app/controllers/decidim/proposals/proposal_endorsements_controller.rb
decidim-proposals-0.17.1 app/controllers/decidim/proposals/proposal_endorsements_controller.rb
decidim-proposals-0.16.1 app/controllers/decidim/proposals/proposal_endorsements_controller.rb
decidim-proposals-0.17.0 app/controllers/decidim/proposals/proposal_endorsements_controller.rb
decidim-proposals-0.16.0 app/controllers/decidim/proposals/proposal_endorsements_controller.rb
decidim-proposals-0.15.2 app/controllers/decidim/proposals/proposal_endorsements_controller.rb
decidim-proposals-0.15.1 app/controllers/decidim/proposals/proposal_endorsements_controller.rb
decidim-proposals-0.15.0 app/controllers/decidim/proposals/proposal_endorsements_controller.rb