From daniel at pfile.net Fri Dec 1 18:24:08 2006 From: daniel at pfile.net (Daniel Pfile) Date: Fri, 01 Dec 2006 17:24:08 -0600 Subject: [Ruby-activeldap-discuss] Is it possible for belongs_to to have a :foreign_key => "dn" ? Message-ID: <4570B998.8010404@pfile.net> Lots of the objects in our directory (Fedora) use the dn to refer to other objects. It's the standard way fedora creates groups, and we've also used it in other custom objects. In all your example code it looks like you assume the directory will use other attributes. Example entries: dn: uid=pfiled,ou=Admins,ou=People,dc=iip cn: Daniel Pfile sn: Pfile objectClass: top objectClass: person objectClass: organizationalPerson objectClass: inetorgpersongiven Name: Daniel uid: pfiled mail: pfiled at example.com dn: cn=AdminUtils,ou=Groups,dc=iip uniqueMember: uid=pfiled, ou=Admins,ou=People, dc=iip objectClass: groupOfUniqueNames objectClass: top description: Access to admin tools cn: AdminUtils Example code: class Group < ActiveLdap::Base ldap_mapping :dn_attribute => 'cn', :prefix => 'ou=Groups' end class User < ActiveLdap::Base ldap_mapping :dn_attribute => 'uid', :prefix => 'ou=People' belongs_to :groups, :class => 'Group', :many => "uniqueMember", :foreign_key => "dn" end me = User.find('pfiled') p me.cn # works p me.dn # works me.groups.each { |group| p group.cn } # blows up With some debug logging on gets me: -- snip -- DEBUG activeldap: stub: called get_attribute("dn", true DEBUG activeldap: stub: called get_attribute_before_type_cast("dn", true DEBUG activeldap: Ignore error LDAP::ProtocolError(Protocol error) for (|) and attrs [] -- snip -- It looks like the dn is never stored in @data, so the only way to get it is with base.dn(), that of course doesn't work for the belongs_to method. So, is there a way to get the dn to use as a :foreign_key? Fedora directory server also has values like entrydn (has the dn in it), modifiersname, nsuniqueid, modifytimestamp, etc, but they're hidden. I'm not sure how to tell the class to map these extra attributes. Otherwise, is there a way to extend the appropriate class to put the dn into @data for use by associations as something like @data['realdn']? I've poured through the code, but I'm stumped. Thanks for your patience, Daniel Pfile From kou at cozmixng.org Sun Dec 3 07:50:15 2006 From: kou at cozmixng.org (Kouhei Sutou) Date: Sun, 03 Dec 2006 21:50:15 +0900 (JST) Subject: [Ruby-activeldap-discuss] Is it possible for belongs_to to have a :foreign_key => "dn" ? In-Reply-To: <4570B998.8010404@pfile.net> References: <4570B998.8010404@pfile.net> Message-ID: <20061203.215015.32750585.kou@cozmixng.org> Hi, In <4570B998.8010404 at pfile.net> "[Ruby-activeldap-discuss] Is it possible for belongs_to to have a :foreign_key => "dn" ?" on Fri, 01 Dec 2006 17:24:08 -0600, Daniel Pfile wrote: > It looks like the dn is never stored in @data, so the only way to get it > is with base.dn(), that of course doesn't work for the belongs_to method. Does the attached patch solve your problem? Thanks -- kou -------------- next part -------------- Index: test/test_base.rb =================================================================== --- test/test_base.rb (revision 98) +++ test/test_base.rb (working copy) @@ -4,6 +4,13 @@ include AlTestUtils priority :must + def test_dn_by_index_getter + make_temporary_user do |user,| + assert_equal(user.dn, user["dn"]) + end + end + + priority :normal def test_create_multiple ensure_delete_user("temp-user1") do |uid1,| ensure_delete_user("temp-user2") do |uid2,| @@ -52,7 +59,6 @@ end end - priority :normal def test_reload_of_not_exists_entry make_temporary_user do |user,| assert_nothing_raised do Index: lib/active_ldap/base.rb =================================================================== --- lib/active_ldap/base.rb (revision 98) +++ lib/active_ldap/base.rb (working copy) @@ -916,7 +916,11 @@ end def [](name, force_array=false) - get_attribute(name, force_array) + if name == "dn" + array_of(dn, force_array) + else + get_attribute(name, force_array) + end end def []=(name, value) From petr at punchyouremployer.com Mon Dec 4 18:42:03 2006 From: petr at punchyouremployer.com (Petr Janda) Date: Tue, 5 Dec 2006 10:42:03 +1100 Subject: [Ruby-activeldap-discuss] Unable to set aRecord or any dNSDomain attributes Message-ID: <200612051042.04024.petr@punchyouremployer.com> Im running 0.8 and Im running into a trouble. This is the output of the script porncatalog# ruby available_attrs.rb physicalDeliveryOfficeName destinationIndicator telexNumber st l businessCategory telephoneNumber postalAddress searchGuide domainComponent preferredDeliveryMethod internationaliSDNNumber o sOARecord nSRecord teletexTerminalIdentifier postalCode streetAddress userPassword description associatedName mXRecord registeredAddress fax street localityName aRecord objectClass facsimileTelephoneNumber postOfficeBox stateOrProvinceName seeAlso organizationName mDRecord cNAMERecord dc x121Address ldaptest.rb porncatalog# less ldaptest.rb require 'rubygems' require 'active_ldap' ActiveLdap::Base.establish_connection( :host => '127.0.0.1', :base => 'dc=webgate,dc=net,dc=au', :bind_dn => "cn=Manager,dc=webgate,dc=net,dc=au", :password_block => Proc.new { 'mogul351' }, :allow_anonymous => false ) class Domain < ActiveLdap::Base ldap_mapping :dn_attribute => "dc", :prefix => "ou=domains", :classes => ['top', 'dcObject', 'dNSDomain'] end domain = Domain.new('ftp') domain.aRecord = "192.168.1.1" domain.save However the aRecord doesnt get set although the object 'ftp' is created without any error. Please help, Petr From kou at cozmixng.org Mon Dec 4 19:40:23 2006 From: kou at cozmixng.org (Kouhei Sutou) Date: Tue, 5 Dec 2006 09:40:23 +0900 Subject: [Ruby-activeldap-discuss] Unable to set aRecord or any dNSDomain attributes In-Reply-To: <200612051042.04024.petr@punchyouremployer.com> References: <200612051042.04024.petr@punchyouremployer.com> Message-ID: Hi, 2006/12/5, Petr Janda : > porncatalog# ruby available_attrs.rb available_attrs.rb? > domain.aRecord = "192.168.1.1" > domain.save > > > However the aRecord doesnt get set although the object 'ftp' is created > without any error. Is 'ftp' really created? What you want to use may be #save! instead of #save. Or: unless domain.save puts "failed" puts domain.errors.full_messages end ActiveLdap has same inteface of ActiveRecord for #save. Thanks, -- kou From kou at cozmixng.org Mon Dec 4 20:38:40 2006 From: kou at cozmixng.org (Kouhei Sutou) Date: Tue, 5 Dec 2006 10:38:40 +0900 Subject: [Ruby-activeldap-discuss] Is it possible for belongs_to to have a :foreign_key => "dn" ? In-Reply-To: <4574C7E9.1030000@pfile.net> References: <4570B998.8010404@pfile.net> <20061203.215015.32750585.kou@cozmixng.org> <4574C7E9.1030000@pfile.net> Message-ID: Hi, 2006/12/5, Daniel Pfile : > Kouhei Sutou wrote: > > Does the attached patch solve your problem? > I just got a chance to test it and I'm happy to say it does. OK. I've committed the patch. Thanks, -- kou From petr at punchyouremployer.com Tue Dec 5 02:14:16 2006 From: petr at punchyouremployer.com (Petr Janda) Date: Tue, 5 Dec 2006 18:14:16 +1100 Subject: [Ruby-activeldap-discuss] Unable to set aRecord or any dNSDomain attributes In-Reply-To: References: <200612051042.04024.petr@punchyouremployer.com> Message-ID: <200612051814.16195.petr@punchyouremployer.com> Hey, On Tuesday 05 December 2006 11:39, you wrote: > Hi, > > 2006/12/5, Petr Janda : > > porncatalog# ruby available_attrs.rb > > available_attrs.rb? Thats just a script that tells me availale attribute_names > > > domain.aRecord = "192.168.1.1" > > domain.save > > > > > > However the aRecord doesnt get set although the object 'ftp' is created > > without any error. > > Is 'ftp' really created? > > What you want to use may be #save! instead of #save. Or: > > unless domain.save > puts "failed" > puts domain.errors.full_messages > end > > ActiveLdap has same inteface of ActiveRecord for #save. > > > Thanks, > -- > kou > > !DSPAM:10,4574bfe6915881895411524! No go, ftp record gets created, but no aRecord attribute set. Not even if i try to edit the object later on. porncatalog# ldapsearch -x -h 192.168.1.40 -W -D 'cn=Manager,dc=webgate,dc=net,dc=au' -b 'dc=webgate,dc=net,dc=au' '(dc=ftp)' Enter LDAP Password: # extended LDIF # # LDAPv3 # base with scope subtree # filter: (dc=ftp) # requesting: ALL # # ftp, domains, webgate.net.au dn: dc=ftp,ou=domains,dc=webgate,dc=net,dc=au dc: ftp objectClass: top objectClass: dcObject objectClass: dNSDomain # search result search: 2 result: 0 Success # numResponses: 2 # numEntries: 1 Also, as you notice, the ftp record gets created in ou=domains (because :prefix => 'ou=domains' in ldap_mapping). How do you set it to/at the moment of creation/ to actually be saved to dc=lemra,dc=com,ou=domains without changing the :prefix in ldap_mapping? Cheers, Petr From kou at cozmixng.org Tue Dec 5 07:45:06 2006 From: kou at cozmixng.org (Kouhei Sutou) Date: Tue, 05 Dec 2006 21:45:06 +0900 (JST) Subject: [Ruby-activeldap-discuss] Unable to set aRecord or any dNSDomain attributes In-Reply-To: <200612051814.16195.petr@punchyouremployer.com> References: <200612051042.04024.petr@punchyouremployer.com> <200612051814.16195.petr@punchyouremployer.com> Message-ID: <20061205.214506.34097807.kou@cozmixng.org> Hi, In <200612051814.16195.petr at punchyouremployer.com> "Re: [Ruby-activeldap-discuss] Unable to set aRecord or any dNSDomain attributes" on Tue, 5 Dec 2006 18:14:16 +1100, Petr Janda wrote: > No go, ftp record gets created, but no aRecord attribute set. Not even if i > try to edit the object later on. Does the attached patch solve your problem? > Also, as you notice, the ftp record gets created in ou=domains > (because :prefix => 'ou=domains' in ldap_mapping). How do you set it to/at > the moment of creation/ to actually be saved to dc=lemra,dc=com,ou=domains > without changing the :prefix in ldap_mapping? domain.dn = "dc=ftp,dc=lemra,dc=com" Thanks, -- kou -------------- next part -------------- Index: test/test_base.rb =================================================================== --- test/test_base.rb (revision 99) +++ test/test_base.rb (working copy) @@ -4,13 +4,29 @@ include AlTestUtils priority :must + def test_save_for_dNSDomain + domain_class = Class.new(ActiveLdap::Base) + domain_class.ldap_mapping :dn_attribute => "dc", :prefix => "", + :classes => ['top', 'dcObject', 'dNSDomain'] + name = "ftp" + a_record = "192.168.1.1" + + domain = domain_class.new('ftp') + domain.a_record = a_record + assert(domain.save) + assert_equal(a_record, domain.a_record) + assert_equal(a_record, domain_class.find(name).a_record) + ensure + domain_class.delete(name) if domain_class.exists?(name) + end + + priority :normal def test_dn_by_index_getter make_temporary_user do |user,| assert_equal(user.dn, user["dn"]) end end - priority :normal def test_create_multiple ensure_delete_user("temp-user1") do |uid1,| ensure_delete_user("temp-user2") do |uid2,| Index: lib/active_ldap/base.rb =================================================================== --- lib/active_ldap/base.rb (revision 99) +++ lib/active_ldap/base.rb (working copy) @@ -1037,14 +1037,20 @@ @musts[objc] = attributes[:must] @mays[objc] = attributes[:may] end - @must = @musts.values.flatten.uniq - @may = @mays.values.flatten.uniq + @must = normalize_attribute_names(@musts.values) + @may = normalize_attribute_names(@mays.values) (@must + @may).uniq.each do |attr| # Update attr_method with appropriate define_attribute_methods(attr) end end + def normalize_attribute_names(names) + names.flatten.uniq.collect do |may| + schema.attribute_aliases(may).first + end + end + alias_method :base_of_class, :base def base logger.debug {"stub: called base"} @@ -1143,8 +1149,7 @@ def define_attribute_methods(attr) logger.debug {"stub: called define_attribute_methods(#{attr.inspect})"} return if @attr_methods.has_key? attr - aliases = schema.attribute_aliases(attr) - aliases.each do |ali| + schema.attribute_aliases(attr).each do |ali| logger.debug {"associating #{ali} --> #{attr}"} @attr_methods[ali] = attr logger.debug {"associating #{Inflector.underscore(ali)}" + From petr at punchyouremployer.com Tue Dec 5 09:50:13 2006 From: petr at punchyouremployer.com (Petr Janda) Date: Wed, 6 Dec 2006 01:50:13 +1100 Subject: [Ruby-activeldap-discuss] Unable to set aRecord or any dNSDomain attributes Message-ID: <200612060150.13531.petr@punchyouremployer.com> Hey, > Does the attached patch solve your problem? It sure does! Thanks a lot and please commit. Petr From kou at cozmixng.org Tue Dec 5 10:02:35 2006 From: kou at cozmixng.org (Kouhei Sutou) Date: Wed, 06 Dec 2006 00:02:35 +0900 (JST) Subject: [Ruby-activeldap-discuss] Unable to set aRecord or any dNSDomain attributes In-Reply-To: <200612060150.13531.petr@punchyouremployer.com> References: <200612060150.13531.petr@punchyouremployer.com> Message-ID: <20061206.000235.64563314.kou@cozmixng.org> Hi, In <200612060150.13531.petr at punchyouremployer.com> "[Ruby-activeldap-discuss] Unable to set aRecord or any dNSDomain attributes" on Wed, 6 Dec 2006 01:50:13 +1100, Petr Janda wrote: > > Does the attached patch solve your problem? > > It sure does! Thanks a lot and please commit. I've committed. Thanks, -- kou From petr at punchyouremployer.com Fri Dec 8 01:17:02 2006 From: petr at punchyouremployer.com (Petr Janda) Date: Fri, 8 Dec 2006 17:17:02 +1100 Subject: [Ruby-activeldap-discuss] How to form has_many and belongs_to relationship between LDAP and SQL? Message-ID: <200612081717.02287.petr@punchyouremployer.com> Hi, Is it possible to have a class Clients < ActiveRecord::Base having a has_many relationship with class Domains < ActiveLdap::Base and Domains belongs_to Clients? If so, can you give me an example please. Cheers, Petr From kou at cozmixng.org Fri Dec 8 01:55:54 2006 From: kou at cozmixng.org (Kouhei Sutou) Date: Fri, 8 Dec 2006 15:55:54 +0900 Subject: [Ruby-activeldap-discuss] How to form has_many and belongs_to relationship between LDAP and SQL? In-Reply-To: <200612081717.02287.petr@punchyouremployer.com> References: <200612081717.02287.petr@punchyouremployer.com> Message-ID: Hi, 2006/12/8, Petr Janda : > Is it possible to have a class Clients < ActiveRecord::Base having a has_many > relationship with class Domains < ActiveLdap::Base and Domains belongs_to > Clients? > > If so, can you give me an example please. examples/objects/{user,group}.rb may help you. Thanks, -- kou From petr at punchyouremployer.com Fri Dec 8 19:54:45 2006 From: petr at punchyouremployer.com (Petr Janda) Date: Sat, 9 Dec 2006 11:54:45 +1100 Subject: [Ruby-activeldap-discuss] How to form has_many and belongs_to relationship between LDAP and SQL? In-Reply-To: References: Message-ID: <200612091154.46004.petr@punchyouremployer.com> Hey, > examples/objects/{user,group}.rb may help you. Where do i find these? Petr From kou at cozmixng.org Fri Dec 8 22:09:09 2006 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 09 Dec 2006 12:09:09 +0900 (JST) Subject: [Ruby-activeldap-discuss] How to form has_many and belongs_to relationship between LDAP and SQL? In-Reply-To: <200612091154.46004.petr@punchyouremployer.com> References: <200612091154.46004.petr@punchyouremployer.com> Message-ID: <20061209.120909.49156009.kou@cozmixng.org> Hi, In <200612091154.46004.petr at punchyouremployer.com> "[Ruby-activeldap-discuss] How to form has_many and belongs_to relationship between LDAP and SQL?" on Sat, 9 Dec 2006 11:54:45 +1100, Petr Janda wrote: > > examples/objects/{user,group}.rb may help you. > > Where do i find these? http://ruby-activeldap.googlecode.com/svn/trunk/examples/ Thanks, -- kou From petr at punchyouremployer.com Fri Dec 8 22:56:23 2006 From: petr at punchyouremployer.com (Petr Janda) Date: Sat, 9 Dec 2006 14:56:23 +1100 Subject: [Ruby-activeldap-discuss] How to form has_many and belongs_to relationship between LDAP and SQL? In-Reply-To: <200612091154.46004.petr@punchyouremployer.com> References: <200612091154.46004.petr@punchyouremployer.com> Message-ID: <200612091456.23157.petr@punchyouremployer.com> Hey, I have this in my domain.rb class Domain < ActiveLdap::Base belongs_to :client, :many => "clientId", :foreign_key => "id" ldap_mapping :dn_attribute => "dc", :prefix => "ou=domains", :classes => ['top', 'dcObject', 'dNSDomain', 'webgateSchema'] end but I get error: " Unknown key(s): filter" when trying to do something like puts domain.client.name When I remove :many => "clientId", I get: "undefined method `dn_attribute' for Client:Class" Thanks, Petr From kou at cozmixng.org Fri Dec 8 23:35:46 2006 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 09 Dec 2006 13:35:46 +0900 (JST) Subject: [Ruby-activeldap-discuss] How to form has_many and belongs_to relationship between LDAP and SQL? In-Reply-To: <200612091456.23157.petr@punchyouremployer.com> References: <200612091154.46004.petr@punchyouremployer.com> <200612091456.23157.petr@punchyouremployer.com> Message-ID: <20061209.133546.12522651.kou@cozmixng.org> Hi, In <200612091456.23157.petr at punchyouremployer.com> "Re: [Ruby-activeldap-discuss] How to form has_many and belongs_to relationship between LDAP and SQL?" on Sat, 9 Dec 2006 14:56:23 +1100, Petr Janda wrote: > class Domain < ActiveLdap::Base > belongs_to :client, :many => "clientId", :foreign_key => "id" > ldap_mapping :dn_attribute => "dc", :prefix => "ou=domains", :classes > => ['top', 'dcObject', 'dNSDomain', 'webgateSchema'] > end > > > but I get error: > > " Unknown key(s): filter" when trying to do something like > > puts domain.client.name > > When I remove :many => "clientId", I get: > > "undefined method `dn_attribute' for Client:Class" Ah, you can't make relationships between ActiveLdap::Base and ActiveRecord::Base. # I was thinking that you have a typo in the previous # thread. Sorry. Thanks, -- kou From petr at punchyouremployer.com Sun Dec 10 03:34:50 2006 From: petr at punchyouremployer.com (Petr Janda) Date: Sun, 10 Dec 2006 19:34:50 +1100 Subject: [Ruby-activeldap-discuss] How do I set multiple values to an attribute? Message-ID: <200612101934.50166.petr@punchyouremployer.com> Hi, Im wondering how to set multiple values to an mXRecord or nSRecord attribute through openldap? Thanks, Petr From petr at punchyouremployer.com Sun Dec 10 03:35:48 2006 From: petr at punchyouremployer.com (Petr Janda) Date: Sun, 10 Dec 2006 19:35:48 +1100 Subject: [Ruby-activeldap-discuss] How do I set multiple values to an attribute? In-Reply-To: <200612101934.50166.petr@punchyouremployer.com> References: <200612101934.50166.petr@punchyouremployer.com> Message-ID: <200612101935.49038.petr@punchyouremployer.com> I meant "activeldap", sorry. Petr On Sunday 10 December 2006 19:34, you wrote: > Hi, > > Im wondering how to set multiple values to an mXRecord or nSRecord > attribute through openldap? > > Thanks, > > Petr From kou at cozmixng.org Sun Dec 10 04:04:33 2006 From: kou at cozmixng.org (Kouhei Sutou) Date: Sun, 10 Dec 2006 18:04:33 +0900 (JST) Subject: [Ruby-activeldap-discuss] How do I set multiple values to an attribute? In-Reply-To: <200612101934.50166.petr@punchyouremployer.com> References: <200612101934.50166.petr@punchyouremployer.com> Message-ID: <20061210.180433.95943917.kou@cozmixng.org> Hi, In <200612101934.50166.petr at punchyouremployer.com> "[Ruby-activeldap-discuss] How do I set multiple values to an attribute?" on Sun, 10 Dec 2006 19:34:50 +1100, Petr Janda wrote: > Im wondering how to set multiple values to an mXRecord or nSRecord attribute > through openldap? You just set value of the attributes as Array. object.mXRecord = ["XXX", "YYY", ...] Ah, do you want to set value as LDIF data by ldapadd/ldapmodify? So you just write entries for the attributes: ... mXRecord: XXX mXRecord: YYY mXRecord: ... ... Thanks, -- kou From kou at cozmixng.org Sat Dec 16 01:35:54 2006 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 16 Dec 2006 15:35:54 +0900 (JST) Subject: [Ruby-activeldap-discuss] notification e-mails for tracers on RubyForge Message-ID: <20061216.153554.125488780.kou@cozmixng.org> Hi Will, In current configuration of tracers on RubyForge, all notification e-mails will be sent you. It seems that you are still busy. So, I want to suggest that we make a new ML for tracers and change configuration of tracers to sent all notification e-mails to the ML. Any opinions? Thanks, -- kou