<commit_before>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class ApplicationController < ActionController::Base
  has_mobile_fu
  protect_from_forgery :except => :receive

  before_filter :set_contacts_notifications_and_status, :except => [:create, :update]
  before_filter :count_requests
  before_filter :set_invites
  before_filter :set_locale
  before_filter :set_git_header
  before_filter :which_action_and_user
  prepend_before_filter :clear_gc_stats
  before_filter :set_grammatical_gender

  inflection_method :grammatical_gender => :gender

  def set_contacts_notifications_and_status
    if user_signed_in?
      @aspect = nil
      @object_aspect_ids = []
      @all_aspects = current_user.aspects.includes(:aspect_memberships)
      @notification_count = Notification.for(current_user, :unread =>true).count
      @user_id = current_user.id
    end
  end

  def count_requests
    @request_count = Request.where(:recipient_id => current_user.person.id).count if current_user
  end

  def set_invites
    if user_signed_in?
      @invites = current_user.invites
    end
  end

  def set_git_header
    headers['X-Git-Update'] = GIT_UPDATE unless GIT_UPDATE.nil?
    headers['X-Git-Revision'] = GIT_REVISION unless GIT_REVISION.nil?
  end

  def which_action_and_user
    str = "event=request_with_user controller=#{self.class} action=#{self.action_name} "
    if current_user
      str << "uid=#{current_user.id} "
      str << "user_created_at='#{current_user.created_at.to_date.to_s}' user_created_at_unix=#{current_user.created_at.to_i} " if current_user.created_at<commit_msg>it can happen that the http referer is nil when we expect it to be set (for example if the user has a privacy extension enabled<commit_after>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class ApplicationController < ActionController::Base
  has_mobile_fu
  protect_from_forgery :except => :receive

  before_filter :ensure_http_referer_is_set
  before_filter :set_contacts_notifications_and_status, :except => [:create, :update]
  before_filter :count_requests
  before_filter :set_invites
  before_filter :set_locale
  before_filter :set_git_header
  before_filter :which_action_and_user
  prepend_before_filter :clear_gc_stats
  before_filter :set_grammatical_gender

  inflection_method :grammatical_gender => :gender

  def ensure_http_referer_is_set
    request.env['HTTP_REFERER'] ||= '/aspects'
  end

  def set_contacts_notifications_and_status
    if user_signed_in?
      @aspect = nil
      @object_aspect_ids = []
      @all_aspects = current_user.aspects.includes(:aspect_memberships)
      @notification_count = Notification.for(current_user, :unread =>true).count
      @user_id = current_user.id
    end
  end

  def count_requests
    @request_count = Request.where(:recipient_id => current_user.person.id).count if current_user
  end

  def set_invites
    if user_signed_in?
      @invites = current_user.invites
    end
  end

  def set_git_header
    headers['X-Git-Update'] = GIT_UPDATE unless GIT_UPDATE.nil?
    headers['X-Git-Revision'] = GIT_REVISION unless GIT_REVISION.nil?
  end

  def which_action_and_user
    str = "event=request_with_user controller=#{self.class} action=#{self.action_name} "
    if current_user
      str << "uid=#{current_user.id} "
      str << "user_created_at='#{current_user.created_at.to_date.to_s}' user_created_at_unix=#{current_user.created_at.to_i} " if current_user.created_at
{'fraction_non_alphanumeric': 0.08189537113119694, 'fraction_numerical': 0.002738975623116954, 'mean_word_length': 4.609831029185868, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3819908', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1204, 'n_words': 255}