Skip to content

Commit

Permalink
providers/scim: patch name when group put fails
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu committed May 10, 2023
1 parent 639a5c4 commit d6bcc02
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions authentik/providers/scim/clients/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,19 @@ def _update(self, group: Group, connection: SCIMGroup):
except SCIMRequestException:
# Some providers don't support PUT on groups, so this is mainly a fix for the initial
# sync, send patch add requests for all the users the group currently has
# TODO: send patch request for group name
users = list(group.users.order_by("id").values_list("id", flat=True))
return self._patch_add_users(group, users)

def _patch(
self,
group_id: str,
*ops: PatchOperation,
):
req = PatchRequest(Operations=ops)
self._request("PATCH", f"/Groups/{group_id}", data=req.json())
self._patch_add_users(group, users)
# Also update the group name
self._patch(
scim_group.id,
PatchOperation(
op=PatchOp.replace,
value={
"id": connection.id,
"displayName": group.name,
}
),
)

def update_group(self, group: Group, action: PatchOp, users_set: set[int]):
"""Update a group, either using PUT to replace it or PATCH if supported"""
Expand All @@ -151,6 +153,14 @@ def update_group(self, group: Group, action: PatchOp, users_set: set[int]):
return self._patch_remove_users(group, users_set)
raise exc

def _patch(
self,
group_id: str,
*ops: PatchOperation,
):
req = PatchRequest(Operations=ops)
self._request("PATCH", f"/Groups/{group_id}", data=req.json())

def _patch_add_users(self, group: Group, users_set: set[int]):
"""Add users in users_set to group"""
if len(users_set) < 1:
Expand Down

0 comments on commit d6bcc02

Please sign in to comment.