From 881f1fba94c60a243feb695e6976ff2eca8d8beb Mon Sep 17 00:00:00 2001 From: Allen Lee Date: Wed, 9 Oct 2024 10:35:51 -0400 Subject: [PATCH] Update doc example JS Hook adding user to group (#4900) --- docs/source/teams/pluggable_auth.md | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/docs/source/teams/pluggable_auth.md b/docs/source/teams/pluggable_auth.md index 6c5a903944..585e8fc657 100644 --- a/docs/source/teams/pluggable_auth.md +++ b/docs/source/teams/pluggable_auth.md @@ -225,18 +225,22 @@ async function Hook(context) { groupName ); } - // Add signed-in user to the group and update the group - group.userIds.push(user.id); - const updatedGroupName = undefined; - const updatedGroupDescription = undefined; - const updatedGroupUserIds = [...group.userIds, user.id]; - await services.directory.groups.updateGroup( - orgId, - group.id, - updatedGroupName, - updatedGroupDescription, - updatedGroupUserIds - ); + + if (!group.userIds.includes(user.id)) { + // Add signed-in user to the group and update the group + const updatedGroupName = undefined; + const updatedGroupDescription = undefined; + const updatedGroupUserIds = [...group.userIds, user.id]; + const accessorId = undefined; + await services.directory.groups.updateGroup( + orgId, + group.id, + accessorId, + updatedGroupName, + updatedGroupDescription, + updatedGroupUserIds + ); + } } } ```