Skip to content

Commit

Permalink
providers/scim: optimize sending all members within a group
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu committed Aug 15, 2024
1 parent 233e43c commit a47885b
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions authentik/providers/scim/clients/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,20 @@ def to_schema(self, obj: Group, connection: SCIMProviderGroup) -> SCIMGroupSchem
if not scim_group.externalId:
scim_group.externalId = str(obj.pk)

users = list(obj.users.order_by("id").values_list("id", flat=True))
connections = SCIMProviderUser.objects.filter(provider=self.provider, user__pk__in=users)
members = []
for user in connections:
members.append(
GroupMember(
value=user.scim_id,
if not self._config.patch.supported:
users = list(obj.users.order_by("id").values_list("id", flat=True))
connections = SCIMProviderUser.objects.filter(provider=self.provider, user__pk__in=users)
members = []
for user in connections:
members.append(

Check warning on line 64 in authentik/providers/scim/clients/groups.py

View check run for this annotation

Codecov / codecov/patch

authentik/providers/scim/clients/groups.py#L64

Added line #L64 was not covered by tests
GroupMember(
value=user.scim_id,
)
)
)
if members:
scim_group.members = members
if members:
scim_group.members = members

Check warning on line 70 in authentik/providers/scim/clients/groups.py

View check run for this annotation

Codecov / codecov/patch

authentik/providers/scim/clients/groups.py#L70

Added line #L70 was not covered by tests
else:
del scim_group.members
return scim_group

def delete(self, obj: Group):
Expand All @@ -93,23 +96,28 @@ def create(self, group: Group):
scim_id = response.get("id")
if not scim_id or scim_id == "":
raise StopSync("SCIM Response with missing or invalid `id`")
return SCIMProviderGroup.objects.create(
connection = SCIMProviderGroup.objects.create(
provider=self.provider, group=group, scim_id=scim_id
)
users = list(group.users.order_by("id").values_list("id", flat=True))
self._patch_add_users(group, users)
return connection

def update(self, group: Group, connection: SCIMProviderGroup):
"""Update existing group"""
scim_group = self.to_schema(group, connection)
scim_group.id = connection.scim_id
try:
return self._request(
self._request(
"PUT",
f"/Groups/{connection.scim_id}",
json=scim_group.model_dump(
mode="json",
exclude_unset=True,
),
)
users = list(group.users.order_by("id").values_list("id", flat=True))
return self._patch_add_users(group, users)

Check warning on line 120 in authentik/providers/scim/clients/groups.py

View check run for this annotation

Codecov / codecov/patch

authentik/providers/scim/clients/groups.py#L119-L120

Added lines #L119 - L120 were not covered by tests
except NotFoundSyncException:
# Resource missing is handled by self.write, which will re-create the group
raise
Expand Down

0 comments on commit a47885b

Please sign in to comment.