<commit_before>class EventRulesController < ApplicationController
  before_action :set_event_rule, only: [:show, :edit, :update, :destroy]
  before_action :add_breadcrumb_show, only: [:show]

  # GET /event_rules
  def index
    @event_rules = EventRule.all
    respond_with(@event_rules)
  end

  # GET /event_rules/1
  def show
    respond_with(@event_rule)
  end

  # GET /event_rules/new
  def new
    @event_rule = EventRule.new
    respond_with(@event_rule)
  end

  # GET /event_rules/1/edit
  def edit
  end

  # POST /event_rules
  def create
    @event_rule = EventRule.new(event_rule_params.merge(filter: filter_params))

    @event_rule.save
    respond_with(@event_rule)
  end

  # PATCH/PUT /event_rules/1
  def update
    update_params = if filter_params.present? 
                      event_rule_params.merge(filter: filter_params)
                    else
                      event_rule_params
                    end
    @event_rule.update(update_params)
    respond_with(@event_rule)
  end

  # DELETE /event_rules/1
  def destroy
    @event_rule.destroy
    respond_with(@event_rule)
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_event_rule
      @event_rule = EventRule.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def event_rule_params
      params.require(:event_rule).permit(:position, :action, :severity, :valid_until)
    end

    def filter_params
      params.require(:event_rule).fetch(:filter, {}).reject{|_, v| v.blank?}
    end
end<commit_msg>safety first: check for allowed attributes<commit_after>class EventRulesController < ApplicationController
  before_action :set_event_rule, only: [:show, :edit, :update, :destroy]
  before_action :add_breadcrumb_show, only: [:show]

  # GET /event_rules
  def index
    @event_rules = EventRule.all
    respond_with(@event_rules)
  end

  # GET /event_rules/1
  def show
    respond_with(@event_rule)
  end

  # GET /event_rules/new
  def new
    @event_rule = EventRule.new
    respond_with(@event_rule)
  end

  # GET /event_rules/1/edit
  def edit
  end

  # POST /event_rules
  def create
    @event_rule = EventRule.new(event_rule_params.merge(filter: filter_params))

    @event_rule.save
    respond_with(@event_rule)
  end

  # PATCH/PUT /event_rules/1
  def update
    update_params = if filter_params.present? 
                      event_rule_params.merge(filter: filter_params)
                    else
                      event_rule_params
                    end
    @event_rule.update(update_params)
    respond_with(@event_rule)
  end

  # DELETE /event_rules/1
  def destroy
    @event_rule.destroy
    respond_with(@event_rule)
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_event_rule
      @event_rule = EventRule.find(params[:id])
    end

    # Only allow a trusted parameter "white list" through.
    def event_rule_params
      params.require(:event_rule).permit(:position, :action, :severity, :valid_until)
    end

    def filter_params
      params.require(:event_rule).permit(filter: EventRule::FILTER_ATTRIBUTES).
        fetch(:filter, {}).reject{|_, v| v.blank?}
    end
end
{'fraction_non_alphanumeric': 0.08726487819919827, 'fraction_numerical': 0.002466851680542707, 'mean_word_length': 2.932121212121212, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3941315', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1015, 'n_words': 230}