mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Improve netgroup-add error messages
These two situations in netgroup-add need to be distinguished:
1) Netgroup cannot be added because a hostgroup with the same name
created a colliding managed netgroup
2) Another native netgroup with the same name exists
This patch checks the colliding netgroup and raise appropriate
error message based on this finding.
https://fedorahosted.org/freeipa/ticket/2069
This commit is contained in:
@@ -143,13 +143,20 @@ class netgroup_add(LDAPCreate):
|
||||
|
||||
has_output_params = LDAPCreate.has_output_params + output_params
|
||||
msg_summary = _('Added netgroup "%(value)s"')
|
||||
|
||||
msg_collision = _(u'hostgroup with name "%s" already exists. ' \
|
||||
u'Hostgroups and netgroups share a common namespace')
|
||||
|
||||
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
||||
entry_attrs.setdefault('nisdomainname', self.api.env.domain)
|
||||
|
||||
try:
|
||||
# check duplicity with netgroups first to provide proper error
|
||||
netgroup = api.Command['netgroup_show'](keys[-1])
|
||||
self.obj.handle_duplicate_entry(*keys)
|
||||
dn = self.obj.get_dn(keys[-1])
|
||||
(dn_, netgroup) = ldap.get_entry(dn, ['objectclass'])
|
||||
if 'mepManagedEntry' in netgroup.get('objectclass', []):
|
||||
raise errors.DuplicateEntry(message=unicode(self.msg_collision % keys[-1]))
|
||||
else:
|
||||
self.obj.handle_duplicate_entry(*keys)
|
||||
except errors.NotFound:
|
||||
pass
|
||||
|
||||
@@ -158,10 +165,7 @@ class netgroup_add(LDAPCreate):
|
||||
# make sure that we don't create a collision if the plugin is
|
||||
# (temporarily) disabled
|
||||
netgroup = api.Command['hostgroup_show'](keys[-1])
|
||||
raise errors.DuplicateEntry(message=unicode(_(\
|
||||
u'hostgroup with name "%s" already exists. ' \
|
||||
u'Hostgroups and netgroups share a common namespace'\
|
||||
) % keys[-1]))
|
||||
raise errors.DuplicateEntry(message=unicode(self.msg_collision % keys[-1]))
|
||||
except errors.NotFound:
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user