Skip to content

Commit

Permalink
maintainting description on UserGroup PUT
Browse files Browse the repository at this point in the history
  • Loading branch information
kgibson-spotnana committed Jan 29, 2024
1 parent 24394ee commit 3afdb06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions jc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ func TestClient_UserGroups_CreateAndDeleteUserGroup(t *testing.T) {
}

// Update UserGroup name to include "-updated"
updatedGroup, err := c.UpdateUserGroup(newGroup.ID, UserGroup{
update := UserGroup{
Name: testName + "-updated",
})
}
updatedGroup, err := c.UpdateUserGroup(newGroup.ID, update)

// Verify UserGroup name changed
result, err := c.GetUserGroupByName(testName + "-updated")
Expand Down
8 changes: 8 additions & 0 deletions usergroups.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ func (c *Client) GetUserGroupByName(groupName string) (userGroup UserGroup, err

// UpdateUserGroup updates a user group
func (c *Client) UpdateUserGroup(groupId string, updatedUserGroup UserGroup) (userGroup UserGroup, err error) {
// If update does not contain a description field, set it to the old description
// We do this because the API will overwrite the description field with an empty string if not passed
if updatedUserGroup.Description == "" {
oldGroupData, _ := c.GetUserGroup(groupId)
if oldGroupData.Description != "" {
updatedUserGroup.Description = oldGroupData.Description
}
}
c.HostURL.Path = "/api/v2/usergroups/" + groupId
jsonBody, err := json.Marshal(updatedUserGroup)
request, err := http.NewRequest(
Expand Down

0 comments on commit 3afdb06

Please sign in to comment.