<commit_before>class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  include GlobalHelpers
  include Pundit
  
  helper_method GlobalHelpers.instance_methods

  # Override build_footer method in ActiveAdmin::Views::Pages
  require 'active_admin_views_pages_base.rb'

  rescue_from CanCan::AccessDenied do |exception|
    redirect_to root_url, :alert => exception.message
  end

  before_filter :set_locale

  after_filter :store_location

  def set_locale
    # parameter from url takes precedence
    # check if locale is defined
    if params[:locale] # and I18n.available_locales.include? params[:locale] # throw an error if not available
      # if locales data is present in the parameter from url use it
      I18n.locale = params[:locale]
    elsif user_signed_in? and !current_user[:language_id].nil?
      I18n.locale = Language.find_by_id(current_user[:language_id]).abbreviation
      # if user has set preferred language use it
    elsif user_signed_in? and current_user.organisation.present? and !current_user.organisation[:language_id].nil?
      I18n.locale = Language.find_by_id(current_user.organisation[:language_id]).abbreviation
      # use user's organization language, keep in mine the "OTHER ORG" edge case which should use default language
    else
      # just use the default language, line can be commented out, included just for clarity
      I18n.locale = I18n.default_locale<commit_msg>added default redirect to 403 page for unauth<commit_after>class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception

  include GlobalHelpers
  include Pundit
  
  helper_method GlobalHelpers.instance_methods

  # Override build_footer method in ActiveAdmin::Views::Pages
  require 'active_admin_views_pages_base.rb'

  rescue_from CanCan::AccessDenied do |exception|
    redirect_to root_url, :alert => exception.message
  end

  rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized

  def user_not_authorized
    render(file: File.join(Rails.root, 'public/403.html'), status: 403, layout: false)
  end

  before_filter :set_locale

  after_filter :store_location

  def set_locale
    # parameter from url takes precedence
    # check if locale is defined
    if params[:locale] # and I18n.available_locales.include? params[:locale] # throw an error if not available
      # if locales data is present in the parameter from url use it
      I18n.locale = params[:locale]
    elsif user_signed_in? and !current_user[:language_id].nil?
      I18n.locale = Language.find_by_id(current_user[:language_id]).abbreviation
      # if user has set preferred language use it
    elsif user_signed_in? and current_user.organisation.present? and !current_user.organisation[:language_id].nil?
      I18n.locale = Language.find_by_id(current_user.organisation[:language_id]).abbreviation
      # use user's organization language, keep in mine the "OTHER ORG" edge case which should use default language
    else
      # just use the default language, line can be commented out, included just for clarity
      I18n.locale = I18n.default_locale
{'fraction_non_alphanumeric': 0.06787762906309751, 'fraction_numerical': 0.010516252390057362, 'mean_word_length': 4.507017543859649, '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': '1201782', 'n_tokens_mistral': 922, 'n_tokens_neox': 884, 'n_words': 270}