<commit_before># CoursesController
class CoursesController < ApplicationController
  before_action :check_for_course, only: [:show]
  before_action :set_course, only: [:show, :display, :take_random_quiz,
                                    :show_random_quizzes,
                                    :render_question_counter]
  before_action :set_course_admin, only: [:edit, :update, :destroy, :inspect]
  before_action :check_if_enough_questions, only: [:show_random_quizzes,
                                                   :take_random_quiz]
  before_action :check_for_consent
  authorize_resource
  layout 'administration'

  def edit
    I18n.locale = @course.locale || I18n.default_locale
    cookies[:edited_course] = params[:id]
  end

  def update
    I18n.locale = @course.locale || I18n.default_locale
    @course.update(course_params)
    @errors = @course.errors
  end

  def create
    @course = Course.new(course_params)
    @course.save
    if @course.valid?
      # set organizational_concept to default
      set_organizational_defaults
      create_notifications
      send_notification_email
      redirect_to administration_path
      return
    end
    @errors = @course.errors
  end

  def show
    cookies[:current_course] = @course.id
    @lecture = @course.primary_lecture(current_user)
    # deactivate http caching for the moment
    # "refused to execute script because its mime type is not executable
    #  error in Chrome"...
    if stale?(etag: @lecture || @course,
              last_modified: [current_user.updated_at, @course.updated_at,
                              Time.parse(ENV['RAILS_CACHE_ID']),
                              @lecture&.updated_at || current_user.updated_at,
                              Thredded::UserDetail.find_by(user_id: current_user.id)
                                                  &.last_seen_at || current_user.updated_at,
                              @lecture&.forum&.updated_at].max)
      unless @course.in?(current_user.courses) && @lecture
        cookies[:current_lecture] = nil
        I18n.locale = @course.locale || I18n.default_locale
        render layout: 'application'
        return
      end
      cookies[:current_lecture] = @lecture.id
      I18n.locale = @lecture.locale_with_inheritance || I18n.default_locale
      @lecture = @course.primary_lecture(current_user, eagerload: true)
      render template: 'lectures/show', layout: 'application'<commit_msg>avoid nil entry in array of Times<commit_after># CoursesController
class CoursesController < ApplicationController
  before_action :check_for_course, only: [:show]
  before_action :set_course, only: [:show, :display, :take_random_quiz,
                                    :show_random_quizzes,
                                    :render_question_counter]
  before_action :set_course_admin, only: [:edit, :update, :destroy, :inspect]
  before_action :check_if_enough_questions, only: [:show_random_quizzes,
                                                   :take_random_quiz]
  before_action :check_for_consent
  authorize_resource
  layout 'administration'

  def edit
    I18n.locale = @course.locale || I18n.default_locale
    cookies[:edited_course] = params[:id]
  end

  def update
    I18n.locale = @course.locale || I18n.default_locale
    @course.update(course_params)
    @errors = @course.errors
  end

  def create
    @course = Course.new(course_params)
    @course.save
    if @course.valid?
      # set organizational_concept to default
      set_organizational_defaults
      create_notifications
      send_notification_email
      redirect_to administration_path
      return
    end
    @errors = @course.errors
  end

  def show
    cookies[:current_course] = @course.id
    @lecture = @course.primary_lecture(current_user)
    # deactivate http caching for the moment
    # "refused to execute script because its mime type is not executable
    #  error in Chrome"...
    if stale?(etag: @lecture || @course,
              last_modified: [current_user.updated_at, @course.updated_at,
                              Time.parse(ENV['RAILS_CACHE_ID']),
                              @lecture&.updated_at || current_user.updated_at,
                              Thredded::UserDetail.find_by(user_id: current_user.id)
                                                  &.last_seen_at || current_user.updated_at,
                              @lecture&.forum&.updated_at || current_user.updated_at].max)
      unless @course.in?(current_user.courses) && @lecture
        cookies[:current_lecture] = nil
        I18n.locale = @course.locale || I18n.default_locale
        render layout: 'application'
        return
      end
      cookies[:current_lecture] = @lecture.id
      I18n.locale = @lecture.locale_with_inheritance || I18n.default_locale
      @lecture = @course.primary_lecture(current_user, eagerload: true)
      render template: 'lectures/show', layout: 'application'
{'fraction_non_alphanumeric': 0.08759862431721627, 'fraction_numerical': 0.006473801335221525, 'mean_word_length': 2.4428969359331476, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1671872', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1418, 'n_words': 286}