Support of user default email domain

This patch fixes the default domain functionality for user email(s).
This setting may be configured via:

ipa config-mod --emaildomain=example.com

Then, when user is added/modified and --mail option is passed,
the default domain is appended if the passed attribute does not
contain another domain already.

https://fedorahosted.org/freeipa/ticket/598
This commit is contained in:
Martin Kosek 2011-02-04 15:12:34 +01:00 committed by Rob Crittenden
parent 29706fb13b
commit 34efc7bc24

View File

@ -214,6 +214,22 @@ class user(LDAPObject):
),
)
def _normalize_email(self, email, config=None):
if not config:
config = self.backend.get_ipa_config()[1]
# check if default email domain should be added
if email and 'ipadefaultemaildomain' in config:
norm_email = []
for m in email:
if m.find('@') == -1:
norm_email.append(m + u'@' + config['ipadefaultemaildomain'][0])
else:
norm_email.append(m)
return norm_email
return email
api.register(user)
@ -275,6 +291,9 @@ class user_add(LDAPCreate):
raise errors.NotFound(reason=error_msg)
entry_attrs['gidnumber'] = group_attrs['gidnumber']
if 'mail' in entry_attrs:
entry_attrs['mail'] = self.obj._normalize_email(entry_attrs['mail'], config)
return dn
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
@ -308,6 +327,11 @@ class user_mod(LDAPUpdate):
msg_summary = _('Modified user "%(value)s"')
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
if 'mail' in entry_attrs:
entry_attrs['mail'] = self.obj._normalize_email(entry_attrs['mail'])
return dn
def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
if not 'nsaccountlock' in entry_attrs:
entry_attrs['nsaccountlock'] = [u'False']