Class: UcbRailsUser::LdapPerson::Entry

Inherits:
Object
  • Object
show all
Includes:
ActiveAttr::Attributes, ActiveAttr::BasicModel, ActiveAttr::BlockInitialization, ActiveAttr::MassAssignment
Defined in:
app/models/ucb_rails_user/ldap_person/entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new_from_ldap_entry(ldap_entry) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/models/ucb_rails_user/ldap_person/entry.rb', line 43

def new_from_ldap_entry(ldap_entry)
  # the to_s calls are because the underlying LDAP library sometimes returns strings as instances
  # of Net::BER::BerIdentifiedString rather than String, and the Oracle DB library doesn't play
  # nicely with those (postgres and sqlite work fine)
  new(
    uid: ldap_entry.uid&.to_s,
    calnet_id: ldap_entry.berkeleyedukerberosprincipalstring.first&.to_s,
    employee_id: ldap_entry.attributes[:berkeleyeduucpathid]&.first&.to_s,
    student_id: ldap_entry.berkeleyedustuid&.to_s,
    first_name: ldap_entry.givenname.first&.to_s,
    last_name: ldap_entry.sn.first&.to_s,
    email: ldap_entry.mail.first&.to_s,
    alternate_email: ldap_entry.attributes[:berkeleyeduofficialemail]&.first&.to_s,
    phone: ldap_entry.phone&.to_s,
    departments: ldap_entry.berkeleyeduunithrdeptname&.to_s,
    affiliations: ldap_entry.berkeleyeduaffiliations&.map(&:to_s),
    affiliate_id: ldap_entry.berkeleyeduaffid.first&.to_s,
    inactive: ldap_entry.expired? || false
  )
end

Instance Method Details

#==(other) ⇒ Object

Currently only used in rspec



37
38
39
# File 'app/models/ucb_rails_user/ldap_person/entry.rb', line 37

def ==(other)
  uid == other.uid
end

#full_nameObject



24
25
26
# File 'app/models/ucb_rails_user/ldap_person/entry.rb', line 24

def full_name
  "#{first_name()} #{last_name()}"
end

#last_firstObject



28
29
30
# File 'app/models/ucb_rails_user/ldap_person/entry.rb', line 28

def last_first
  "#{last_name}, #{first_name}"
end

#last_first_downcaseObject



32
33
34
# File 'app/models/ucb_rails_user/ldap_person/entry.rb', line 32

def last_first_downcase
  last_first.downcase
end