forked from Github-Mirrors/canaille
Fixed empty models attributes registration
This commit is contained in:
parent
2a4b382209
commit
4bfbeccc1c
3 changed files with 34 additions and 2 deletions
|
@ -18,6 +18,7 @@ Fixed
|
|||
*****
|
||||
|
||||
- ``OIDC.JWT.MAPPING`` configuration entry is really optional now.
|
||||
- Fixed empty model attributes registration :pr:`125`
|
||||
|
||||
[0.0.24] - 2023-04-07
|
||||
=====================
|
||||
|
|
|
@ -384,7 +384,11 @@ class LDAPObject(metaclass=LDAPObjectMetaclass):
|
|||
deletions = [
|
||||
name
|
||||
for name, value in self.changes.items()
|
||||
if (value is None or value == [None]) and name in self.attrs
|
||||
if (
|
||||
value is None
|
||||
or (isinstance(value, list) and len(value) == 1 and not value[0])
|
||||
)
|
||||
and name in self.attrs
|
||||
]
|
||||
changes = {
|
||||
name: value
|
||||
|
@ -394,7 +398,7 @@ class LDAPObject(metaclass=LDAPObjectMetaclass):
|
|||
formatted_changes = {
|
||||
name: value
|
||||
for name, value in python_attrs_to_ldap(changes).items()
|
||||
if value is not None and value != [None]
|
||||
if value is not None and len(value) > 0 and value[0]
|
||||
}
|
||||
modlist = [(ldap.MOD_DELETE, name, None) for name in deletions] + [
|
||||
(ldap.MOD_REPLACE, name, values)
|
||||
|
|
|
@ -153,6 +153,33 @@ def test_edition(
|
|||
logged_user.save()
|
||||
|
||||
|
||||
def test_edition_remove_fields(
|
||||
testclient,
|
||||
slapd_server,
|
||||
logged_user,
|
||||
admin,
|
||||
):
|
||||
res = testclient.get("/profile/user", status=200)
|
||||
res.form["display_name"] = ""
|
||||
res.form["phone_number"] = ""
|
||||
|
||||
res = res.form.submit(name="action", value="edit")
|
||||
assert res.flashes == [("success", "Profile updated successfuly.")], res.text
|
||||
res = res.follow()
|
||||
|
||||
logged_user.reload()
|
||||
|
||||
assert not logged_user.display_name
|
||||
assert not logged_user.phone_number
|
||||
|
||||
logged_user.formatted_name = ["John (johnny) Doe"]
|
||||
logged_user.family_name = ["Doe"]
|
||||
logged_user.mail = ["john@doe.com"]
|
||||
logged_user.given_name = None
|
||||
logged_user.photo = None
|
||||
logged_user.save()
|
||||
|
||||
|
||||
def test_profile_edition_dynamic_validation(testclient, logged_admin, user):
|
||||
res = testclient.get(f"/profile/admin")
|
||||
res = testclient.post(
|
||||
|
|
Loading…
Reference in a new issue