<commit_before>class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :quill_iframe
  before_action :authenticate!
  helper CMS::Helper

  rescue_from OAuth2::Error do
    session.delete :access_token
    authenticate!
  end

  def root
    # raise session[:user_role].inspect
    if session[:user_role] == :admin
      redirect_to cms_root_path
    else
      render text: '', head: :ok
    end
  end

protected

  def admin!
    return unless authenticate!

    unless session[:user_role] == :admin
      redirect_to root_path
    end
  end

  def authenticate!
    if session[:access_token].blank? && params[:anonymous].blank? && params[:student].blank?
      redirect_to oauth_redirect_path(back: request.fullpath)
      return false
    end

    true
  end

  def quill_iframe
    response.headers['X-Frame-Options'] = "ALLOW-FROM #{ENV['QUILL_SITE_URL']}"
  end
end<commit_msg>Better handling of session.<commit_after>class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  before_action :quill_iframe
  before_action :authenticate!
  helper CMS::Helper

  rescue_from OAuth2::Error do
    session.delete :access_token
    authenticate!
  end

  def root
    # raise session[:user_role].inspect
    if session[:user_role] == :admin
      redirect_to cms_root_path
    else
      render text: '', head: :ok
    end
  end

protected

  def admin!
    return unless authenticate!

    unless session[:user_role] == :admin
      redirect_to root_path
    end
  end

  def authenticate!
    return true if session[:activity_session_id] == :anonymous

    if session[:access_token].blank? && params[:anonymous].blank? && params[:student].blank?
      redirect_to oauth_redirect_path(back: request.fullpath)
      return false
    end

    true
  end

  def quill_iframe
    response.headers['X-Frame-Options'] = "ALLOW-FROM #{ENV['QUILL_SITE_URL']}"
  end
end
{'fraction_non_alphanumeric': 0.09067622950819672, 'fraction_numerical': 0.0010245901639344263, 'mean_word_length': 3.606132075471698, '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': '119553', 'n_tokens_mistral': 621, 'n_tokens_neox': 594, 'n_words': 145}