utils: add special case for mapping the User.password (fixes #24835)

The goal is to set a random password for new accounts,
so that they can recover it. In this case we use
the value {"compute": "random"}.
This commit is contained in:
Benjamin Dauvergne 2018-06-27 19:59:58 +02:00
parent 215c1f5abd
commit 186f3518d0
1 changed files with 9 additions and 1 deletions

View File

@ -76,6 +76,8 @@ def mapping_to_value(mapping, user_info):
elif 'compute' in mapping:
if mapping['compute'] == 'today':
value = datetime.date.today()
elif mapping['compute'] == 'random':
value = unicode(uuid.uuid4())
else:
raise NotImplementedError
@ -143,7 +145,13 @@ def apply_user_info_mappings(user, user_info):
continue
if mapping.get('if-tag') and mapping['if-tag'] not in tags:
continue
if hasattr(user, attribute):
if attribute == 'password':
if mapping.get('if-empty') and user.has_usable_password():
continue
save_user = True
user.set_password(value)
elif hasattr(user, attribute):
save_user = True
if mapping.get('if-empty') and getattr(user, attribute):
continue