<commit_before># Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  theme :current_theme
  before_filter :require_http_auth
  before_filter :violate_mvc
  
  # ==================
  # = Authentication =
  # ==================
  include AuthenticatedSystem
  
  # When access is denied redirect to the login page.
  def access_denied
    respond_to do |format|
      format.html do
        store_location
        flash[:error] = "You must be logged in to access this feature."
        redirect_to '/login'
      end
      format.xml do
        request_http_basic_authentication 'Password required to access this feature.'
      end
    end
  end


  def current_theme
    @current_theme ||= (Settings.public_theme || Settings.current_theme)
  end
  hide_action :current_theme
  helper_method :current_theme

  # Returns the names of all controllers that should be interacted with (resourceful)
  #  * must be plural
  #  * no slashes (aka supcontrollers)
  #
  # => ["users", "roles", "images"] ...
  def primary_controller_names
    ActionController::Routing::Routes.routes.collect {|r| r.defaults[:controller] }.uniq.compact.
      reject { |c| c=~%r~/~}.
      select { |c| c=~%r~s$~ } - %w(sessions javascripts)
  end
  helper_method :primary_controller_names
  

  private
  def violate_mvc
    [Grid, Rendering, Part].each { |k| k.active_controller = self }
  end
  def fetch_rendering
    @rendering = Rendering.find(params[:rendering_id])
  end

  def require_http_auth
    if `hostname` =~ /soykaf|lanpartei/i 
      if auth =  APP_CONFIG['http_auth']
        authenticate_or_request_with_http_basic do |user_name, password|
          user_name == auth['name'] && password == auth['password']
        end      
      end
    end
  end

  # See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you're not using the cookie session store
  protect_from_forgery # :secret => 'da7c5d7c04e209653d264f43028c248a'
end<commit_msg>make redirect_back_or_default toolbox aware<commit_after># Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
  helper :all # include all helpers, all the time
  theme :current_theme
  before_filter :require_http_auth
  before_filter :violate_mvc
  
  # ==================
  # = Authentication =
  # ==================
  include AuthenticatedSystem
  
  # When access is denied redirect to the login page.
  def access_denied
    respond_to do |format|
      format.html do
        store_location
        flash[:error] = "You must be logged in to access this feature."
        redirect_to '/login'
      end
      format.xml do
        request_http_basic_authentication 'Password required to access this feature.'
      end
    end
  end


  def current_theme
    @current_theme ||= (Settings.public_theme || Settings.current_theme)
  end
  hide_action :current_theme
  helper_method :current_theme

  # Returns the names of all controllers that should be interacted with (resourceful)
  #  * must be plural
  #  * no slashes (aka supcontrollers)
  #
  # => ["users", "roles", "images"] ...
  def primary_controller_names
    ActionController::Routing::Routes.routes.collect {|r| r.defaults[:controller] }.uniq.compact.
      reject { |c| c=~%r~/~}.
      select { |c| c=~%r~s$~ } - %w(sessions javascripts)
  end
  helper_method :primary_controller_names
  

  private
  def violate_mvc
    [Grid, Rendering, Part].each { |k| k.active_controller = self }
  end
  def fetch_rendering
    @rendering = Rendering.find(params[:rendering_id])
  end

  def require_http_auth
    if `hostname` =~ /soykaf|lanpartei/i 
      if auth =  APP_CONFIG['http_auth']
        authenticate_or_request_with_http_basic do |user_name, password|
          user_name == auth['name'] && password == auth['password']
        end      
      end
    end
  end

  def redirect_back_or_default(default)
    respond_to do |wants|
      wants.html { redirect_to(session[:return_to] || default) }
      wants.js do
        render :update do |page|
          if session[:return_to]
            page.toolbox.pop_and_refresh_last() 
            # TODO what else? where did we came from? was there a Toolbox frame involved?
          else
            page.toolbox.pop_and_refresh_last()
          end
        end
      end
    end
    session[:return_to] = nil
  end

  # See ActionController::RequestForgeryProtection for details
  # Uncomment the :secret if you're not using the cookie session store
  protect_from_forgery # :secret => 'da7c5d7c04e209653d264f43028c248a'
end
{'fraction_non_alphanumeric': 0.09720509658857378, 'fraction_numerical': 0.009042334566378957, 'mean_word_length': 3.258092738407699, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '336925', 'n_tokens_mistral': 1519, 'n_tokens_neox': 1454, 'n_words': 420}