summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorPavel Zuna <pzuna@redhat.com>2010-11-23 09:14:03 -0500
committerAdam Young <ayoung@redhat.com>2010-11-23 21:32:12 -0500
commit9120155daeeee8287115a09f280f0e4f075f96df (patch)
tree750face4b0d32b652e1683038f1dc89e52f1aa6c /ipalib
parent5060fdfade63f299bf3ad15c16a1aff06135b80f (diff)
downloadfreeipa-9120155daeeee8287115a09f280f0e4f075f96df.tar.gz
freeipa-9120155daeeee8287115a09f280f0e4f075f96df.tar.xz
freeipa-9120155daeeee8287115a09f280f0e4f075f96df.zip
Generate better DuplicateEntry error messages in LDAPCreate.
Ticket #530
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/plugins/baseldap.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index e0dcad44f..8f723b999 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -262,6 +262,16 @@ class LDAPObject(Object):
}
)
+ def handle_duplicate_entry(self, *keys):
+ pkey = ''
+ if self.primary_key:
+ pkey = keys[-1]
+ raise errors.DuplicateEntry(
+ message=self.already_exists_msg % {
+ 'pkey': pkey, 'oname': self.object_name,
+ }
+ )
+
# list of attributes we want exported to JSON
json_friendly_attributes = (
'parent_object', 'container_dn', 'object_name', 'object_name_plural',
@@ -408,12 +418,7 @@ class LDAPCreate(CallbackInterface, crud.Create):
dn = self.obj.get_dn(*keys, **options)
if self.obj.rdn_attribute:
if not dn.startswith('%s=' % self.obj.primary_key.name):
- raise errors.DuplicateEntry(
- message=self.obj.already_exists_msg % {
- 'oname': self.obj.object_name,
- 'pkey': keys[-1],
- }
- )
+ self.obj.handle_duplicate_entry(*keys)
dn = ldap.make_dn(
entry_attrs, self.obj.rdn_attribute, self.obj.container_dn
)
@@ -459,6 +464,8 @@ class LDAPCreate(CallbackInterface, crud.Create):
'container': self.obj.container_dn,
}
)
+ except errors.DuplicateEntry:
+ self.obj.handle_duplicate_entry(*keys)
try:
if self.obj.rdn_attribute: