Class: BBMB::Html::Util::KnownUser

Inherits:
SBSM::User
  • Object
show all
Defined in:
lib/bbmb/html/util/known_user.rb

Constant Summary collapse

PREFERENCE_KEYS =
[ :home, :pagestep ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth_session) ⇒ KnownUser

Returns a new instance of KnownUser.



20
21
22
# File 'lib/bbmb/html/util/known_user.rb', line 20

def initialize(auth_session)
  @auth_session = auth_session
end

Instance Attribute Details

#auth_sessionObject (readonly)

Admin users need permissions for: login BBMB.config.auth_domain + “.Admin” edit yus.entities set_password grant login

Customers need permissions for: login BBMB.config.auth_domain + “.Customer”



18
19
20
# File 'lib/bbmb/html/util/known_user.rb', line 18

def auth_session
  @auth_session
end

Instance Method Details

#allowed?(action, key = nil) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bbmb/html/util/known_user.rb', line 23

def allowed?(action, key=nil)
  if @auth_session
    return @auth_session.allowed?(action, key)
    return @auth_session.remote_call(:allowed?, action, key)
  end
  SBSM.debug('User ' + sprintf('allowed?(%s, %s)', action, key))
  return true
rescue => error
  puts error
  puts error.backtrace.join("\n")
end

#entity_valid?(email) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/bbmb/html/util/known_user.rb', line 34

def entity_valid?(email)
  !!(@auth_session.allowed?('edit', 'yus.entities') \
    && (entity = @auth_session.find_entity(email)) && entity.valid?)
end

#get_preference(key) ⇒ Object



41
42
43
44
# File 'lib/bbmb/html/util/known_user.rb', line 41

def get_preference(key)
  return @auth_session.get_preference(key.to_s)
  remote_call(:get_preference, key)
end


38
39
40
# File 'lib/bbmb/html/util/known_user.rb', line 38

def navigation
  [ :logout ]
end

#remote_call(method, *args, &block) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/bbmb/html/util/known_user.rb', line 45

def remote_call(method, *args, &block)
  SBSM.debug("remote_call #{method} args #{args} block.nil? #{block.nil?}")
  if defined?(@auth_session) && @auth_session.is_a?(DRb::DRbObject)
    return @auth_session.send(method, *args, &block)
  else
    return false
    return super(method, *args, &block)
  end
rescue RangeError, DRb::DRbError => e
  SBSM.info('auth') { e }
rescue error
  puts error
  puts error.backtrace.join("\n")
end