<commit_before>class ApplicationController < ActionController::Base
  include Clearance::Controller

  before_action :set_locale
  before_action :fix_chapter_ids

  def must_be_logged_in
    if current_user.blank? || !current_user.logged_in?
      flash[:notice] = t("flash.permissions.must-be-logged-in")
      redirect_to root_url
    end
  end

  def must_be_admin
    unless current_user.try(:admin?)
      flash[:notice] = t("flash.permissions.must-be-admin")
      redirect_to root_url
    end
  end

  def must_be_able_to_manage_chapter_users(role_id)
    role = Role.find(role_id)
    if !current_user.try(:admin?) && !current_user.can_manage_users?(role.chapter)
      flash[:notice] = t("flash.permissions.cannot-remove-user")
      redirect_to root_url
    end
  end

  def must_be_able_to_manage_chapter
    chapter = Chapter.find(params[:id])
    unless current_user.try(:admin?) || (current_user && current_user.can_manage_chapter?(chapter))
      flash[:notice] = t("flash.permissions.must-be-dean-or-admin")
      redirect_to root_url
    end
  end

  def current_user
    super || Guest.new
  end

  def set_locale
    begin
      I18n.locale = params[:locale] || I18n.default_locale
    rescue I18n::InvalidLocale
      I18n.locale = I18n.default_locale
    end
  end

  def default_url_options(options={})
    { :locale => I18n.locale }
  end

  def fix_chapter_ids
    if params[:chapter_id]
      chapter = Chapter.find_by_slug(params[:chapter_id])
      params[:chapter_id] = (chapter && chapter.id) || params[:chapter_id]
    end

    if params[:id]
      chapter = Chapter.find_by_id(params[:id])
      params[:id] = (chapter && chapter.id) || params[:id]
    end
  end

  def render_404
    respond_to do |format|
      format.all { render status: :not_found, template: "errors/not_found", formats: [:html], content_type: [:html] }
    end
  end
end<commit_msg>Fix 404 Content-Type<commit_after>class ApplicationController < ActionController::Base
  include Clearance::Controller

  before_action :set_locale
  before_action :fix_chapter_ids

  def must_be_logged_in
    if current_user.blank? || !current_user.logged_in?
      flash[:notice] = t("flash.permissions.must-be-logged-in")
      redirect_to root_url
    end
  end

  def must_be_admin
    unless current_user.try(:admin?)
      flash[:notice] = t("flash.permissions.must-be-admin")
      redirect_to root_url
    end
  end

  def must_be_able_to_manage_chapter_users(role_id)
    role = Role.find(role_id)
    if !current_user.try(:admin?) && !current_user.can_manage_users?(role.chapter)
      flash[:notice] = t("flash.permissions.cannot-remove-user")
      redirect_to root_url
    end
  end

  def must_be_able_to_manage_chapter
    chapter = Chapter.find(params[:id])
    unless current_user.try(:admin?) || (current_user && current_user.can_manage_chapter?(chapter))
      flash[:notice] = t("flash.permissions.must-be-dean-or-admin")
      redirect_to root_url
    end
  end

  def current_user
    super || Guest.new
  end

  def set_locale
    begin
      I18n.locale = params[:locale] || I18n.default_locale
    rescue I18n::InvalidLocale
      I18n.locale = I18n.default_locale
    end
  end

  def default_url_options(options={})
    { :locale => I18n.locale }
  end

  def fix_chapter_ids
    if params[:chapter_id]
      chapter = Chapter.find_by_slug(params[:chapter_id])
      params[:chapter_id] = (chapter && chapter.id) || params[:chapter_id]
    end

    if params[:id]
      chapter = Chapter.find_by_id(params[:id])
      params[:id] = (chapter && chapter.id) || params[:id]
    end
  end

  def render_404
    respond_to do |format|
      format.all { render status: :not_found, template: "errors/not_found", formats: [:html], content_type: "text/html" }
    end
  end
end
{'fraction_non_alphanumeric': 0.11234469997356596, 'fraction_numerical': 0.008723235527359239, 'mean_word_length': 3.5535499398315284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '660772', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1263, 'n_words': 237}