<commit_before># frozen_string_literal: true

module OrgAdmin

  class QuestionOptionsController < ApplicationController

    include Versionable

    after_action :verify_authorized


    def destroy
      question_option = QuestionOption.find(params[:id])
      authorize question_option
#      begin
        question_option = get_modifiable(question_option)
        section = question_option.question.section
        if question_option.destroy!
          flash[:notice] = success_message(question_option, _("deleted"))
        else
          flash[:alert] = flash[:alert] = failure_message(question_option, _("delete"))
        end
#      rescue StandardError => e
#        flash[:alert] = _("Unable to create a new version of this template.")
#      end
#      redirect_to edit_org_admin_template_phase_section_path(
#        template_id: question.section.phase.template.id,
#        phase_id: question.section.phase.id,
#        id: question.section.id
#      )
      redirect_to edit_org_admin_template_phase_path(
        template_id: section.phase.template.id,
        id: section.phase.id,
        section: section.id
      )
    end

  end


end
<commit_msg>when question_option deleted remove any condition dependent on it<commit_after># frozen_string_literal: true

module OrgAdmin

  class QuestionOptionsController < ApplicationController

    include Versionable

    after_action :verify_authorized


    def destroy
      question_option = QuestionOption.find(params[:id])
      option_id_to_remove = question_option.id.to_s
      authorize question_option
      begin
        question_option = get_modifiable(question_option)
        question = question_option.question
        section = question.section
        if question_option.destroy!
          # need to remove any conditions which refer to this question option
          question.conditions.each do |cond|
            if cond.option_list.include?(option_id_to_remove)
              cond.destroy
            end
          end
          flash[:notice] = success_message(question_option, _("deleted"))
        else
          flash[:alert] = flash[:alert] = failure_message(question_option, _("delete"))
        end
      rescue StandardError => e
        flash[:alert] = _("Unable to create a new version of this template.")
      end
      redirect_to edit_org_admin_template_phase_path(
        template_id: section.phase.template.id,
        id: section.phase.id,
        section: section.id
      )
    end

  end


end

{'fraction_non_alphanumeric': 0.0736884261113336, 'fraction_numerical': 0.0, 'mean_word_length': 2.7620481927710845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3746512', 'n_tokens_mistral': 670, 'n_tokens_neox': 660, 'n_words': 157}