google-code-export / ruby-activeldap

Automatically exported from code.google.com/p/ruby-activeldap
Other
1 stars 1 forks source link

Raised on modify_rdn_entry when rdn already exists #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi kou!
I would ask you replace this 'raise' by error message, like when you trying
create new record when rdn already exists

What steps will reproduce the problem?
1. Create model: org_unit.rb

---
class OrgUnit < ActiveLdap::Base
 ldap_mapping :dn_attribute => "ou", :prefix => "", :classes => ['top', 
'organizationalUnit']
end

---
2. Run console: script/console development
3. Generate records:
test_root   = OrgUnit.create("test_root")
test_child1 = OrgUnit.create(:ou => "test_child1", :parent => test_root)
test_child2 = OrgUnit.create(:ou => "test_child2", :parent => test_root)
3. Try to modify rdn of test_child1 to "test_child2"

What is the expected output? What do you see instead?

>> test_child1.modify_rdn_entry(test_child1.dn, "ou=test_child2", true, {})
ActiveLdap::LdapError::AlreadyExists: Already exists
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/adapter/ldap_ext.
rb:80:in
`assert_error_code'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/adapter/ldap.rb:1
81:in
`rescue in execute'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/adapter/ldap.rb:1
77:in
`execute'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/adapter/ldap.rb:1
65:in
`block in modify_rdn'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/adapter/base.rb:2
34:in
`block in modify_rdn'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/adapter/base.rb:2
66:in
`block in operation'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/timeout.rb:15:in
`call'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/timeout.rb:15:in
`alarm'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/adapter/base.rb:3
12:in
`with_timeout'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/adapter/base.rb:2
65:in
`operation'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/adapter/base.rb:2
33:in
`modify_rdn'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/adapter/ldap.rb:1
60:in
`modify_rdn'
 from
/usr/lib/ruby/gems/1.9.1/gems/activeldap-1.1.0/lib/active_ldap/operations.rb:540
:in
`modify_rdn_entry'
 from (irb):4
 from /usr/bin/irb:12:in `<main>'
>> test_child1.errors
=> #<ActiveRecord::Errors:0x8336018 @base=#<OrgUnit objectClass:<top,
organizationalUnit>, must:<objectClass, ou>, may:<...>, @errors={}>

---

>> test_child3 = OrgUnit.create(:ou => "test_child2", :parent => test_root)
=> #<OrgUnit objectClass:<top, organizationalUnit>, must:<objectClass, ou>,
may:<...>
>> test_child3.errors
=> #<ActiveRecord::Errors:0xa65d730 @base=#<OrgUnit objectClass:<top,
organizationalUnit>, must:<objectClass, ou>, may:<...>,
@errors={"dn"=>["%{fn} is duplicated: ou=test_child2,ou=test_root,dc=com"]}>

What version of the product are you using? On what operating system?

openldap 2.4.16 (hdb database)
ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux]
rubygems 1.3.4
ruby-ldap (0.9.9)
activeldap (1.1.0)

I hope it possible :)

Original issue reported on code.google.com by Alexey.Chebotar@gmail.com on 6 Aug 2009 at 5:47

GoogleCodeExporter commented 9 years ago
Should we support validate_on_rename?
ActiveLdap::Base#create updates errors because it uses validation mechanism.
(validate_on_create)

Original comment by kou...@gmail.com on 9 Aug 2009 at 2:48

GoogleCodeExporter commented 9 years ago
Maybe yes. In case support validate_on_rename Ruby/LDAP needs to be updated?
Maybe we can use validate_on_update mechanism?

Original comment by Alexey.Chebotar@gmail.com on 11 Aug 2009 at 7:25

GoogleCodeExporter commented 9 years ago
Hi kou, I found temporary solution for this problem :)
I have created global model with method rename_to(new_rdn):

  def rename_to(new_rdn)
    old_dn = self.dn
    old_rdn = self.id
    self.id = new_rdn
    if self.valid?
      self.id = old_rdn
      self.dn = old_dn
      self.modify_rdn_entry(self.dn, "#{self.dn_attribute}=#{new_rdn}", true, {})
      self.id = new_rdn
      self.dn = old_dn.gsub(old_rdn, new_rdn)
      self.reload
      return true
    else
      return false
    end
  end

Manipulation with dn needed for me, because of dynamic prefixes of records.

P.S.: Dynamic prefixes meaning: Rails models, includes static prefix 
"ou=domains",
but entries written in LDAP has other prefix, some like
"ou=users,dc=test.com,ou=domains". (I was changing dn during validation)
>> user = User.find("admin", :prefix => "ou=users,dc=test.com")
=> #<User objectClass:<User>, must:<uid>, may:<>
>> user.dn
=> "uid=admin,ou=users,dc=test.com,ou=domains,dc=...,dc=com"
>> user.id
=> "admin"
>> user.prefix
=> "ou=domains"
>> user.id = "test"
=> "test"
>> user.dn
=> "uid=test,ou=domains,dc=...,dc=com"

I think dn should be:
"uid=test,ou=users,dc=test.com,ou=domains,dc=...,dc=com"
but I'm not sure if it's will be correct.

Hope this will help you :)

Original comment by danger1...@gmail.com on 2 Sep 2009 at 4:15

GoogleCodeExporter commented 9 years ago
It is Alexey Chebotar :) 
Sorry. I was logged in with my old account :(

Original comment by danger1...@gmail.com on 2 Sep 2009 at 4:18

GoogleCodeExporter commented 9 years ago
Sorry for my late work. :<
I have modified code for it on my environment but it's not completed yet...

Original comment by kou...@gmail.com on 3 Sep 2009 at 11:07

GoogleCodeExporter commented 9 years ago
I've implemented "rename" in trunk.

  entry.id = "new-rdn-value"
  entry.save

But new_superior isn't implemented because Ruby/LDAP doesn't bind 
ldap_rename(). :<

Original comment by kou...@gmail.com on 21 Sep 2009 at 9:07

GoogleCodeExporter commented 9 years ago
Thanks for solving, I will try use this all as soon as possible.

And I will thinking about ldap_rename() for Ruby/LDAP :)

Original comment by Alexey.Chebotar@gmail.com on 21 Sep 2009 at 1:16