@Summary Update organization IdP Sync mapping @ID update-organization-idp-sync-mapping @Security CoderSessionToken @Produce json @Accept json @Tags Enterprise @Success 200 {object} codersdk.OrganizationSyncSettings @Param request body codersdk.PatchOrganizationIDPSyncMappingRequest true "Description
(rw http.ResponseWriter, r *http.Request)
| 676 | // @Param request body codersdk.PatchOrganizationIDPSyncMappingRequest true "Description of the mappings to add and remove" |
| 677 | // @Router /api/v2/settings/idpsync/organization/mapping [patch] |
| 678 | func (api *API) patchOrganizationIDPSyncMapping(rw http.ResponseWriter, r *http.Request) { |
| 679 | ctx := r.Context() |
| 680 | auditor := *api.AGPL.Auditor.Load() |
| 681 | aReq, commitAudit := audit.InitRequest[idpsync.OrganizationSyncSettings](rw, &audit.RequestParams{ |
| 682 | Audit: auditor, |
| 683 | Log: api.Logger, |
| 684 | Request: r, |
| 685 | Action: database.AuditActionWrite, |
| 686 | }) |
| 687 | defer commitAudit() |
| 688 | |
| 689 | if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceIdpsyncSettings) { |
| 690 | httpapi.Forbidden(rw) |
| 691 | return |
| 692 | } |
| 693 | |
| 694 | var req codersdk.PatchOrganizationIDPSyncMappingRequest |
| 695 | if !httpapi.Read(ctx, rw, r, &req) { |
| 696 | return |
| 697 | } |
| 698 | |
| 699 | var settings idpsync.OrganizationSyncSettings |
| 700 | //nolint:gocritic // Requires system context to update runtime config |
| 701 | sysCtx := dbauthz.AsSystemRestricted(ctx) |
| 702 | err := database.ReadModifyUpdate(api.Database, func(tx database.Store) error { |
| 703 | existing, err := api.IDPSync.OrganizationSyncSettings(sysCtx, tx) |
| 704 | if err != nil { |
| 705 | return err |
| 706 | } |
| 707 | aReq.Old = *existing |
| 708 | |
| 709 | newMapping := applyIDPSyncMappingDiff(existing.Mapping, req.Add, req.Remove) |
| 710 | settings = idpsync.OrganizationSyncSettings{ |
| 711 | Field: existing.Field, |
| 712 | Mapping: newMapping, |
| 713 | AssignDefault: existing.AssignDefault, |
| 714 | } |
| 715 | |
| 716 | err = api.IDPSync.UpdateOrganizationSyncSettings(sysCtx, tx, settings) |
| 717 | if err != nil { |
| 718 | return err |
| 719 | } |
| 720 | |
| 721 | return nil |
| 722 | }) |
| 723 | if err != nil { |
| 724 | httpapi.InternalServerError(rw, err) |
| 725 | return |
| 726 | } |
| 727 | |
| 728 | aReq.New = settings |
| 729 | httpapi.Write(ctx, rw, http.StatusOK, codersdk.OrganizationSyncSettings{ |
| 730 | Field: settings.Field, |
| 731 | Mapping: settings.Mapping, |
| 732 | AssignDefault: settings.AssignDefault, |
| 733 | }) |
| 734 | } |
| 735 |
nothing calls this directly
no test coverage detected