<commit_before># frozen_string_literal: true

require "#{Rails.root}/lib/importers/user_importer"

#= Controller for adding multiple users to a course at once
class MassEnrollmentController < ApplicationController
  respond_to :html
  before_action :require_permissions

  def index
    @course = Course.find_by_slug(params[:course_id])
  end

  def add_users
    @course = Course.find_by_slug(params[:course_id])

    usernames_list = params[:usernames].lines.map(&:strip)
    @results = {}
    usernames_list.each do |username|
      @results[username] = add_user(username)
    end
    render :index
  end

  private

  def add_user(username)<commit_msg>Make sure course pages get updated after mass enrollment<commit_after># frozen_string_literal: true

require "#{Rails.root}/lib/importers/user_importer"
require "#{Rails.root}/app/workers/update_course_worker"

#= Controller for adding multiple users to a course at once
class MassEnrollmentController < ApplicationController
  respond_to :html
  before_action :require_permissions

  def index
    @course = Course.find_by_slug(params[:course_id])
  end

  def add_users
    @course = Course.find_by_slug(params[:course_id])

    usernames_list = params[:usernames].lines.map(&:strip)
    @results = {}
    usernames_list.each do |username|
      @results[username] = add_user(username)
    end

    UpdateCourseWorker.schedule_edits(course: @course, editing_user: current_user)

    render :index
  end

  private

  def add_user(username)
{'fraction_non_alphanumeric': 0.09218436873747494, 'fraction_numerical': 0.0, 'mean_word_length': 4.674242424242424, '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': '6710540', 'n_tokens_mistral': 472, 'n_tokens_neox': 464, 'n_words': 105}