@Summary Update role IdP Sync settings by organization @ID update-role-idp-sync-settings-by-organization @Security CoderSessionToken @Produce json @Accept json @Tags Enterprise @Param organization path string true "Organization ID" format(uuid) @Param request body codersdk.RoleSyncSettings true "New
(rw http.ResponseWriter, r *http.Request)
| 317 | // @Success 200 {object} codersdk.RoleSyncSettings |
| 318 | // @Router /api/v2/organizations/{organization}/settings/idpsync/roles [patch] |
| 319 | func (api *API) patchRoleIDPSyncSettings(rw http.ResponseWriter, r *http.Request) { |
| 320 | ctx := r.Context() |
| 321 | org := httpmw.OrganizationParam(r) |
| 322 | auditor := *api.AGPL.Auditor.Load() |
| 323 | |
| 324 | aReq, commitAudit := audit.InitRequest[idpsync.RoleSyncSettings](rw, &audit.RequestParams{ |
| 325 | Audit: auditor, |
| 326 | Log: api.Logger, |
| 327 | Request: r, |
| 328 | Action: database.AuditActionWrite, |
| 329 | OrganizationID: org.ID, |
| 330 | }) |
| 331 | defer commitAudit() |
| 332 | |
| 333 | if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceIdpsyncSettings.InOrg(org.ID)) { |
| 334 | httpapi.Forbidden(rw) |
| 335 | return |
| 336 | } |
| 337 | |
| 338 | var req codersdk.RoleSyncSettings |
| 339 | if !httpapi.Read(ctx, rw, r, &req) { |
| 340 | return |
| 341 | } |
| 342 | |
| 343 | //nolint:gocritic // Requires system context to update runtime config |
| 344 | sysCtx := dbauthz.AsSystemRestricted(ctx) |
| 345 | existing, err := api.IDPSync.RoleSyncSettings(sysCtx, org.ID, api.Database) |
| 346 | if err != nil { |
| 347 | httpapi.InternalServerError(rw, err) |
| 348 | return |
| 349 | } |
| 350 | aReq.Old = *existing |
| 351 | |
| 352 | err = api.IDPSync.UpdateRoleSyncSettings(sysCtx, org.ID, api.Database, idpsync.RoleSyncSettings{ |
| 353 | Field: req.Field, |
| 354 | Mapping: req.Mapping, |
| 355 | }) |
| 356 | if err != nil { |
| 357 | httpapi.InternalServerError(rw, err) |
| 358 | return |
| 359 | } |
| 360 | |
| 361 | settings, err := api.IDPSync.RoleSyncSettings(sysCtx, org.ID, api.Database) |
| 362 | if err != nil { |
| 363 | httpapi.InternalServerError(rw, err) |
| 364 | return |
| 365 | } |
| 366 | |
| 367 | aReq.New = *settings |
| 368 | httpapi.Write(ctx, rw, http.StatusOK, codersdk.RoleSyncSettings{ |
| 369 | Field: settings.Field, |
| 370 | Mapping: settings.Mapping, |
| 371 | }) |
| 372 | } |
| 373 | |
| 374 | // @Summary Update role IdP Sync config |
| 375 | // @ID update-role-idp-sync-config |
nothing calls this directly
no test coverage detected