utils: fix mapping of user attributes
This commit is contained in:
parent
2ee9cc3a7d
commit
44d8bfb472
|
@ -117,18 +117,22 @@ def apply_user_info_mappings(user, user_info):
|
|||
logger = logging.getLogger(__name__)
|
||||
mappings = app_settings.user_info_mappings
|
||||
|
||||
save_user = False
|
||||
for attribute, mapping in mappings.iteritems():
|
||||
try:
|
||||
value = mapping_to_value(mapping, user_info)
|
||||
except (ValueError, KeyError, NotImplementedError) as e:
|
||||
logger.warning(u'auth_fc: cannot apply mapping %s <- %r: %s', attribute, mapping, e)
|
||||
continue
|
||||
if hasattr(user.attributes, attribute):
|
||||
if hasattr(user, attribute):
|
||||
save_user = True
|
||||
setattr(user, attribute, value)
|
||||
elif hasattr(user.attributes, attribute):
|
||||
if getattr(mapping, 'verified', False):
|
||||
setattr(user.verified_attributes, attribute, value)
|
||||
else:
|
||||
setattr(user.attributes, attribute, value)
|
||||
elif hasattr(user, 'attribute'):
|
||||
setattr(user, attribute, value)
|
||||
else:
|
||||
logger.warning(u'auth_fc: unknown attribut in user_info mapping: %s', attribute)
|
||||
if save_user:
|
||||
user.save()
|
||||
|
|
Loading…
Reference in New Issue