Class: ODDB::Html::Util::KnownUser

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

Constant Summary collapse

PREFERENCE_KEYS =
[ :address, :city, :name_first, :name_last, :plz,
:salutation,  ]
@@iconv =
Iconv.new('utf8', 'latin1')

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session) ⇒ KnownUser

Returns a new instance of KnownUser.



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

def initialize(session)
  @auth_session = session
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/oddb/html/util/known_user.rb', line 51

def remote_call(method, *args, &block)
  res = @auth_session.send(method, *args, &block)
  case res
  when String
    @@iconv.iconv res rescue res
  else
    res
  end
rescue RangeError, DRb::DRbError => e
  ODDB.logger.error('auth') { e }
end

Instance Attribute Details

#auth_sessionObject (readonly)

Returns the value of attribute auth_session.



11
12
13
# File 'lib/oddb/html/util/known_user.rb', line 11

def auth_session
  @auth_session
end

Instance Method Details

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

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/oddb/html/util/known_user.rb', line 23

def allowed?(action, key=nil)
  allowed = remote_call(:allowed?, action, key)
  ODDB.logger.debug('User') {
    sprintf('%s: allowed?(%s, %s) -> %s', name, action, key, allowed)
  }
  allowed
end

#emailObject



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

def email
  remote_call :name
end

#entity_valid?(email) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/oddb/html/util/known_user.rb', line 30

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


37
38
39
# File 'lib/oddb/html/util/known_user.rb', line 37

def navigation
  [ :logout ]
end

#remote_call(method, *args, &block) ⇒ Object Also known as: method_missing



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/oddb/html/util/known_user.rb', line 40

def remote_call(method, *args, &block)
  res = @auth_session.send(method, *args, &block)
  case res
  when String
    @@iconv.iconv res rescue res
  else
    res
  end
rescue RangeError, DRb::DRbError => e
  ODDB.logger.error('auth') { e }
end