sources/ldap: fix error when modifying ldap source with password write-back

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-08-24 13:03:41 +02:00
parent 884c2bd0e9
commit 2ec1ff2ebb
1 changed files with 4 additions and 1 deletions

View File

@ -27,7 +27,10 @@ class LDAPSourceSerializer(SourceSerializer):
"""Check that only a single source has password_sync on"""
sync_users_password = attrs.get("sync_users_password", True)
if sync_users_password:
if LDAPSource.objects.filter(sync_users_password=True).exists():
filter = LDAPSource.objects.filter(sync_users_password=True)
if self.instance:
filter = filter.exclude(pk=self.instance.pk)
if filter.exists():
raise ValidationError(
"Only a single LDAP Source with password synchronization is allowed"
)