<commit_before># Sets a few devise configs and security measures
class ApplicationController < ActionController::Base
  set_current_tenant_by_subdomain(:fund, :subdomain)

  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery prepend: true, with: :exception

  prepend_before_action :authenticate_user!
  prepend_before_action :confirm_user_not_disabled!, unless: :devise_controller?

  if Rails.env.development?
    before_action :confirm_tenant_set_development
  end
  before_action :confirm_tenant_set
  before_action :configure_permitted_parameters, if: :devise_controller?
  before_action :prevent_caching_via_headers
  before_action :set_locale
  before_action :set_sentry_context
  before_action :set_paper_trail_whodunnit

  # Don't let any requests through without confirming a tenant is set.
  def confirm_tenant_set
    # There's an ActsAsTenant config method that does this too,
    # but we do it here so we can control when it runs.
    if ActsAsTenant.current_tenant.nil? && !ActsAsTenant.unscoped?
      raise ActsAsTenant::Errors::NoTenantSet<commit_msg>let us redirect for a bit if an env var is set, to point legacy systems toward new urls (#2456)<commit_after># Sets a few devise configs and security measures
class ApplicationController < ActionController::Base
  set_current_tenant_by_subdomain(:fund, :subdomain)

  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery prepend: true, with: :exception

  prepend_before_action :authenticate_user!
  prepend_before_action :confirm_user_not_disabled!, unless: :devise_controller?

  if Rails.env.development?
    before_action :confirm_tenant_set_development
  end
  before_action :redirect_if_legacy
  before_action :confirm_tenant_set
  before_action :configure_permitted_parameters, if: :devise_controller?
  before_action :prevent_caching_via_headers
  before_action :set_locale
  before_action :set_sentry_context
  before_action :set_paper_trail_whodunnit

  # redirect to new system if config is set
  def redirect_if_legacy
    if ENV['REDIRECT_DESTINATION'].present?
      redirect_to ENV['REDIRECT_DESTINATION']
    end
  end

  # Don't let any requests through without confirming a tenant is set.
  def confirm_tenant_set
    # There's an ActsAsTenant config method that does this too,
    # but we do it here so we can control when it runs.
    if ActsAsTenant.current_tenant.nil? && !ActsAsTenant.unscoped?
      raise ActsAsTenant::Errors::NoTenantSet
{'fraction_non_alphanumeric': 0.05568445475638051, 'fraction_numerical': 0.0015467904098994587, 'mean_word_length': 5.356265356265356, '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': '5145739', 'n_tokens_mistral': 811, 'n_tokens_neox': 781, 'n_words': 234}