<commit_before>class Cms::Apis::Preview::InplaceEdit::ColumnValuesController < ApplicationController
  include Cms::ApiFilter
  include Cms::InplaceEditFilter

  model Cms::Column::Value::Base

  layout "ss/ajax_in_iframe"

  before_action :set_inplace_mode
  before_action :set_item
  before_action :set_column, only: %i[new]
  before_action :set_column_and_value, only: %i[edit update destroy move_up move_down move_at]

  private

  def fix_params
    { cur_user: @cur_user, cur_site: @cur_site }
  end

  def set_inplace_mode
    @inplace_mode = true
  end

  def set_item
    @item = @cur_page = Cms::Page.site(@cur_site).find(params[:page_id]).becomes_with_route
    raise "404" if !@item.respond_to?(:form) || !@item.respond_to?(:column_values)

    @model = @item.class
  end

  def set_column
    @cur_column = @item.form.columns.find(params[:column_id].to_s)
  end

  def set_column_and_value
    @cur_column_value = @item.column_values.find(params[:id])

    @cur_column = @cur_column_value.column
    raise "404" if @cur_column.blank?
  end

  def new_column_value
    safe_params = params.require(:item).permit(@model.permit_params)
    column_value_param = safe_params[:column_values].first
    column_value_param[:order] = @item.column_values.present? ? @item.column_values.max(:order) + 1 : 0
    @cur_column_value = @item.column_values.build(column_value_param)
    @cur_column = @cur_column_value.column<commit_msg>[fix] lock error in preview edit (#2642)<commit_after>class Cms::Apis::Preview::InplaceEdit::ColumnValuesController < ApplicationController
  include Cms::ApiFilter
  include Cms::InplaceEditFilter

  model Cms::Column::Value::Base

  layout "ss/ajax_in_iframe"

  before_action :set_inplace_mode
  before_action :set_item
  before_action :set_column, only: %i[new]
  before_action :set_column_and_value, only: %i[edit update destroy move_up move_down move_at]

  private

  def fix_params
    { cur_user: @cur_user, cur_site: @cur_site }
  end

  def set_inplace_mode
    @inplace_mode = true
  end

  def set_item
    @item = @cur_page = Cms::Page.site(@cur_site).find(params[:page_id]).becomes_with_route
    @item.attributes = fix_params
    raise "404" if !@item.respond_to?(:form) || !@item.respond_to?(:column_values)

    @model = @item.class
  end

  def set_column
    @cur_column = @item.form.columns.find(params[:column_id].to_s)
  end

  def set_column_and_value
    @cur_column_value = @item.column_values.find(params[:id])

    @cur_column = @cur_column_value.column
    raise "404" if @cur_column.blank?
  end

  def new_column_value
    safe_params = params.require(:item).permit(@model.permit_params)
    column_value_param = safe_params[:column_values].first
    column_value_param[:order] = @item.column_values.present? ? @item.column_values.max(:order) + 1 : 0
    @cur_column_value = @item.column_values.build(column_value_param)
    @cur_column = @cur_column_value.column
{'fraction_non_alphanumeric': 0.11274342330030748, 'fraction_numerical': 0.006832934745473181, 'mean_word_length': 4.987730061349693, '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': '984081', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1015, 'n_words': 177}