Class: ODDB::YusUser

Inherits:
SBSM::KnownUser
  • Object
show all
Defined in:
src/model/user.rb

Constant Summary

PREFERENCE_KEYS =
[ :salutation, :name_first, :name_last, :address, 
:city, :plz, :company_name, :business_area, :phone, 
:poweruser_duration]

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (YusUser) initialize(yus_session)

A new instance of YusUser



61
62
63
# File 'src/model/user.rb', line 61

def initialize(yus_session)
  @yus_session = yus_session
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args, &block)



109
110
111
# File 'src/model/user.rb', line 109

def method_missing(method, *args, &block)
  remote_call(method, *args, &block) 
end

Instance Attribute Details

- (Object) yus_session (readonly)

Returns the value of attribute yus_session



60
61
62
# File 'src/model/user.rb', line 60

def yus_session
  @yus_session
end

Instance Method Details

- (Boolean) allowed?(action, key = nil)

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'src/model/user.rb', line 64

def allowed?(action, key=nil)
  result = case key.odba_instance
  when ActiveAgentCommon
    allowed?(action, key.sequence)
  when Company
    allowed?(action, key.pointer.to_yus_privilege)
  when Fachinfo
    allowed?(action, key.registrations.first)
  when PackageCommon
    allowed?(action, key.sequence)
  when RegistrationCommon
    allowed?(action, key.company) \
      || allowed?(action, key.pointer.to_yus_privilege)
  when SequenceCommon
    allowed?(action, key.registration)  
  else
    remote_call(:allowed?, action, key)
  end
  result
end

- (Boolean) creditable?(obj)

Returns:

  • (Boolean)


84
85
86
87
88
89
90
# File 'src/model/user.rb', line 84

def creditable?(obj)
  unless(obj.is_a?(String))
    klass = obj.class.to_s.split('::').last
    obj = "org.oddb.#{klass}"
  end
  allowed?('credit', obj)
end

- (Boolean) expired?

Returns:

  • (Boolean)


91
92
93
94
95
# File 'src/model/user.rb', line 91

def expired?
  !@yus_session.ping
rescue RangeError, DRb::DRbConnError, NoMethodError
  true
end

- (Object) fullname



96
97
98
# File 'src/model/user.rb', line 96

def fullname
  [name_first, name_last].join(' ')
end

- (Object) groups



104
105
106
107
108
# File 'src/model/user.rb', line 104

def groups
  remote_call(:entities).reject { |entity| 
    /@/u.match(entity.name)
  }
end

- (Object) model



99
100
101
102
103
# File 'src/model/user.rb', line 99

def model
  if(id = remote_call(:get_preference, 'association'))
    ODBA.cache.fetch(id, self)
  end
end

- (Object) name Also known as: email, unique_email



112
113
114
# File 'src/model/user.rb', line 112

def name
  remote_call(:name)
end

- (Object) remote_call(method, *args, &block)



117
118
119
120
121
# File 'src/model/user.rb', line 117

def remote_call(method, *args, &block)
  @yus_session.send(method, *args, &block)
rescue RangeError, DRb::DRbError => e
  warn e
end

- (Object) set_preferences(values)



122
123
124
125
126
127
# File 'src/model/user.rb', line 122

def set_preferences(values)
  (values.keys - PREFERENCE_KEYS).each { |key|
    values.delete(key)
  }
  remote_call(:set_preferences, values)
end