Class: UcbRailsUser::UserLdapService
- Inherits:
-
Object
- Object
- UcbRailsUser::UserLdapService
- Defined in:
- app/models/ucb_rails_user/user_ldap_service.rb
Class Method Summary collapse
- .create_or_update_user(uid) ⇒ Object
- .create_or_update_user_from_entry(entry) ⇒ Object
- .create_user_from_ldap_entry(ldap_entry) ⇒ Object
- .create_user_from_uid(uid) ⇒ Object
- .update_user_from_ldap_entry(ldap_entry) ⇒ Object
- .update_user_from_uid(uid) ⇒ Object
Class Method Details
.create_or_update_user(uid) ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/models/ucb_rails_user/user_ldap_service.rb', line 49 def create_or_update_user(uid) if user = UcbRailsUser.user_class.find_by_ldap_uid(uid) update_user_from_uid(uid) else create_user_from_uid(uid) end end |
.create_or_update_user_from_entry(entry) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/ucb_rails_user/user_ldap_service.rb', line 57 def create_or_update_user_from_entry(entry) # LDAP returns some values as Net::BER::BerIdentifiedString instances, and not # all DBs seem to handle that well (e.g. Oracle) - we might want to fix LDAP library # to smooth this over? if user = UcbRailsUser.user_class.find_by_ldap_uid(entry.uid.to_s) update_user_from_ldap_entry(entry) else create_user_from_ldap_entry(entry) end end |
.create_user_from_ldap_entry(ldap_entry) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/ucb_rails_user/user_ldap_service.rb', line 12 def create_user_from_ldap_entry(ldap_entry) UcbRailsUser.logger.debug "create_user_from_ldap_entry #{ldap_entry.uid}" UcbRailsUser.user_class.create! do |u| u.ldap_uid = ldap_entry.uid u.employee_id = ldap_entry.employee_id u.affiliate_id = ldap_entry.affiliate_id u.student_id = ldap_entry.student_id u.first_name = ldap_entry.first_name u.last_name = ldap_entry.last_name u.email = ldap_entry.email u.inactive_flag = ldap_entry.inactive end end |
.create_user_from_uid(uid) ⇒ Object
5 6 7 8 9 10 |
# File 'app/models/ucb_rails_user/user_ldap_service.rb', line 5 def create_user_from_uid(uid) UcbRailsUser.logger.debug "create_user_from_uid #{uid}" ldap_entry = UcbRailsUser::LdapPerson::Finder.find_by_uid!(uid) create_user_from_ldap_entry(ldap_entry) end |
.update_user_from_ldap_entry(ldap_entry) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/models/ucb_rails_user/user_ldap_service.rb', line 34 def update_user_from_ldap_entry(ldap_entry) UcbRailsUser.logger.debug "update_user_from_ldap_entry #{ldap_entry.uid}" UcbRailsUser.user_class.find_by_ldap_uid!(ldap_entry.uid).tap do |user| user.employee_id = ldap_entry.employee_id if user.respond_to?(:employee_id=) user.affiliate_id = ldap_entry.affiliate_id user.student_id = ldap_entry.student_id user.first_name = ldap_entry.first_name user.last_name = ldap_entry.last_name user.email = ldap_entry.email user.inactive_flag = ldap_entry.inactive user.save(validate: false) end end |
.update_user_from_uid(uid) ⇒ Object
27 28 29 30 31 32 |
# File 'app/models/ucb_rails_user/user_ldap_service.rb', line 27 def update_user_from_uid(uid) UcbRailsUser.logger.debug "update_user_from_uid #{uid}" ldap_entry = UcbRailsUser::LdapPerson::Finder.find_by_uid!(uid) update_user_from_ldap_entry(ldap_entry) end |