From 1d00080d5b6093a9637b9a7a8d559354897b931f Mon Sep 17 00:00:00 2001 From: sispeo <42068883+fperot74@users.noreply.github.com> Date: Tue, 24 Mar 2020 12:09:41 +0100 Subject: [PATCH] [CLOUDTRUST-2402] Add methods to make a user join/leave a group --- users.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/users.go b/users.go index f5e376f..af34a24 100644 --- a/users.go +++ b/users.go @@ -13,6 +13,7 @@ const ( userCountPath = userPath + "/count" userIDPath = userPath + "/:id" userGroupsPath = userIDPath + "/groups" + userGroupIDPath = userGroupsPath + "/:groupId" executeActionsEmailPath = userIDPath + "/execute-actions-email" sendReminderEmailPath = "/auth/realms/:realm/onboarding/sendReminderEmail" smsAPI = "/auth/realms/:realm/smsApi" @@ -47,20 +48,30 @@ func (c *Client) CountUsers(accessToken string, realmName string) (int, error) { return resp, err } -// GetUser get the represention of the user. +// GetUser gets the represention of the user. func (c *Client) GetUser(accessToken string, realmName, userID string) (UserRepresentation, error) { var resp = UserRepresentation{} var err = c.get(accessToken, &resp, url.Path(userIDPath), url.Param("realm", realmName), url.Param("id", userID)) return resp, err } -// GetGroupsOfUser get the groups of the user. +// GetGroupsOfUser gets the groups of the user. func (c *Client) GetGroupsOfUser(accessToken string, realmName, userID string) ([]GroupRepresentation, error) { var resp = []GroupRepresentation{} var err = c.get(accessToken, &resp, url.Path(userGroupsPath), url.Param("realm", realmName), url.Param("id", userID)) return resp, err } +// AddGroupToUser adds a group to the groups of the user. +func (c *Client) AddGroupToUser(accessToken string, realmName, userID, groupID string) error { + return c.put(accessToken, url.Path(userGroupIDPath), url.Param("realm", realmName), url.Param("id", userID), url.Param("groupId", groupID)) +} + +// DeleteGroupFromUser adds a group to the groups of the user. +func (c *Client) DeleteGroupFromUser(accessToken string, realmName, userID, groupID string) error { + return c.delete(accessToken, url.Path(userGroupIDPath), url.Param("realm", realmName), url.Param("id", userID), url.Param("groupId", groupID)) +} + // UpdateUser updates the user. func (c *Client) UpdateUser(accessToken string, realmName, userID string, user UserRepresentation) error { return c.put(accessToken, url.Path(userIDPath), url.Param("realm", realmName), url.Param("id", userID), body.JSON(user))