Sha256: 4c1bbc8c9eaf684c5ad324125e4997b30dee0a651fb27fc6d8a0f0f2da647d5b

Contents?: true

Size: 1.32 KB

Versions: 33

Compression:

Stored size: 1.32 KB

Contents

module Lockdown
  module Session

    protected

    def add_lockdown_session_values(user = nil)
      user ||= current_user

      if user
        session[:access_rights] = Lockdown::System.access_rights_for_user(user)
        session[:current_user_id] = user.id
      end
    end

    def logged_in?
      current_user_id.to_i > 0
    end

    def current_user_id
      session[:current_user_id]
    end

    def current_user_is_admin?
      session[:access_rights] == :all
    end

    def current_user_access_in_group?(grp)
      return true if current_user_is_admin?
        Lockdown::System.user_groups[grp].each do |perm|
          return true if access_in_perm?(perm)
        end
      false
    end

    def access_in_perm?(perm)
      if Lockdown::System.permissions[perm]
        Lockdown::System.permissions[perm].each do |ar|
          return true if session_access_rights_include?(ar)
        end 
      end
      false
    end

    def session_access_rights_include?(str)
      return false unless session[:access_rights]
      session[:access_rights].include?(str)
    end

    def reset_lockdown_session
      [:expiry_time, :current_user_id, :access_rights].each do |val|
        session[val] = nil if session[val]
      end
    end 

    alias_method :nil_lockdown_values, :reset_lockdown_session
  end # Session
end # Lockdown

Version data entries

33 entries across 33 versions & 5 rubygems

Version Path
andrewzielinski-lockdown-0.9.6 lib/lockdown/session.rb
blaxter-lockdown-0.9.8.99 lib/lockdown/session.rb
blaxter-lockdown-0.9.9 lib/lockdown/session.rb
hone-lockdown-1.2.1 lib/lockdown/session.rb
hone-lockdown-1.2.2 lib/lockdown/session.rb
hone-lockdown-1.2.3 lib/lockdown/session.rb
revo-lockdown-0.9.6 lib/lockdown/session.rb
lockdown-1.5.1 lib/lockdown/session.rb
lockdown-1.5.0 lib/lockdown/session.rb
lockdown-1.3.2 lib/lockdown/session.rb
lockdown-1.3.1 lib/lockdown/session.rb
lockdown-1.3.0 lib/lockdown/session.rb
lockdown-1.2.1 lib/lockdown/session.rb
lockdown-1.2.2 lib/lockdown/session.rb
lockdown-1.2.0 lib/lockdown/session.rb
lockdown-1.1.5 lib/lockdown/session.rb
lockdown-1.1.6 lib/lockdown/session.rb
lockdown-1.1.3 lib/lockdown/session.rb
lockdown-1.0.0 lib/lockdown/session.rb
lockdown-1.0.1 lib/lockdown/session.rb