diff --git a/authentik/providers/scim/signals.py b/authentik/providers/scim/signals.py index 4450a72a6..c9e179ac9 100644 --- a/authentik/providers/scim/signals.py +++ b/authentik/providers/scim/signals.py @@ -34,8 +34,16 @@ def pre_delete_scim(sender: type[Model], instance: User | Group, **_): @receiver(m2m_changed, sender=User.ak_groups.through) -def m2m_changed_scim(sender: type[Model], instance, action: str, pk_set: set, **kwargs): +def m2m_changed_scim( + sender: type[Model], instance, action: str, pk_set: set, reverse: bool, **kwargs +): """Sync group membership""" if action not in ["post_add", "post_remove"]: return - scim_signal_m2m.delay(str(instance.pk), action, list(pk_set)) + # reverse: instance is a Group, pk_set is a list of user pks + # non-reverse: instance is a User, pk_set is a list of groups + if reverse: + scim_signal_m2m.delay(str(instance.pk), action, list(pk_set)) + else: + for group_pk in pk_set: + scim_signal_m2m.delay(group_pk, action, [instance.pk]) diff --git a/authentik/providers/scim/tasks.py b/authentik/providers/scim/tasks.py index 89895dfbe..18673d3ad 100644 --- a/authentik/providers/scim/tasks.py +++ b/authentik/providers/scim/tasks.py @@ -151,7 +151,7 @@ def scim_signal_direct(model: str, pk: Any, raw_op: str): @CELERY_APP.task() -def scim_signal_m2m(group_pk: str, action: str, pk_set: set[int]): +def scim_signal_m2m(group_pk: str, action: str, pk_set: list[int]): """Update m2m (group membership)""" group = Group.objects.filter(pk=group_pk).first() if not group: