Sha256: c5b0481be3eb9f97e32bb9ea70d265cbc2021c8efe393463c5a5d1c81cc17634
Contents?: true
Size: 1.58 KB
Versions: 7
Compression:
Stored size: 1.58 KB
Contents
# frozen_string_literal: true module Decidim module Elections module Admin # This controller allows to import proposals as answers. class ProposalsImportsController < Admin::ApplicationController helper_method :election, :question, :answers, :answers def new enforce_permission_to(:import_proposals, :answer, election:, question:) @form = form(Admin::AnswerImportProposalsForm).instance end def create enforce_permission_to(:import_proposals, :answer, election:, question:) @form = form(Admin::AnswerImportProposalsForm).from_params(params, election:, question:) Admin::ImportProposalsToElections.call(@form) do on(:ok) do |answers| flash[:notice] = I18n.t("proposals_imports.create.success", scope: "decidim.elections.admin", number: answers.length) redirect_to election_question_answers_path(election, question) end on(:invalid) do flash[:alert] = I18n.t("proposals_imports.create.invalid", scope: "decidim.elections.admin") render action: "new" end end end private def election @election ||= Election.where(component: current_component).find_by(id: params[:election_id]) end def question @question ||= election.questions.find_by(id: params[:question_id]) end def answers @answers ||= question.answers end def answer answers.find(params[:id]) end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems