hobo-notify/deploy: add support for date/birthdate kinds (#22444)
This commit is contained in:
parent
98d2204b13
commit
8ef533d0e3
|
@ -390,12 +390,12 @@ PROFILE = {
|
|||
'name': 'country'
|
||||
},
|
||||
{
|
||||
'kind': 'string',
|
||||
'kind': 'birthdate',
|
||||
'description': '',
|
||||
'required': False,
|
||||
'user_visible': True,
|
||||
'label': 'Date de naissance',
|
||||
'disabled': True,
|
||||
'disabled': False,
|
||||
'user_editable': True,
|
||||
'asked_on_registration': False,
|
||||
'name': 'birthdate'
|
||||
|
@ -499,6 +499,7 @@ def test_process_notification_user_provision(pub):
|
|||
assert user.form_data['_first_name'] == 'John'
|
||||
assert user.form_data['_last_name'] == u'Doé'.encode('utf-8')
|
||||
assert user.form_data['_zipcode'] == '13400'
|
||||
assert user.form_data['_birthdate'] is None
|
||||
assert user.name_identifiers == ['a'*32]
|
||||
assert user.is_admin is False
|
||||
assert set(user.roles) == set(['12345', old_role.id])
|
||||
|
@ -516,6 +517,7 @@ def test_process_notification_user_provision(pub):
|
|||
u'last_name': u'Doe',
|
||||
u'email': u'john.doe@example.net',
|
||||
u'zipcode': u'13600',
|
||||
u'birthdate': u'2000-01-01',
|
||||
u'is_superuser': True,
|
||||
u'roles': [
|
||||
{
|
||||
|
@ -537,6 +539,7 @@ def test_process_notification_user_provision(pub):
|
|||
assert user.form_data['_first_name'] == 'John'
|
||||
assert user.form_data['_last_name'] == 'Doe'
|
||||
assert user.form_data['_zipcode'] == '13600'
|
||||
assert user.form_data['_birthdate'].tm_year == 2000
|
||||
assert user.name_identifiers == ['a'*32]
|
||||
assert user.is_admin is True
|
||||
assert set(user.roles) == set([old_role.id])
|
||||
|
|
|
@ -31,7 +31,7 @@ from qommon.ctl import Command, make_option
|
|||
from qommon.storage import atomic_write
|
||||
|
||||
from wcs.admin.settings import UserFieldsFormDef
|
||||
from wcs.fields import StringField, EmailField
|
||||
from wcs.fields import StringField, EmailField, DateField
|
||||
|
||||
|
||||
class NoChange(Exception):
|
||||
|
@ -212,11 +212,13 @@ class CmdCheckHobos(Command):
|
|||
for attribute in profile.get('fields', []):
|
||||
field_id = '_' + attribute['name']
|
||||
if not field_id in profile_fields:
|
||||
field_class, field_typename = StringField, 'string'
|
||||
field_class = StringField
|
||||
if attribute['kind'] == 'email':
|
||||
field_class, field_typename = EmailField, 'email'
|
||||
field_class = EmailField
|
||||
elif attribute['kind'] in ('date', 'birthdate'):
|
||||
field_class = DateField
|
||||
new_field = field_class(label=attribute['label'].encode('utf-8'),
|
||||
type=field_typename,
|
||||
type=field_class.key,
|
||||
varname=attribute['name'])
|
||||
new_field.id = field_id
|
||||
profile_fields[field_id] = new_field
|
||||
|
|
|
@ -22,6 +22,7 @@ from quixote import get_publisher
|
|||
from wcs.roles import Role
|
||||
from qommon.ctl import Command
|
||||
from qommon.publisher import get_cfg
|
||||
from wcs.admin.settings import UserFieldsFormDef
|
||||
from wcs.qommon.misc import json_encode_helper
|
||||
|
||||
|
||||
|
@ -163,6 +164,7 @@ class CmdHoboNotify(Command):
|
|||
|
||||
@classmethod
|
||||
def provision_user(cls, publisher, issuer, action, data, full=False):
|
||||
formdef = UserFieldsFormDef(publisher=publisher)
|
||||
User = publisher.user_class
|
||||
|
||||
if full:
|
||||
|
@ -183,10 +185,13 @@ class CmdHoboNotify(Command):
|
|||
else:
|
||||
user = User(uuid)
|
||||
user.form_data = user.form_data or {}
|
||||
for key in o:
|
||||
if key in ['uuid', 'roles']:
|
||||
for field in formdef.fields:
|
||||
if not field.id.startswith('_'):
|
||||
continue
|
||||
user.form_data['_%s' % key] = o[key]
|
||||
field_value = o.get(field.id[1:])
|
||||
if field_value and field.convert_value_from_anything:
|
||||
field_value = field.convert_value_from_anything(field_value)
|
||||
user.form_data[field.id] = field_value
|
||||
user.name_identifiers = [uuid]
|
||||
role_uuids = [role['uuid'] for role in o['roles']]
|
||||
# reset roles
|
||||
|
|
Loading…
Reference in New Issue