<commit_before>class UserGroupsController < ApplicationController
  before_action :load_user_groups
  before_action :find_user_group, only: [:add_users]
  load_and_authorize_resource

  def index
    @add_mode = params[:add].present?
    render(partial: "index_table") if request.xhr?
  end

  def edit
    render(partial: "edit_name")
  end

  def update
    @user_group.name = params[:name]
    @user_group.save
    render json: { name: @user_group.name }
  end

  def create
    @add_mode = params[:add].present?
    @user_group.name = params[:name]
    @user_group.save
    render(partial: "index_table") if request.xhr?
  end

  def destroy
    @user_group.destroy
    page_info = view_context.page_entries_info(load_user_groups, model: UserGroup)
    render json: { page_entries_info: page_info }
  end

  def add_users
    users = load_users(params[:user_ids])
    @user_group.users = users
    @user_group.save
    flash[:success] = I18n.t('user_group.add_users_success', count: users.count, group: @user_group.name)
    flash.keep(:success)
    render nothing: true
  end

  private

  def load_user_groups
    @user_groups = UserGroup.accessible_by(current_ability).order(:name).paginate(page: 1, per_page: 500)
  end

  def find_user_group
    @user_group = UserGroup.accessible_by(current_ability).find(params[:user_group_id])
  end

  def load_users(user_ids)
    @user_groups = User.accessible_by(current_ability).includes(:assignments).where(id: user_ids, assignments: { mission: current_mission})
  end
end
<commit_msg>4745: Fixes duplication issue and overrwrite issue<commit_after>class UserGroupsController < ApplicationController
  before_action :load_user_groups
  before_action :find_user_group, only: [:add_users]
  load_and_authorize_resource

  def index
    @add_mode = params[:add].present?
    render(partial: "index_table") if request.xhr?
  end

  def edit
    render(partial: "edit_name")
  end

  def update
    @user_group.name = params[:name]
    @user_group.save
    render json: { name: @user_group.name }
  end

  def create
    @add_mode = params[:add].present?
    @user_group.name = params[:name]
    @user_group.save
    render(partial: "index_table") if request.xhr?
  end

  def destroy
    @user_group.destroy
    page_info = view_context.page_entries_info(load_user_groups, model: UserGroup)
    render json: { page_entries_info: page_info }
  end

  def add_users
    users = load_users(params[:user_ids])
    @user_group.users << (users - @user_group.users)
    @user_group.save
    flash[:success] = I18n.t("user_group.add_users_success", count: users.count, group: @user_group.name)
    flash.keep(:success)
    render nothing: true
  end

  private

  def load_user_groups
    @user_groups = UserGroup.accessible_by(current_ability).order(:name).paginate(page: 1, per_page: 500)
  end

  def find_user_group
    @user_group = UserGroup.accessible_by(current_ability).find(params[:user_group_id])
  end

  def load_users(user_ids)
    @user_groups = User.accessible_by(current_ability).includes(:assignments).where(id: user_ids, assignments: { mission: current_mission})
  end
end

{'fraction_non_alphanumeric': 0.10255591054313098, 'fraction_numerical': 0.005111821086261981, 'mean_word_length': 4.388984509466437, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2480915', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1033, 'n_words': 207}