Files
nairobi/app/controllers/admin/poll/questions_controller.rb
Javi Martín 2239b8fdca Remove obsolete questions index in the admin area
We removed the link to this page in commit 83e8d6035 because poll
questions don't really make sense without a poll.

However, this page also contained information about successful
proposals, which might be interesting so administrators don't have to
navigate to the public area in order to find and create questions based
on successful proposals.

So we're keeping the part about successful proposals and linking it from
the proposals part of the admin area.

Note we're using translation keys like `successful_proposals_tab`, which
don't make sense anymore, for the successful proposals. We're doing so
because we've already got translations for these keys and, if we renamed
them, we'd lose the existing translations and our translators would have
to add them again.

Also note we're changing one poll question test a little bit so we
create the question from a successful proposal using the new page. There
are other tests checking how to create a question from the
admin/proposals#show action and other tests checking what happens when
accessing a successful proposal in the admin section, so we don't lose
any test coverage by changing an existing test instead of adding a new
one.

Finally, note that we've removing the `search` method in poll question
because we no longer use it. This currently makes the
`author_visible_name` database column useless; we aren't removing it
right now because we don't want to risk a possible data loss in a patch
release (we're about to release version 2.3.1), but we might remove it
in the future.
2025-03-26 16:42:04 +01:00

58 lines
1.3 KiB
Ruby

class Admin::Poll::QuestionsController < Admin::Poll::BaseController
include CommentableActions
include Translatable
load_and_authorize_resource :poll
load_resource class: "Poll::Question"
authorize_resource except: :new
def new
proposal = Proposal.find(params[:proposal_id]) if params[:proposal_id].present?
@question.copy_attributes_from_proposal(proposal)
@question.poll = @poll
@question.votation_type = VotationType.new
authorize! :create, @question
end
def create
@question.author = @question.proposal&.author || current_user
if @question.save
redirect_to admin_question_path(@question)
else
render :new
end
end
def show
end
def edit
end
def update
if @question.update(question_params)
redirect_to admin_question_path(@question), notice: t("flash.actions.save_changes.notice")
else
render :edit
end
end
def destroy
@question.destroy!
redirect_to admin_poll_path(@question.poll), notice: t("admin.questions.destroy.notice")
end
private
def question_params
params.require(:poll_question).permit(allowed_params)
end
def allowed_params
attributes = [:poll_id, :question, :proposal_id, votation_type_attributes: [:vote_type, :max_votes]]
[*attributes, translation_params(Poll::Question)]
end
end