From b097cf4d7e74a9e95bad7f2dd1a520becc59c3da Mon Sep 17 00:00:00 2001 From: Jens L Date: Sun, 26 Mar 2023 22:34:53 +0200 Subject: [PATCH] providers/scim: fix error when user-group m2m is updated forward (#5082) * providers/scim: fix error when user-group m2m is updated forward Signed-off-by: Jens Langhammer * fix Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer --- authentik/providers/scim/signals.py | 12 ++++++++++-- authentik/providers/scim/tasks.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) 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: