@Summary Update organization IdP Sync config @ID update-organization-idp-sync-config @Security CoderSessionToken @Produce json @Accept json @Tags Enterprise @Success 200 {object} codersdk.OrganizationSyncSettings @Param request body codersdk.PatchOrganizationIDPSyncConfigRequest true "New config val
(rw http.ResponseWriter, r *http.Request)
| 610 | // @Param request body codersdk.PatchOrganizationIDPSyncConfigRequest true "New config values" |
| 611 | // @Router /api/v2/settings/idpsync/organization/config [patch] |
| 612 | func (api *API) patchOrganizationIDPSyncConfig(rw http.ResponseWriter, r *http.Request) { |
| 613 | ctx := r.Context() |
| 614 | auditor := *api.AGPL.Auditor.Load() |
| 615 | aReq, commitAudit := audit.InitRequest[idpsync.OrganizationSyncSettings](rw, &audit.RequestParams{ |
| 616 | Audit: auditor, |
| 617 | Log: api.Logger, |
| 618 | Request: r, |
| 619 | Action: database.AuditActionWrite, |
| 620 | }) |
| 621 | defer commitAudit() |
| 622 | |
| 623 | if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceIdpsyncSettings) { |
| 624 | httpapi.Forbidden(rw) |
| 625 | return |
| 626 | } |
| 627 | |
| 628 | var req codersdk.PatchOrganizationIDPSyncConfigRequest |
| 629 | if !httpapi.Read(ctx, rw, r, &req) { |
| 630 | return |
| 631 | } |
| 632 | |
| 633 | var settings idpsync.OrganizationSyncSettings |
| 634 | //nolint:gocritic // Requires system context to update runtime config |
| 635 | sysCtx := dbauthz.AsSystemRestricted(ctx) |
| 636 | err := database.ReadModifyUpdate(api.Database, func(tx database.Store) error { |
| 637 | existing, err := api.IDPSync.OrganizationSyncSettings(sysCtx, tx) |
| 638 | if err != nil { |
| 639 | return err |
| 640 | } |
| 641 | aReq.Old = *existing |
| 642 | |
| 643 | settings = idpsync.OrganizationSyncSettings{ |
| 644 | Field: req.Field, |
| 645 | AssignDefault: req.AssignDefault, |
| 646 | Mapping: existing.Mapping, |
| 647 | } |
| 648 | |
| 649 | err = api.IDPSync.UpdateOrganizationSyncSettings(sysCtx, tx, settings) |
| 650 | if err != nil { |
| 651 | return err |
| 652 | } |
| 653 | |
| 654 | return nil |
| 655 | }) |
| 656 | if err != nil { |
| 657 | httpapi.InternalServerError(rw, err) |
| 658 | return |
| 659 | } |
| 660 | |
| 661 | aReq.New = settings |
| 662 | httpapi.Write(ctx, rw, http.StatusOK, codersdk.OrganizationSyncSettings{ |
| 663 | Field: settings.Field, |
| 664 | Mapping: settings.Mapping, |
| 665 | AssignDefault: settings.AssignDefault, |
| 666 | }) |
| 667 | } |
| 668 | |
| 669 | // @Summary Update organization IdP Sync mapping |
nothing calls this directly
no test coverage detected