Sha256: 907d612b5df974717a23ce6e9bd79d5997227b24e5f10f8cc39be9dd156e8467

Contents?: true

Size: 1.67 KB

Versions: 9

Compression:

Stored size: 1.67 KB

Contents

class UcbRails::UserLdapService
  
  class << self
    
    def create_user_from_uid(uid)
      UcbRails.logger.debug "create_user_from_uid #{uid}"
      
      ldap_entry = UcbRails::LdapPerson::Finder.find_by_uid!(uid)
      create_user_from_ldap_entry(ldap_entry)
    end
    
    def create_user_from_ldap_entry(ldap_entry)
      UcbRails.logger.debug "create_user_from_ldap_entry #{ldap_entry.uid}"
      
      UcbRails::User.create! do |u|
        u.uid = ldap_entry.uid
        u.first_name = ldap_entry.first_name
        u.last_name = ldap_entry.last_name
        u.email = ldap_entry.email
        u.phone = ldap_entry.phone
      end
    end

    def update_user_from_uid(uid)
      UcbRails.logger.debug "update_user_from_uid #{uid}"
      
      ldap_entry = UcbRails::LdapPerson::Finder.find_by_uid!(uid)
      update_user_from_ldap_entry(ldap_entry)
    end

    def update_user_from_ldap_entry(ldap_entry)
      UcbRails.logger.debug "update_user_from_ldap_entry #{ldap_entry.uid}"
      
      UcbRails::User.find_by_uid!(ldap_entry.uid).tap do |user|
        user.first_name = ldap_entry.first_name
        user.last_name = ldap_entry.last_name
        user.email = ldap_entry.email
        user.phone = ldap_entry.phone
        user.save(validate: false)
      end
    end
    
    def create_or_update_user(uid)
      if user = UcbRails::User.find_by_uid(uid)
        update_user_from_uid(uid)
      else
        create_user_from_uid(uid)
      end
    end
    
    def create_or_update_user_from_entry(entry)
      if user = UcbRails::User.find_by_uid(entry.uid)
        update_user_from_ldap_entry(entry)
      else
        create_user_from_ldap_entry(entry)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ucb_rails-0.0.13 app/models/ucb_rails/user_ldap_service.rb
ucb_rails-0.0.12 app/models/ucb_rails/user_ldap_service.rb
ucb_rails-0.0.11 app/models/ucb_rails/user_ldap_service.rb
ucb_rails-0.0.10 app/models/ucb_rails/user_ldap_service.rb
ucb_rails-0.0.9 app/models/ucb_rails/user_ldap_service.rb
ucb_rails-0.0.8 app/models/ucb_rails/user_ldap_service.rb
ucb_rails-0.0.7 app/models/ucb_rails/user_ldap_service.rb
ucb_rails-0.0.6 app/models/ucb_rails/user_ldap_service.rb
ucb_rails-0.0.5 app/models/ucb_rails/user_ldap_service.rb