Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Commit

Permalink
* add ActiveLdap::Base#rename.
Browse files Browse the repository at this point in the history
  [#26774] Changing RDN attributetype value fails
  Reported by Marc Dequènes. Thanks!!!


git-svn-id: http://ruby-activeldap.googlecode.com/svn/trunk@1065 fd4f1387-ac19-0410-9179-05984c98faae
  • Loading branch information
koutou committed Aug 4, 2009
1 parent a90773c commit 778860a
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 27 deletions.
8 changes: 7 additions & 1 deletion lib/active_ldap/adapter/ldap.rb
Expand Up @@ -158,9 +158,15 @@ def modify(dn, entries, options={})

def modify_rdn(dn, new_rdn, delete_old_rdn, new_superior, options={})
super do |_dn, _new_rdn, _delete_old_rdn, _new_superior|
if _new_superior
raise NotImplemented.new(_("modify RDN with new superior"))
end
info = {
:name => "modify: RDN",
:dn => _dn, :new_rdn => _new_rdn, :delete_old_rdn => _delete_old_rdn
:dn => _dn,
:new_rdn => _new_rdn,
:new_superior => _new_superior,
:delete_old_rdn => _delete_old_rdn
}
execute(:modrdn, info, _dn, _new_rdn, _delete_old_rdn)
end
Expand Down
22 changes: 22 additions & 0 deletions lib/active_ldap/base.rb
Expand Up @@ -259,6 +259,14 @@ def initialize(attribute, value, message)
end
end

class NotImplemented < Error
attr_reader :target
def initialize(target)
@target = target
super(_("not implemented: %s") % @target)
end
end

# Base
#
# Base is the primary class which contains all of the core
Expand Down Expand Up @@ -792,6 +800,20 @@ def save!
end
end

# Renames RDN and reload the entry.
def rename(new_rdn, new_superior=nil)
begin
new_rdn = DN.parse(new_rdn) unless new_rdn.is_a?(DN)
rescue DistinguishedNameInvalid
new_rdn = DN.parse("#{dn_attribute}=#{new_rdn}")
end
new_rdn = DN.new(new_rdn.rdns[0]).to_s
modify_rdn_entry(dn, new_rdn, false, new_superior)
self.id = new_rdn
self.base = new_superior if new_superior
reload
end

# method_missing
#
# If a given method matches an attribute or an attribute alias
Expand Down
32 changes: 20 additions & 12 deletions po/en/active-ldap.po
Expand Up @@ -6,7 +6,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Ruby/ActiveLdap 1.1.1\n"
"POT-Creation-Date: 2009-08-04 22:43+0900\n"
"POT-Creation-Date: 2009-08-04 23:26+0900\n"
"PO-Revision-Date: 2009-02-25 08:40+0900\n"
"Last-Translator: Kouhei Sutou <kou@cozmixng.org>\n"
"Language-Team: English\n"
Expand Down Expand Up @@ -3440,17 +3440,17 @@ msgstr ""
msgid "Can't remove required objectClass: %s"
msgstr ""

#: lib/active_ldap/adapter/jndi.rb:105 lib/active_ldap/adapter/ldap.rb:197
#: lib/active_ldap/adapter/jndi.rb:105 lib/active_ldap/adapter/ldap.rb:203
#: lib/active_ldap/adapter/net_ldap.rb:155
msgid "%s is not one of the available connect methods: %s"
msgstr ""

#: lib/active_ldap/adapter/jndi.rb:118 lib/active_ldap/adapter/ldap.rb:210
#: lib/active_ldap/adapter/jndi.rb:118 lib/active_ldap/adapter/ldap.rb:216
#: lib/active_ldap/adapter/net_ldap.rb:168
msgid "%s is not one of the available LDAP scope: %s"
msgstr ""

#: lib/active_ldap/adapter/jndi.rb:176 lib/active_ldap/adapter/ldap.rb:274
#: lib/active_ldap/adapter/jndi.rb:176 lib/active_ldap/adapter/ldap.rb:280
#: lib/active_ldap/adapter/net_ldap.rb:290
msgid "unknown type: %s"
msgstr ""
Expand All @@ -3459,6 +3459,10 @@ msgstr ""
msgid "No matches: filter: %s: attributes: %s"
msgstr ""

#: lib/active_ldap/adapter/ldap.rb:162
msgid "modify RDN with new superior"
msgstr ""

#: lib/active_ldap/adapter/net_ldap.rb:211
msgid "unsupported qops: %s"
msgstr ""
Expand Down Expand Up @@ -3793,39 +3797,43 @@ msgstr ""
msgid "%s is unknown attribute"
msgstr ""

#: lib/active_ldap/base.rb:374
#: lib/active_ldap/base.rb:266
msgid "not implemented: %s"
msgstr ""

#: lib/active_ldap/base.rb:382
msgid ""
"ActiveLdap::Base.establish_connection has been deprecated since 1.1.0. "
"Please use ActiveLdap::Base.setup_connection instead."
msgstr ""

#: lib/active_ldap/base.rb:455
#: lib/active_ldap/base.rb:463
msgid "scope '%s' must be a Symbol"
msgstr ""

#: lib/active_ldap/base.rb:506
#: lib/active_ldap/base.rb:514
msgid "%s doesn't belong in a hierarchy descending from ActiveLdap"
msgstr ""

#: lib/active_ldap/base.rb:661
#: lib/active_ldap/base.rb:669
msgid ""
"'%s' must be either nil, DN value as ActiveLdap::DN, String or Array or "
"attributes as Hash"
msgstr ""

#: lib/active_ldap/base.rb:791
#: lib/active_ldap/base.rb:799
msgid "entry %s can't be saved"
msgstr ""

#: lib/active_ldap/base.rb:810 lib/active_ldap/base.rb:821
#: lib/active_ldap/base.rb:832 lib/active_ldap/base.rb:843
msgid "wrong number of arguments (%d for 1)"
msgstr ""

#: lib/active_ldap/base.rb:942
#: lib/active_ldap/base.rb:964
msgid "Can't find DN '%s' to reload"
msgstr ""

#: lib/active_ldap/base.rb:1347
#: lib/active_ldap/base.rb:1369
msgid "%s's DN attribute (%s) isn't set"
msgstr ""

Expand Down
34 changes: 21 additions & 13 deletions po/ja/active-ldap.po
Expand Up @@ -6,8 +6,8 @@
msgid ""
msgstr ""
"Project-Id-Version: Ruby/ActiveLdap 1.1.1\n"
"POT-Creation-Date: 2009-08-04 22:43+0900\n"
"PO-Revision-Date: 2009-08-04 22:45+0900\n"
"POT-Creation-Date: 2009-08-04 23:26+0900\n"
"PO-Revision-Date: 2009-08-04 23:28+0900\n"
"Last-Translator: Kouhei Sutou <kou@cozmixng.org>\n"
"Language-Team: Japanese\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -3449,17 +3449,17 @@ msgstr "LDAPサーバが知らないobjectClassです: %s"
msgid "Can't remove required objectClass: %s"
msgstr "必須のobjectClassは削除できません: %s"

#: lib/active_ldap/adapter/jndi.rb:105 lib/active_ldap/adapter/ldap.rb:197
#: lib/active_ldap/adapter/jndi.rb:105 lib/active_ldap/adapter/ldap.rb:203
#: lib/active_ldap/adapter/net_ldap.rb:155
msgid "%s is not one of the available connect methods: %s"
msgstr "%sは有効な接続方法ではありません: %s"

#: lib/active_ldap/adapter/jndi.rb:118 lib/active_ldap/adapter/ldap.rb:210
#: lib/active_ldap/adapter/jndi.rb:118 lib/active_ldap/adapter/ldap.rb:216
#: lib/active_ldap/adapter/net_ldap.rb:168
msgid "%s is not one of the available LDAP scope: %s"
msgstr "%sは有効なLDAPスコープではありません: %s"

#: lib/active_ldap/adapter/jndi.rb:176 lib/active_ldap/adapter/ldap.rb:274
#: lib/active_ldap/adapter/jndi.rb:176 lib/active_ldap/adapter/ldap.rb:280
#: lib/active_ldap/adapter/net_ldap.rb:290
msgid "unknown type: %s"
msgstr "未知の種類です: %s"
Expand All @@ -3468,6 +3468,10 @@ msgstr "未知の種類です: %s"
msgid "No matches: filter: %s: attributes: %s"
msgstr "マッチしませんでした: フィルタ: %s: 属性: %s"

#: lib/active_ldap/adapter/ldap.rb:162
msgid "modify RDN with new superior"
msgstr "異なるツリー上のRDNへ変更"

#: lib/active_ldap/adapter/net_ldap.rb:211
msgid "unsupported qops: %s"
msgstr "対応していないqopsです: %s"
Expand Down Expand Up @@ -3812,43 +3816,47 @@ msgstr "LDAPの設定が存在しない%sアダプタが指定しています"
msgid "%s is unknown attribute"
msgstr "%sは未知の属性です"

#: lib/active_ldap/base.rb:374
#: lib/active_ldap/base.rb:266
msgid "not implemented: %s"
msgstr "未実装です: %s"

#: lib/active_ldap/base.rb:382
msgid ""
"ActiveLdap::Base.establish_connection has been deprecated since 1.1.0. "
"Please use ActiveLdap::Base.setup_connection instead."
msgstr ""
"1.1.0からActiveLdap::Base.establish_connectionは非推奨になりました。代わりに"
"ActiveLdap::Base.setup_connectionを使ってください。"

#: lib/active_ldap/base.rb:455
#: lib/active_ldap/base.rb:463
msgid "scope '%s' must be a Symbol"
msgstr "スコープ'%s'はシンボルでなければいけません"

#: lib/active_ldap/base.rb:506
#: lib/active_ldap/base.rb:514
msgid "%s doesn't belong in a hierarchy descending from ActiveLdap"
msgstr "%sはActiveLdapの子孫ではありません。"

#: lib/active_ldap/base.rb:661
#: lib/active_ldap/base.rb:669
msgid ""
"'%s' must be either nil, DN value as ActiveLdap::DN, String or Array or "
"attributes as Hash"
msgstr ""
"'%s'はnil、ActiveLdap::DNあるいはStringによるDN、DNの配列、Hashによる属性のど"
"れかでなければいけません"

#: lib/active_ldap/base.rb:791
#: lib/active_ldap/base.rb:799
msgid "entry %s can't be saved"
msgstr "エントリ%sを保存できません"

#: lib/active_ldap/base.rb:810 lib/active_ldap/base.rb:821
#: lib/active_ldap/base.rb:832 lib/active_ldap/base.rb:843
msgid "wrong number of arguments (%d for 1)"
msgstr "引数の数が違います。(1つの引数なのに%d個指定しました)"

#: lib/active_ldap/base.rb:942
#: lib/active_ldap/base.rb:964
msgid "Can't find DN '%s' to reload"
msgstr "再読み込みするDN '%s'が見つかりません"

#: lib/active_ldap/base.rb:1347
#: lib/active_ldap/base.rb:1369
msgid "%s's DN attribute (%s) isn't set"
msgstr "%sのDN属性(%s)が設定されていません"

Expand Down
28 changes: 27 additions & 1 deletion test/test_base.rb
Expand Up @@ -6,6 +6,33 @@ class TestBase < Test::Unit::TestCase
include AlTestUtils

priority :must
def test_rename_with_superior
make_ou("sub,ou=users")
make_temporary_user(:simple => true) do |user,|
assert_raise(ActiveLdap::NotImplemented) do
user.rename("user2", "ou=sub,#{@user_class.base}")
end
end
end

def test_rename
make_temporary_user(:simple => true) do |user,|
assert_not_equal("user2", user.id)
assert_raise(ActiveLdap::EntryNotFound) do
@user_class.find("user2")
end
user.rename("user2")
assert_equal("user2", user.id)

found_user = nil
assert_nothing_raised do
found_user = @user_class.find("user2")
end
assert_equal("user2", found_user.id)
end
end

priority :normal
def test_operational_attributes
make_temporary_group do |group|
dn, attributes = @group_class.search(:attributes => ["*"])[0]
Expand All @@ -22,7 +49,6 @@ def test_operational_attributes
end
end

priority :normal
def test_destroy_mixed_tree_by_instance
make_ou("base")
_entry_class = entry_class("ou=base")
Expand Down

0 comments on commit 778860a

Please sign in to comment.