Skip to content
Extraits de code Groupes Projets
application_controller.rb 1,52 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
    #   Copyright (c) 2010, Diaspora Inc.  This file is
    
    Raphael's avatar
    Raphael a validé
    #   licensed under the Affero General Public License version 3 or later.  See
    
    Raphael's avatar
    Raphael a validé
    #   the COPYRIGHT file.
    
    Raphael Sofaer's avatar
    Raphael Sofaer a validé
    class ApplicationController < ActionController::Base
    
      protect_from_forgery :except => :receive
    
    maxwell's avatar
    maxwell a validé
      before_filter :set_contacts_notifications_and_status, :except => [:create, :update]
    
      before_filter :count_requests
    
      before_filter :set_invites
    
      before_filter :set_locale
    
      before_filter :which_action_and_user
    
    danielvincent's avatar
    danielvincent a validé
    
    
    maxwell's avatar
    maxwell a validé
      def set_contacts_notifications_and_status
    
    Raphael's avatar
    Raphael a validé
        if user_signed_in?
    
    Raphael's avatar
    Raphael a validé
          @all_aspects = current_user.aspects.includes(:aspect_memberships)
    
    Raphael's avatar
    Raphael a validé
          @notification_count = Notification.for(current_user, :unread =>true).count
    
          @user_id = current_user.id
    
    Raphael's avatar
    Raphael a validé
        end
    
      end
    
      def count_requests
    
        @request_count = Request.where(:recipient_id => current_user.person.id).count if current_user
    
    maxwell's avatar
    maxwell a validé
        if user_signed_in?
    
          @invites = current_user.invites
        end
      end
    
      def which_action_and_user
    
        str = "event=request_with_user controller=#{self.class} action=#{self.action_name} "
    
          str << "uid=#{current_user.id} "
          str << "user_created_at=#{current_user.created_at.to_date.to_s} " if current_user.created_at
    
        else
          str << 'uid=nil'
        end
        Rails.logger.info str
      end
    
    
    maxwell's avatar
    maxwell a validé
        if user_signed_in?
    
          I18n.locale = current_user.language
        else
          I18n.locale = request.compatible_language_from AVAILABLE_LANGUAGE_CODES
        end
    
    Raphael Sofaer's avatar
    Raphael Sofaer a validé
    end