@Summary Update organization IdP Sync settings @ID update-organization-idp-sync-settings @Security CoderSessionToken @Produce json @Accept json @Tags Enterprise @Success 200 {object} codersdk.OrganizationSyncSettings @Param request body codersdk.OrganizationSyncSettings true "New settings" @Router /
(rw http.ResponseWriter, r *http.Request)
| 546 | // @Param request body codersdk.OrganizationSyncSettings true "New settings" |
| 547 | // @Router /api/v2/settings/idpsync/organization [patch] |
| 548 | func (api *API) patchOrganizationIDPSyncSettings(rw http.ResponseWriter, r *http.Request) { |
| 549 | ctx := r.Context() |
| 550 | auditor := *api.AGPL.Auditor.Load() |
| 551 | aReq, commitAudit := audit.InitRequest[idpsync.OrganizationSyncSettings](rw, &audit.RequestParams{ |
| 552 | Audit: auditor, |
| 553 | Log: api.Logger, |
| 554 | Request: r, |
| 555 | Action: database.AuditActionWrite, |
| 556 | }) |
| 557 | defer commitAudit() |
| 558 | |
| 559 | if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceIdpsyncSettings) { |
| 560 | httpapi.Forbidden(rw) |
| 561 | return |
| 562 | } |
| 563 | |
| 564 | var req codersdk.OrganizationSyncSettings |
| 565 | if !httpapi.Read(ctx, rw, r, &req) { |
| 566 | return |
| 567 | } |
| 568 | |
| 569 | //nolint:gocritic // Requires system context to update runtime config |
| 570 | sysCtx := dbauthz.AsSystemRestricted(ctx) |
| 571 | existing, err := api.IDPSync.OrganizationSyncSettings(sysCtx, api.Database) |
| 572 | if err != nil { |
| 573 | httpapi.InternalServerError(rw, err) |
| 574 | return |
| 575 | } |
| 576 | aReq.Old = *existing |
| 577 | |
| 578 | err = api.IDPSync.UpdateOrganizationSyncSettings(sysCtx, api.Database, idpsync.OrganizationSyncSettings{ |
| 579 | Field: req.Field, |
| 580 | // We do not check if the mappings point to actual organizations. |
| 581 | Mapping: req.Mapping, |
| 582 | AssignDefault: req.AssignDefault, |
| 583 | }) |
| 584 | if err != nil { |
| 585 | httpapi.InternalServerError(rw, err) |
| 586 | return |
| 587 | } |
| 588 | |
| 589 | settings, err := api.IDPSync.OrganizationSyncSettings(sysCtx, api.Database) |
| 590 | if err != nil { |
| 591 | httpapi.InternalServerError(rw, err) |
| 592 | return |
| 593 | } |
| 594 | |
| 595 | aReq.New = *settings |
| 596 | httpapi.Write(ctx, rw, http.StatusOK, codersdk.OrganizationSyncSettings{ |
| 597 | Field: settings.Field, |
| 598 | Mapping: settings.Mapping, |
| 599 | AssignDefault: settings.AssignDefault, |
| 600 | }) |
| 601 | } |
| 602 | |
| 603 | // @Summary Update organization IdP Sync config |
| 604 | // @ID update-organization-idp-sync-config |
nothing calls this directly
no test coverage detected