From 0edeb9b01d7fe11c8a00ab1a986ec7429b8aadbb Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Tue, 25 Sep 2012 06:20:49 -0400 Subject: Improve user addition to default group in user-add On adding new user, user-add tries to make it a member of default user group. This, however, can raise AlreadyGroupMember when the user is already member of this group due to automember rule or default group configured. This patch makes sure AlreadyGroupMember exception is caught in such cases. https://fedorahosted.org/freeipa/ticket/3097 --- ipalib/plugins/user.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'ipalib/plugins/user.py') diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py index e6eb0d9c..5d667dc9 100644 --- a/ipalib/plugins/user.py +++ b/ipalib/plugins/user.py @@ -538,7 +538,15 @@ class user_add(LDAPCreate): # add the user we just created into the default primary group def_primary_group = config.get('ipadefaultprimarygroup') group_dn = self.api.Object['group'].get_dn(def_primary_group) - ldap.add_entry_to_group(dn, group_dn) + + # if the user is already a member of default primary group, + # do not raise error + # this can happen if automember rule or default group is set + try: + ldap.add_entry_to_group(dn, group_dn) + except errors.AlreadyGroupMember: + pass + if self.api.env.wait_for_attr: newentry = wait_for_value(ldap, dn, 'memberOf', def_primary_group) entry_from_entry(entry_attrs, newentry) -- cgit