<commit_before># encoding: utf-8
#
#  = Application Controller Base Class
#
#  This is the base class for all the application's controllers.  It contains
#  all the important application-wide filters and lots of helper methods.
#  Anything that appears here is available to every controller and view.
#
#  == Filters
#
#  autologin::          Determine which if any User is logged in.
#  set_locale::         Determine which language is requested.
#  check_user_alert::   Check if User has an alert to be displayed.
#
#  == Methods
#  *NOTE*: Methods in parentheses are "private" helpers; you are encouraged to
#  use the public ones instead.
#
#  ==== User authentication
#  autologin::              (filter: determine which user is logged in)
#  login_for_ajax::         (filter: minimal version of autologin for ajax)
#  check_permission::       Make sure current User is the right one.
#  check_permission!::      Same, but flashes "denied" message, too.
#  reviewer?::              Is the current User a reviewer?
#  in_admin_mode?::         Is the current User in admin mode?
#  unshown_notifications?:: Are there pending Notification's of a given type?
#  check_user_alert::       (filter: redirect to show_alert if has alert)
#  autologin_cookie_set::   (set autologin cookie)
#  clear_autologin_cookie:: (clear autologin cookie)
#  session_user_set::       (store user in session -- id only)
#  session_user::           (retrieve user from session)
#
#  ==== Internationalization
#  all_locales::            Array of available locales for which we have
#                           translations.
#  set_locale::             (filter: determine which locale is requested)
#  set_timezone::           (filter: Set timezone from cookie set by client's
#                            browser.)
#  sorted_locales_from_request_header::
#                           (parse locale preferences from request header)
#  valid_locale_from_request_header::
#                           (choose locale that best matches request header)
#
#  ==== Error handling
#  flash_notices?::         Are there any errors pending?
#  flash_get_notices::      Get list of errors.
#  flash_notice_level::     Get current notice level.
#  flash_clear::            Clear error messages.
#  flash_notice::           Add a success message.
#  flash_warning::          Add a warning message.
#  flash_error::            Add an error message.
#  flash_object_errors::    Add all errors for a given instance.
#
#  ==== Name validation
#  construct_approved_names:: Creates a list of names if they've been approved.
#  construct_approved_name::  (helper)
#
#  ==== Searching
#  clear_query_in_session:: Clears out Query stored in session below.
#  store_query_in_session:: Stores Query in session for use by
#                           create_species_list.
#  query_from_session::     Gets Query that was stored in the session above.
#  query_params::           Parameters to add to link_to, etc. for passing
#                           Query around.
#  query_params_set::       Make +query_params+ refer to a given Query.
#  pass_query_params::      Tell +query_params+ to pass-through the Query
#                            given to this action.
#  find_query::             Find a given Query or return nil.
#  find_or_create_query::   Find appropriate Query or create as necessary.
#  create_query::           Create a new Query from scratch.
#  redirect_to_next_object:: Find next object from a Query and redirect to its
#                            show page.
#
#  ==== Indexes
#  show_index_of_objects::  Show paginated set of Query results as a list.
#  add_sorting_links::      Create sorting links for index pages.
#  find_or_goto_index::     Look up object by id, displaying error and
#                           redirecting on failure.
#  goto_index::             Redirect to a reasonable fallback (index) page
#                           in case of error.
#  paginate_letters::       Paginate an Array by letter.
#  paginate_numbers::       Paginate an Array normally.
#
#  ==== Memory usage
#  log_memory_usage::       (filter: logs memory use stats from
#                           <tt>/proc/$$/smaps</tt>)
#  extra_gc::               (filter: calls <tt>ObjectSpace.garbage_collect</tt>)
#  count_objects::          (does... nothing??!!... for every Object that
#                           currently exists)
#
#  ==== Other stuff
#  disable_link_prefetching::    (filter: prevents prefetching of destroy
#                                 methods)
#  update_view_stats::           Called after each show_object request.
#  calc_layout_params::          Gather User's list layout preferences.
#  catch_errors                  (filter: catches errors for integration tests)
#  default_thumbnail_size::      Default thumbnail size: :thumbnail or :small.
#  default_thumbnail_size_set::  Change default thumbnail size for current user.
#
class ApplicationController < ActionController::Base
  require "extensions"
  require "login_system"
  require "csv"
  include LoginSystem

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

  around_action :catch_errors # if Rails.env == "test"
  before_action :kick_out_robots
  before_action :create_view_instance_variable
  before_action :verify_authenticity_token
  before_action :fix_bad_domains
  before_action :autologin
  before_action :set_locale
  before_action :set_timezone
  before_action :refresh_translations
  before_action :track_translations
  before_action :check_user_alert
  # before_action :extra_gc
  # after_action  :extra_gc
  # after_action  :log_memory_usage

  # Disable all filters except set_locale.
  # (Used to streamline API and Ajax controllers.)
  def self.disable_filters
    skip_action_callback :verify_authenticity_token
    skip_action_callback :fix_bad_domains
    skip_action_callback :autologin
    skip_action_callback :set_timezone
    skip_action_callback :refresh_translations
    skip_action_callback :track_translations
    skip_action_callback :check_user_alert
    # skip_action_callback   :extra_gc
    # skip_action_callback   :log_memory_usage<commit_msg>Make helper available to nested partials<commit_after># encoding: utf-8
#
#  = Application Controller Base Class
#
#  This is the base class for all the application's controllers.  It contains
#  all the important application-wide filters and lots of helper methods.
#  Anything that appears here is available to every controller and view.
#
#  == Filters
#
#  autologin::          Determine which if any User is logged in.
#  set_locale::         Determine which language is requested.
#  check_user_alert::   Check if User has an alert to be displayed.
#
#  == Methods
#  *NOTE*: Methods in parentheses are "private" helpers; you are encouraged to
#  use the public ones instead.
#
#  ==== User authentication
#  autologin::              (filter: determine which user is logged in)
#  login_for_ajax::         (filter: minimal version of autologin for ajax)
#  check_permission::       Make sure current User is the right one.
#  check_permission!::      Same, but flashes "denied" message, too.
#  reviewer?::              Is the current User a reviewer?
#  in_admin_mode?::         Is the current User in admin mode?
#  unshown_notifications?:: Are there pending Notification's of a given type?
#  check_user_alert::       (filter: redirect to show_alert if has alert)
#  autologin_cookie_set::   (set autologin cookie)
#  clear_autologin_cookie:: (clear autologin cookie)
#  session_user_set::       (store user in session -- id only)
#  session_user::           (retrieve user from session)
#
#  ==== Internationalization
#  all_locales::            Array of available locales for which we have
#                           translations.
#  set_locale::             (filter: determine which locale is requested)
#  set_timezone::           (filter: Set timezone from cookie set by client's
#                            browser.)
#  sorted_locales_from_request_header::
#                           (parse locale preferences from request header)
#  valid_locale_from_request_header::
#                           (choose locale that best matches request header)
#
#  ==== Error handling
#  flash_notices?::         Are there any errors pending?
#  flash_get_notices::      Get list of errors.
#  flash_notice_level::     Get current notice level.
#  flash_clear::            Clear error messages.
#  flash_notice::           Add a success message.
#  flash_warning::          Add a warning message.
#  flash_error::            Add an error message.
#  flash_object_errors::    Add all errors for a given instance.
#
#  ==== Name validation
#  construct_approved_names:: Creates a list of names if they've been approved.
#  construct_approved_name::  (helper)
#
#  ==== Searching
#  clear_query_in_session:: Clears out Query stored in session below.
#  store_query_in_session:: Stores Query in session for use by
#                           create_species_list.
#  query_from_session::     Gets Query that was stored in the session above.
#  query_params::           Parameters to add to link_to, etc. for passing
#                           Query around.
#  query_params_set::       Make +query_params+ refer to a given Query.
#  pass_query_params::      Tell +query_params+ to pass-through the Query
#                            given to this action.
#  find_query::             Find a given Query or return nil.
#  find_or_create_query::   Find appropriate Query or create as necessary.
#  create_query::           Create a new Query from scratch.
#  redirect_to_next_object:: Find next object from a Query and redirect to its
#                            show page.
#
#  ==== Indexes
#  show_index_of_objects::  Show paginated set of Query results as a list.
#  add_sorting_links::      Create sorting links for index pages.
#  find_or_goto_index::     Look up object by id, displaying error and
#                           redirecting on failure.
#  goto_index::             Redirect to a reasonable fallback (index) page
#                           in case of error.
#  paginate_letters::       Paginate an Array by letter.
#  paginate_numbers::       Paginate an Array normally.
#
#  ==== Memory usage
#  log_memory_usage::       (filter: logs memory use stats from
#                           <tt>/proc/$$/smaps</tt>)
#  extra_gc::               (filter: calls <tt>ObjectSpace.garbage_collect</tt>)
#  count_objects::          (does... nothing??!!... for every Object that
#                           currently exists)
#
#  ==== Other stuff
#  disable_link_prefetching::    (filter: prevents prefetching of destroy
#                                 methods)
#  update_view_stats::           Called after each show_object request.
#  calc_layout_params::          Gather User's list layout preferences.
#  catch_errors                  (filter: catches errors for integration tests)
#  default_thumbnail_size::      Default thumbnail size: :thumbnail or :small.
#  default_thumbnail_size_set::  Change default thumbnail size for current user.
#
class ApplicationController < ActionController::Base
  require "extensions"
  require "login_system"
  require "csv"
  include LoginSystem

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

  around_action :catch_errors # if Rails.env == "test"
  before_action :kick_out_robots
  before_action :create_view_instance_variable
  before_action :verify_authenticity_token
  before_action :fix_bad_domains
  before_action :autologin
  before_action :set_locale
  before_action :set_timezone
  before_action :refresh_translations
  before_action :track_translations
  before_action :check_user_alert
  # before_action :extra_gc
  # after_action  :extra_gc
  # after_action  :log_memory_usage

  # Make show_observation_helper available to nested partials
  helper :show_observation

  # Disable all filters except set_locale.
  # (Used to streamline API and Ajax controllers.)
  def self.disable_filters
    skip_action_callback :verify_authenticity_token
    skip_action_callback :fix_bad_domains
    skip_action_callback :autologin
    skip_action_callback :set_timezone
    skip_action_callback :refresh_translations
    skip_action_callback :track_translations
    skip_action_callback :check_user_alert
    # skip_action_callback   :extra_gc
    # skip_action_callback   :log_memory_usage
{'fraction_non_alphanumeric': 0.07261724659606657, 'fraction_numerical': 0.00015924834779839159, 'mean_word_length': 2.8503985285101163, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3618095', 'n_tokens_mistral': 3501, 'n_tokens_neox': 3401, 'n_words': 1166}