sources/ldap: sync source on save
This commit is contained in:
parent
494950ac65
commit
e7472de4bf
|
@ -0,0 +1,14 @@
|
||||||
|
"""passbook ldap source signals"""
|
||||||
|
from django.db.models.signals import post_save
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
|
from passbook.sources.ldap.models import LDAPSource
|
||||||
|
from passbook.sources.ldap.tasks import sync_single
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=LDAPSource)
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
def sync_ldap_source_on_save(sender, instance: LDAPSource, **_):
|
||||||
|
"""Ensure that source is synced on save (if enabled)"""
|
||||||
|
if instance.enabled:
|
||||||
|
sync_single.delay(instance.pk)
|
|
@ -8,6 +8,13 @@ from passbook.sources.ldap.models import LDAPSource
|
||||||
def sync():
|
def sync():
|
||||||
"""Sync all sources"""
|
"""Sync all sources"""
|
||||||
for source in LDAPSource.objects.filter(enabled=True):
|
for source in LDAPSource.objects.filter(enabled=True):
|
||||||
|
sync_single.delay(source.pk)
|
||||||
|
|
||||||
|
|
||||||
|
@CELERY_APP.task()
|
||||||
|
def sync_single(source_pk):
|
||||||
|
"""Sync a single source"""
|
||||||
|
source = LDAPSource.objects.get(pk=source_pk)
|
||||||
connector = Connector(source)
|
connector = Connector(source)
|
||||||
connector.sync_users()
|
connector.sync_users()
|
||||||
connector.sync_groups()
|
connector.sync_groups()
|
||||||
|
|
Reference in New Issue