api: fix case of boolean user's attributs (fixes #26113)
As NullBooleanField does not support the allow_null init attribute, we must special case it and remember to never use BooleanField.
This commit is contained in:
parent
da31b8a52d
commit
e1d73640b9
|
@ -339,7 +339,11 @@ class BaseUserSerializer(serializers.ModelSerializer):
|
|||
})
|
||||
if not at.required:
|
||||
# setting an attribute to null will delete it
|
||||
kwargs['allow_null'] = True
|
||||
# NullBooleanField and BooleanField does not support allow_null
|
||||
if field_class is serializers.BooleanField:
|
||||
field_class = serializers.NullBooleanField
|
||||
elif field_class is not serializers.NullBooleanField:
|
||||
kwargs['allow_null'] = True
|
||||
# if not stated otherwise by the definition of the kind, string alike fields
|
||||
# accept blank values when not required
|
||||
if (issubclass(field_class, serializers.CharField) and 'allow_blank' not in
|
||||
|
|
|
@ -151,6 +151,16 @@ def test_api_users_boolean_attribute(app, superuser):
|
|||
assert resp.json['boolean'] is True
|
||||
|
||||
|
||||
def test_api_users_boolean_attribute_optional(app, superuser):
|
||||
from authentic2.models import Attribute, AttributeValue
|
||||
at = Attribute.objects.create(
|
||||
kind='boolean', name='boolean', label='boolean', required=False)
|
||||
superuser.attributes.boolean = True
|
||||
app.authorization = ('Basic', (superuser.username, superuser.username))
|
||||
resp = app.get('/api/users/%s/' % superuser.uuid)
|
||||
assert resp.json['boolean'] is True
|
||||
|
||||
|
||||
def test_api_users_list_by_authorized_service(app, superuser):
|
||||
from authentic2.models import Service
|
||||
|
||||
|
|
Loading…
Reference in New Issue