sources/ldap: sync source on save
This commit is contained in:
parent
494950ac65
commit
e7472de4bf
|
@ -45,7 +45,7 @@ class AdministrationOverviewView(AdminRequiredMixin, TemplateView):
|
|||
def get_context_data(self, **kwargs):
|
||||
kwargs["application_count"] = len(Application.objects.all())
|
||||
kwargs["policy_count"] = len(Policy.objects.all())
|
||||
kwargs["user_count"] = len(User.objects.all()) - 1 # Remove anonymous user
|
||||
kwargs["user_count"] = len(User.objects.all()) - 1 # Remove anonymous user
|
||||
kwargs["provider_count"] = len(Provider.objects.all())
|
||||
kwargs["source_count"] = len(Source.objects.all())
|
||||
kwargs["stage_count"] = len(Stage.objects.all())
|
||||
|
|
|
@ -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,7 +8,14 @@ from passbook.sources.ldap.models import LDAPSource
|
|||
def sync():
|
||||
"""Sync all sources"""
|
||||
for source in LDAPSource.objects.filter(enabled=True):
|
||||
connector = Connector(source)
|
||||
connector.sync_users()
|
||||
connector.sync_groups()
|
||||
connector.sync_membership()
|
||||
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.sync_users()
|
||||
connector.sync_groups()
|
||||
connector.sync_membership()
|
||||
|
|
Reference in New Issue