Retrieve ldap entry from user model
This commit is contained in:
		
							parent
							
								
									30fb9805e5
								
							
						
					
					
						commit
						678e80a25d
					
				| @ -70,6 +70,12 @@ class User < ApplicationRecord | |||||||
|               end |               end | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   def ldap_entry | ||||||
|  |     return @ldap_entry if defined?(@ldap_entry) | ||||||
|  |     ldap = LdapService.new | ||||||
|  |     @ldap_entry = ldap.fetch_users(uid: self.cn, ou: self.ou).first | ||||||
|  |   end | ||||||
|  | 
 | ||||||
|   def address |   def address | ||||||
|     "#{self.cn}@#{self.ou}" |     "#{self.cn}@#{self.ou}" | ||||||
|   end |   end | ||||||
|  | |||||||
| @ -43,7 +43,7 @@ class LdapService < ApplicationService | |||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     attributes = %w{dn cn uid mail admin} |     attributes = %w{dn cn uid mail admin} | ||||||
|     filter     = Net::LDAP::Filter.eq("uid", "*") |     filter     = Net::LDAP::Filter.eq("uid", args[:uid] || "*") | ||||||
| 
 | 
 | ||||||
|     entries = ldap_client.search(base: treebase, filter: filter, attributes: attributes) |     entries = ldap_client.search(base: treebase, filter: filter, attributes: attributes) | ||||||
|     entries.sort_by! { |e| e.cn[0] } |     entries.sort_by! { |e| e.cn[0] } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user