<commit_before># coding: UTF-8

class ApplicationController < ActionController::Base
  include SslRequirement
  protect_from_forgery

  helper :all

  before_filter :browser_is_html5_compliant?
  before_filter :check_domain
  after_filter :remove_flash_cookie
  before_filter :allow_cross_domain_access

  rescue_from NoHTML5Compliant, :with => :no_html5_compliant
  rescue_from RecordNotFound,   :with => :render_404

  # this disables SSL requirement in non-production environments
  unless Rails.env.production?
    def self.ssl_required(*splat)
      false
    end
    def self.ssl_allowed(*splat)
      true
    end
  end


  protected

  def allow_cross_domain_access
    unless Rails.env.production?
      response.headers["Access-Control-Allow-Origin"] = "*"
      response.headers["Access-Control-Allow-Methods"] = "*"
    end
  end

  def render_404
    respond_to do |format|
      format.html do
        render :file => "public/404.html", :status => 404, :layout => false
      end
      format.json do
        head :not_found
      end
    end
  end

  def render_500
    render :file => "public/500.html", :status => 500, :layout => false
  end

  def login_required
    authenticated?(request.subdomain) || not_authorized
  end

  def api_authorization_required
    authenticate!(:api_authentication, :scope => request.subdomain)
  end

  def not_authorized
    respond_to do |format|
      format.html do
        redirect_to login_url(:host => CartoDB.account_host) and return
      end
      format.json do
        head :unauthorized
      end
    end
  end

  def check_domain
    if Rails.env.production?
     protocol   = 'https'
     port       = ""
    else
     protocol   = 'http'
     port       = ":#{request.port}"
    end
    app_domain = CartoDB.session_domain

    if logged_in?
      if request.host !~ /^#{current_user.username}#{app_domain}$/
        redirect_to "#{protocol}://#{current_user.username}#{app_domain}#{port}"
      end
    end
  end

  def table_privacy_text(table)
    if table.is_a?(Table)
      table.private? ? 'PRIVATE' : 'PUBLIC'
    elsif table.is_a?(Hash)
      table["privacy"]
    end
  end<commit_msg>check for current_user<commit_after># coding: UTF-8

class ApplicationController < ActionController::Base
  include SslRequirement
  protect_from_forgery

  helper :all

  before_filter :browser_is_html5_compliant?
  before_filter :check_domain
  after_filter :remove_flash_cookie
  before_filter :allow_cross_domain_access

  rescue_from NoHTML5Compliant, :with => :no_html5_compliant
  rescue_from RecordNotFound,   :with => :render_404

  # this disables SSL requirement in non-production environments
  unless Rails.env.production?
    def self.ssl_required(*splat)
      false
    end
    def self.ssl_allowed(*splat)
      true
    end
  end


  protected

  def allow_cross_domain_access
    unless Rails.env.production?
      response.headers["Access-Control-Allow-Origin"] = "*"
      response.headers["Access-Control-Allow-Methods"] = "*"
    end
  end

  def render_404
    respond_to do |format|
      format.html do
        render :file => "public/404.html", :status => 404, :layout => false
      end
      format.json do
        head :not_found
      end
    end
  end

  def render_500
    render :file => "public/500.html", :status => 500, :layout => false
  end

  def login_required
    authenticated?(request.subdomain) || not_authorized
  end

  def api_authorization_required
    authenticate!(:api_authentication, :scope => request.subdomain)
  end

  def not_authorized
    respond_to do |format|
      format.html do
        redirect_to login_url(:host => CartoDB.account_host) and return
      end
      format.json do
        head :unauthorized
      end
    end
  end

  def check_domain
    if Rails.env.production?
     protocol   = 'https'
     port       = ""
    else
     protocol   = 'http'
     port       = ":#{request.port}"
    end
    app_domain = CartoDB.session_domain

    if logged_in? && current_user
      if request.host !~ /^#{current_user.username}#{app_domain}$/
        redirect_to "#{protocol}://#{current_user.username}#{app_domain}#{port}"
      end
    end
  end

  def table_privacy_text(table)
    if table.is_a?(Table)
      table.private? ? 'PRIVATE' : 'PUBLIC'
    elsif table.is_a?(Hash)
      table["privacy"]
    end
  end
{'fraction_non_alphanumeric': 0.09390103567318757, 'fraction_numerical': 0.011507479861910242, 'mean_word_length': 2.890778871978514, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 23, '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': '3857362', 'n_tokens_mistral': 1427, 'n_tokens_neox': 1366, 'n_words': 310}