[Ovirt-devel] [PATCH 3/4] Updated the account class.
Darryl L. Pierce
dpierce at redhat.com
Wed May 7 21:03:32 UTC 2008
---
wui/src/app/helpers/ldap_connection.rb | 18 ++++++++----------
wui/src/app/models/account.rb | 19 ++++++++++++++++++-
2 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/wui/src/app/helpers/ldap_connection.rb b/wui/src/app/helpers/ldap_connection.rb
index 53256fa..623c02a 100644
--- a/wui/src/app/helpers/ldap_connection.rb
+++ b/wui/src/app/helpers/ldap_connection.rb
@@ -21,16 +21,14 @@
# connections with an LDAP server.
#
class LDAPConnection
- @@hostname = nil
- @@port = 389
-
+ @@config = YAML.load(File.open("#{RAILS_ROOT}/config/ldap.yml"))
+
# Connects the LDAP server.
- def LDAPConnection.connect(
- base,
- hostname = LDAPConnection.hostname,
- port = LDAPConnection.port
- )
- ActiveLdap::Base.establish_connection(:host => hostname
+ def LDAPConnection.connect(base,host,port)
+
+ ActiveLdap::Base.establish_connection(:host => host,
+ :port => port,
+ :base => base) if LDAPConnection.connected? == false
end
# Returns whether a connection already exists to the LDAP server.
@@ -39,7 +37,7 @@ class LDAPConnection
end
# Disconnects from the LDAP server.
- def LDAPConnection.disconnected
+ def LDAPConnection.disconnect
ActiveLdap::Base.remove_connection if LDAPConnection.connected?
end
diff --git a/wui/src/app/models/account.rb b/wui/src/app/models/account.rb
index 94c3bb6..2664f18 100644
--- a/wui/src/app/models/account.rb
+++ b/wui/src/app/models/account.rb
@@ -20,5 +20,22 @@
# +Account+ represents a single user's account from the LDAP server.
#
class Account < ActiveLdap::Base
- ldap_mapping :dn_attribute => 'uid', :classes => ['person', 'posixAccount']
+ ldap_mapping :dn_attribute => 'cn', :prefix => 'ou=Users', :scope => :one
+
+ # +query+ returns the set of all accounts that contain the given search value.
+ #
+ # This API requires that a previous connection be made using
+ # +LDAPConnection.connect+.
+ #
+ def Account.query(value)
+
+ @users = Account.find(:all, value)
+
+ if block_given?
+ @users.each { |user| yield(user) }
+ end
+
+ return @users
+
+ end
end
--
1.5.4.1
More information about the ovirt-devel
mailing list