Sha256: 611371e7b3d90fb7f1a65ff86ae9a1688de7adb376425c882272e4554194ed41

Contents?: true

Size: 877 Bytes

Versions: 3

Compression:

Stored size: 877 Bytes

Contents

module Netzke
  module Core
    module Masquerading
      # Example:
      #   masquarade_as(:role, 2)
      #   masquarade_as(:user, 4)
      #   masquarade_as(:world)
      def masquerade_as(authority_level, authority_id = true)
        reset_masquerading
        session.merge!(:"masq_#{authority_level}" => authority_id)
      end
  
      def reset_masquerading
        session[:masq_world] = session[:masq_role] = session[:masq_user] = nil
      end
  
      # Who are we acting as?
      def authority_level
        if session[:masq_world]
          :world
        elsif session[:masq_role]
          [:role, session[:masq_role]]
        elsif session[:masq_user]
          [:user, session[:masq_user]]
        elsif session[:netzke_user_id]
          [:self, session[:netzke_user_id]]
        else
          :none # or nil ?
        end
      end
    
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
netzke-core-0.6.2 lib/netzke/core/masquerading.rb
netzke-core-0.6.1 lib/netzke/core/masquerading.rb
netzke-core-0.6.0 lib/netzke/core/masquerading.rb