hobo: fix mapping of attributes (#7277)
This commit is contained in:
parent
bf1c8daf4a
commit
f46a9d5221
|
@ -251,3 +251,16 @@ def test_update_profile():
|
|||
hobo_cmd.update_profile(profile, pub)
|
||||
formdef = UserFieldsFormDef(pub)
|
||||
assert 'bool' in [x.label for x in formdef.fields]
|
||||
|
||||
# create a fake entry in idp to check attribute mapping
|
||||
pub.cfg['idp'] = {'xxx': {}}
|
||||
hobo_cmd.update_profile(profile, pub)
|
||||
|
||||
attribute_mapping = pub.cfg['idp']['xxx']['attribute-mapping']
|
||||
for field in profile.get('fields'):
|
||||
attribute_name = str(field['name'])
|
||||
field_id = str('_' + attribute_name)
|
||||
if field.get('disabled'):
|
||||
assert not attribute_name in attribute_mapping
|
||||
else:
|
||||
assert attribute_mapping[attribute_name] == field_id
|
||||
|
|
|
@ -107,9 +107,9 @@ class CmdCheckHobos(Command):
|
|||
def update_profile(self, profile, pub):
|
||||
formdef = UserFieldsFormDef(publisher=pub)
|
||||
profile_fields = {}
|
||||
profile_field_names = ['_' + x['name'] for x in profile.get('fields', [])]
|
||||
profile_field_ids = ['_' + x['name'] for x in profile.get('fields', [])]
|
||||
for field in formdef.fields:
|
||||
if field.id in profile_field_names:
|
||||
if field.id in profile_field_ids:
|
||||
profile_fields[field.id] = field
|
||||
|
||||
# create or update profile fields
|
||||
|
@ -133,10 +133,10 @@ class CmdCheckHobos(Command):
|
|||
profile_fields[field_id].required = attribute['required']
|
||||
|
||||
if attribute['disabled']:
|
||||
profile_field_names.remove('_' + attribute['name'])
|
||||
profile_field_ids.remove('_' + attribute['name'])
|
||||
|
||||
# insert profile fields at the beginning
|
||||
formdef.fields = [profile_fields[x] for x in profile_field_names] + formdef.fields
|
||||
formdef.fields = [profile_fields[x] for x in profile_field_ids] + formdef.fields
|
||||
formdef.store()
|
||||
|
||||
pub.cfg['users']['field_email'] = '_email'
|
||||
|
@ -147,8 +147,11 @@ class CmdCheckHobos(Command):
|
|||
for idp in pub.cfg.get('idp', {}).values():
|
||||
if not 'attribute-mapping' in idp:
|
||||
idp['attribute-mapping'] = {}
|
||||
for field_name in profile_field_names:
|
||||
idp['attribute-mapping'][str(field_name)] = '_' + str(field_name)
|
||||
for field in profile.get('fields', []):
|
||||
attribute_name = field['name']
|
||||
field_id = '_' + attribute_name
|
||||
if field_id in profile_field_ids:
|
||||
idp['attribute-mapping'][str(attribute_name)] = str(field_id)
|
||||
pub.write_cfg()
|
||||
|
||||
def configure_authentication_methods(self, service, pub):
|
||||
|
|
Loading…
Reference in New Issue