<commit_before>class Gws::Monitor::TopicsController < ApplicationController
  include Gws::BaseFilter
  include Gws::CrudFilter

  model Gws::Monitor::Topic

  before_action :set_item, only: [
    :show, :edit, :update, :delete, :destroy,
    :public, :preparation, :question_not_applicable, :answered
  ]

  before_action :set_selected_items, only: [
      :destroy_all, :public_all,
      :preparation_all, :question_not_applicable_all
  ]

  before_action :set_category

  private

  def set_crumbs
    set_category
    if @category.present?
      @crumbs << [t("modules.gws/monitor"), gws_monitor_topics_path]
      @crumbs << [@category.name, action: :index]
    else
      @crumbs << [t("modules.gws/monitor"), action: :index]
    end
  end

  def set_category
    @categories = Gws::Monitor::Category.site(@cur_site).readable(@cur_user, @cur_site).tree_sort
    if category_id = params[:category].presence
      @category ||= Gws::Monitor::Category.site(@cur_site).readable(@cur_user, @cur_site).where(id: category_id).first
    end
  end

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

  def pre_params
    current_category_id = super
    if @category.present?
      current_category_id[:category_ids] = [ @category.id ]
    end
    current_category_id
  end

  public

  def index
    @items = @model.site(@cur_site).topic

    @items = @items.and_public.and_readable(@cur_user, @cur_site)

    if @category.present?
      params[:s] ||= {}
      params[:s][:site] = @cur_site
      params[:s][:category] = @category.name
    end

    custom_group_ids = []
    Gws::CustomGroup.site(@cur_site).each do |i|
      custom_group_ids.push(i._id) if i.member_ids.include?(@cur_user.id)
    end

    @items = @items.search(params[:s]).
        custom_order(params.dig(:s, :sort) || 'updated_desc').
        and_topics(@cur_user.id, @cur_group.id, custom_group_ids).
        page(params[:page]).per(50)
  end

  def show
    raise "403" unless @item.readable?(@cur_user, @cur_site)
    render file: "/gws/monitor/main/show_#{@item.mode}"
  end

  def create
    @item = @model.new get_params

    if @item.admin_setting == "0"
      @item.attributes["user_ids"] = []
    elsif @item.admin_setting == "1"
      @item.attributes["group_ids"] = []
    end

    @item.attributes["readable_group_ids"] = (@item.attend_group_ids + @item.readable_group_ids).uniq

    raise "403" unless @item.allowed?(:edit, @cur_user, site: @cur_site)<commit_msg>[modify] variable name change i to cuctom_group<commit_after>class Gws::Monitor::TopicsController < ApplicationController
  include Gws::BaseFilter
  include Gws::CrudFilter

  model Gws::Monitor::Topic

  before_action :set_item, only: [
    :show, :edit, :update, :delete, :destroy,
    :public, :preparation, :question_not_applicable, :answered
  ]

  before_action :set_selected_items, only: [
      :destroy_all, :public_all,
      :preparation_all, :question_not_applicable_all
  ]

  before_action :set_category

  private

  def set_crumbs
    set_category
    if @category.present?
      @crumbs << [t("modules.gws/monitor"), gws_monitor_topics_path]
      @crumbs << [@category.name, action: :index]
    else
      @crumbs << [t("modules.gws/monitor"), action: :index]
    end
  end

  def set_category
    @categories = Gws::Monitor::Category.site(@cur_site).readable(@cur_user, @cur_site).tree_sort
    if category_id = params[:category].presence
      @category ||= Gws::Monitor::Category.site(@cur_site).readable(@cur_user, @cur_site).where(id: category_id).first
    end
  end

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

  def pre_params
    current_category_id = super
    if @category.present?
      current_category_id[:category_ids] = [ @category.id ]
    end
    current_category_id
  end

  public

  def index
    @items = @model.site(@cur_site).topic

    @items = @items.and_public.and_readable(@cur_user, @cur_site)

    if @category.present?
      params[:s] ||= {}
      params[:s][:site] = @cur_site
      params[:s][:category] = @category.name
    end

    custom_group_ids = []
    Gws::CustomGroup.site(@cur_site).each do |custom_group|
      custom_group_ids.push(custom_group._id) if custom_group.member_ids.include?(@cur_user.id)
    end

    @items = @items.search(params[:s]).
        custom_order(params.dig(:s, :sort) || 'updated_desc').
        and_topics(@cur_user.id, @cur_group.id, custom_group_ids).
        page(params[:page]).per(50)
  end

  def show
    raise "403" unless @item.readable?(@cur_user, @cur_site)
    render file: "/gws/monitor/main/show_#{@item.mode}"
  end

  def create
    @item = @model.new get_params

    if @item.admin_setting == "0"
      @item.attributes["user_ids"] = []
    elsif @item.admin_setting == "1"
      @item.attributes["group_ids"] = []
    end

    @item.attributes["readable_group_ids"] = (@item.attend_group_ids + @item.readable_group_ids).uniq

    raise "403" unless @item.allowed?(:edit, @cur_user, site: @cur_site)
{'fraction_non_alphanumeric': 0.13911653008195082, 'fraction_numerical': 0.003997601439136518, 'mean_word_length': 3.716305372290292, 'pattern_counts': {'":': 0, '<': 17, '<?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': '7550768', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1715, 'n_words': 307}