<commit_before>class MiqPolicyController < ApplicationController
  include_concern 'MiqActions'
  include_concern 'AlertProfiles'
  include_concern 'Alerts'
  include_concern 'Conditions'
  include_concern 'Events'
  include_concern 'Policies'
  include_concern 'PolicyProfiles'
  include_concern 'Rsop'

  before_filter :check_privileges
  before_filter :get_session_data
  after_filter :cleanup_action
  after_filter :set_session_data

  def index
    redirect_to :action => 'explorer'
  end

  def export
    @breadcrumbs = Array.new
    @layout = "miq_policy_export"
    drop_breadcrumb( {:name=>"Import / Export", :url=>"miq_policy/export"} )
    case params[:button]
    when "cancel"
      @sb = nil
      if @lastaction != "fetch_yaml"
        add_flash(_("%s cancelled by user") % "Export")
      end
      render :update do |page|                    # Use JS to update the display
        page.redirect_to :action=>"explorer"
      end
    when "export"
      if params[:choices_chosen]
        @sb[:new][:choices_chosen] = params[:choices_chosen]
      else
        @sb[:new][:choices_chosen] = Array.new
      end
      if @sb[:new][:choices_chosen].length == 0 # At least one member is required
        add_flash(_("At least %{num} %{model} must be selected for %{action}") % {:num=>1, :model=>"item", :action=>"export"}, :error)
        render :update do |page|                    # Use JS to update the display
          page.replace_html("profile_export_div", :partial=>"export")
          page << "miqSparkle(false);"
        end
      else
        begin
          case @sb[:dbtype]
            when "pp"
              db = MiqPolicySet
              filename = "Profiles"
            when "p"
              db = MiqPolicy
              filename = "Policies"
            when "al"
              db = MiqAlert
              filename = "Alerts"
          end
          session[:export_data] = MiqPolicy.export_to_yaml(@sb[:new][:choices_chosen], db)
          render :update do |page|          # Use RJS to update the display
            page.redirect_to :action=>'fetch_yaml', :fname=>filename, :escape=>false
          end
        rescue StandardError => bang
          add_flash(_("Error during '%s': ") % "export" << bang.message, :error)
          render :update do |page|                    # Use JS to update the display
            page.replace_html("profile_export_div", :partial=>"export")
            page << "miqSparkle(false);"
          end
        end
      end
    when "reset", nil # Reset or first time in
      dbtype = params[:dbtype] == nil ? "pp" : params[:dbtype]
      type = params[:typ] == nil ? "export" : params[:typ]

      export_chooser(dbtype,type)
    end
  end

  # handle buttons pressed on the button bar
  def button
    @edit = session[:edit]                                  # Restore @edit for adv search box
    @refresh_div = "main_div" # Default div for button.rjs to refresh
    if params[:pressed] == "refresh_log"
      refresh_log
      return
    end
    if params[:pressed] == "collect_logs"
      collect_logs
      return
    end

    if ! @refresh_partial # if no button handler ran, show not implemented msg
      add_flash(I18n.t("flash.button.not_implemented)"), :error)
      @refresh_partial = "layouts/flash_msg"
      @refresh_div = "flash_msg_div"
    end
  end

  POLICY_X_BUTTON_ALLOWED_ACTIONS = {<commit_msg>Forgotten flash message<commit_after>class MiqPolicyController < ApplicationController
  include_concern 'MiqActions'
  include_concern 'AlertProfiles'
  include_concern 'Alerts'
  include_concern 'Conditions'
  include_concern 'Events'
  include_concern 'Policies'
  include_concern 'PolicyProfiles'
  include_concern 'Rsop'

  before_filter :check_privileges
  before_filter :get_session_data
  after_filter :cleanup_action
  after_filter :set_session_data

  def index
    redirect_to :action => 'explorer'
  end

  def export
    @breadcrumbs = Array.new
    @layout = "miq_policy_export"
    drop_breadcrumb( {:name=>"Import / Export", :url=>"miq_policy/export"} )
    case params[:button]
    when "cancel"
      @sb = nil
      if @lastaction != "fetch_yaml"
        add_flash(_("%s cancelled by user") % "Export")
      end
      render :update do |page|                    # Use JS to update the display
        page.redirect_to :action=>"explorer"
      end
    when "export"
      if params[:choices_chosen]
        @sb[:new][:choices_chosen] = params[:choices_chosen]
      else
        @sb[:new][:choices_chosen] = Array.new
      end
      if @sb[:new][:choices_chosen].length == 0 # At least one member is required
        add_flash(_("At least %{num} %{model} must be selected for %{action}") % {:num=>1, :model=>"item", :action=>"export"}, :error)
        render :update do |page|                    # Use JS to update the display
          page.replace_html("profile_export_div", :partial=>"export")
          page << "miqSparkle(false);"
        end
      else
        begin
          case @sb[:dbtype]
            when "pp"
              db = MiqPolicySet
              filename = "Profiles"
            when "p"
              db = MiqPolicy
              filename = "Policies"
            when "al"
              db = MiqAlert
              filename = "Alerts"
          end
          session[:export_data] = MiqPolicy.export_to_yaml(@sb[:new][:choices_chosen], db)
          render :update do |page|          # Use RJS to update the display
            page.redirect_to :action=>'fetch_yaml', :fname=>filename, :escape=>false
          end
        rescue StandardError => bang
          add_flash(_("Error during '%s': ") % "export" << bang.message, :error)
          render :update do |page|                    # Use JS to update the display
            page.replace_html("profile_export_div", :partial=>"export")
            page << "miqSparkle(false);"
          end
        end
      end
    when "reset", nil # Reset or first time in
      dbtype = params[:dbtype] == nil ? "pp" : params[:dbtype]
      type = params[:typ] == nil ? "export" : params[:typ]

      export_chooser(dbtype,type)
    end
  end

  # handle buttons pressed on the button bar
  def button
    @edit = session[:edit]                                  # Restore @edit for adv search box
    @refresh_div = "main_div" # Default div for button.rjs to refresh
    if params[:pressed] == "refresh_log"
      refresh_log
      return
    end
    if params[:pressed] == "collect_logs"
      collect_logs
      return
    end

    if ! @refresh_partial # if no button handler ran, show not implemented msg
      add_flash(_("Button not yet implemented"), :error)
      @refresh_partial = "layouts/flash_msg"
      @refresh_div = "flash_msg_div"
    end
  end

  POLICY_X_BUTTON_ALLOWED_ACTIONS = {
{'fraction_non_alphanumeric': 0.10655253837072019, 'fraction_numerical': 0.0008854781582054309, 'mean_word_length': 2.359940505701537, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7050370', 'n_tokens_mistral': 2059, 'n_tokens_neox': 2023, 'n_words': 531}