Skip to content

Commit e1a756d

Browse files
fix!: Send request body in SCIM update methods
UpdateProvisionedOrgMembership and UpdateAttributeForSCIMUser passed their parameters through addOptions, which only serializes url-tagged fields. Since the SCIM types are json-tagged, nothing was sent and the calls were effectively no-ops. They also discarded the updated user returned by the API. Both methods now send the payload as the request body and return the updated *SCIMUserAttributes. The body is taken by value via dedicated request types: a new UpdateProvisionedOrgMembershipRequest and UpdateAttributeForSCIMUserRequest (renamed from UpdateAttributeForSCIMUserOptions), whose Operations field is now a slice as required by the SCIM PATCH spec. The //nolint:paramcheck workaround is removed. Fixes google#4301. Co-Authored-By: Claude Opus 4.8 <[email protected]>
1 parent 4bb059c commit e1a756d

4 files changed

Lines changed: 282 additions & 43 deletions

File tree

‎github/github-accessors.go‎

Lines changed: 77 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎github/github-accessors_test.go‎

Lines changed: 101 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎github/scim.go‎

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -162,32 +162,48 @@ func (s *SCIMService) GetSCIMProvisioningInfoForUser(ctx context.Context, org, s
162162
return user, resp, nil
163163
}
164164

165+
// UpdateProvisionedOrgMembershipRequest represents the body of a request to
166+
// update a provisioned organization membership.
167+
type UpdateProvisionedOrgMembershipRequest struct {
168+
UserName string `json:"userName"` // Configured by the admin. Could be an email, login, or username. (Required.)
169+
Name SCIMUserName `json:"name"` // (Required.)
170+
DisplayName *string `json:"displayName,omitempty"` // The name of the user, suitable for display to end-users. (Optional.)
171+
Emails []*SCIMUserEmail `json:"emails"` // User emails. (Required.)
172+
Schemas []string `json:"schemas,omitempty"` // (Optional.)
173+
ExternalID *string `json:"externalId,omitempty"` // (Optional.)
174+
Groups []string `json:"groups,omitempty"` // (Optional.)
175+
Roles []*SCIMUserRole `json:"roles,omitempty"` // (Optional, GHES only.)
176+
Active *bool `json:"active,omitempty"` // (Optional.)
177+
}
178+
165179
// UpdateProvisionedOrgMembership updates a provisioned organization membership.
166180
//
167181
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim?apiVersion=2022-11-28#update-a-provisioned-organization-membership
168182
//
169183
//meta:operation PUT /scim/v2/organizations/{org}/Users/{scim_user_id}
170-
func (s *SCIMService) UpdateProvisionedOrgMembership(ctx context.Context, org, scimUserID string, opts *SCIMUserAttributes) (*Response, error) { //nolint:paramcheck // see https://github.com/google/go-github/issues/4301
184+
func (s *SCIMService) UpdateProvisionedOrgMembership(ctx context.Context, org, scimUserID string, body UpdateProvisionedOrgMembershipRequest) (*SCIMUserAttributes, *Response, error) {
171185
u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
172-
u, err := addOptions(u, opts)
186+
req, err := s.client.NewRequest(ctx, "PUT", u, body)
173187
if err != nil {
174-
return nil, err
188+
return nil, nil, err
175189
}
176190

177-
req, err := s.client.NewRequest(ctx, "PUT", u, nil)
191+
var user *SCIMUserAttributes
192+
resp, err := s.client.Do(req, &user)
178193
if err != nil {
179-
return nil, err
194+
return nil, resp, err
180195
}
181196

182-
return s.client.Do(req, nil)
197+
return user, resp, nil
183198
}
184199

185-
// UpdateAttributeForSCIMUserOptions represents options for UpdateAttributeForSCIMUser.
200+
// UpdateAttributeForSCIMUserRequest represents the body of a request to update an
201+
// attribute for a SCIM user.
186202
//
187203
// GitHub API docs: https://docs.github.com/rest/scim#update-an-attribute-for-a-scim-user--parameters
188-
type UpdateAttributeForSCIMUserOptions struct {
189-
Schemas []string `json:"schemas,omitempty"` // (Optional.)
190-
Operations UpdateAttributeForSCIMUserOperations `json:"operations"` // Set of operations to be performed. (Required.)
204+
type UpdateAttributeForSCIMUserRequest struct {
205+
Schemas []string `json:"schemas,omitempty"` // (Optional.)
206+
Operations []*UpdateAttributeForSCIMUserOperations `json:"Operations"` // Set of operations to be performed. (Required.)
191207
}
192208

193209
// UpdateAttributeForSCIMUserOperations represents operations for UpdateAttributeForSCIMUser.
@@ -202,19 +218,20 @@ type UpdateAttributeForSCIMUserOperations struct {
202218
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/scim/scim?apiVersion=2022-11-28#update-an-attribute-for-a-scim-user
203219
//
204220
//meta:operation PATCH /scim/v2/organizations/{org}/Users/{scim_user_id}
205-
func (s *SCIMService) UpdateAttributeForSCIMUser(ctx context.Context, org, scimUserID string, opts *UpdateAttributeForSCIMUserOptions) (*Response, error) {
221+
func (s *SCIMService) UpdateAttributeForSCIMUser(ctx context.Context, org, scimUserID string, body UpdateAttributeForSCIMUserRequest) (*SCIMUserAttributes, *Response, error) {
206222
u := fmt.Sprintf("scim/v2/organizations/%v/Users/%v", org, scimUserID)
207-
u, err := addOptions(u, opts)
223+
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
208224
if err != nil {
209-
return nil, err
225+
return nil, nil, err
210226
}
211227

212-
req, err := s.client.NewRequest(ctx, "PATCH", u, nil)
228+
var user *SCIMUserAttributes
229+
resp, err := s.client.Do(req, &user)
213230
if err != nil {
214-
return nil, err
231+
return nil, resp, err
215232
}
216233

217-
return s.client.Do(req, nil)
234+
return user, resp, nil
218235
}
219236

220237
// DeleteSCIMUserFromOrg deletes SCIM user from an organization.

0 commit comments

Comments
 (0)