app/controllers/decidim/elections/admin/answers_controller.rb in decidim-elections-0.23.6 vs app/controllers/decidim/elections/admin/answers_controller.rb in decidim-elections-0.24.0.rc1

- old
+ new

@@ -55,9 +55,41 @@ render action: "edit" end end end + def select + change_selected(true) + end + + def unselect + change_selected(false) + end + + def change_selected(selected) + enforce_permission_to :select, :answer, election: election, question: question + + UpdateAnswerSelection.call(answer, selected) do + on(:ok) do + flash[:notice] = if selected + I18n.t("answers.select.success", scope: "decidim.elections.admin") + else + I18n.t("answers.unselect.success", scope: "decidim.elections.admin") + end + end + + on(:invalid) do + flash.now[:alert] = if selected + I18n.t("answers.select.invalid", scope: "decidim.elections.admin") + else + I18n.t("answers.unselect.invalid", scope: "decidim.elections.admin") + end + end + end + + redirect_to election_question_answers_path(election, question) + end + def destroy enforce_permission_to :update, :answer, election: election, question: question DestroyAnswer.call(answer, current_user) do on(:ok) do