@Summary Update group IdP Sync config @ID update-group-idp-sync-config @Security CoderSessionToken @Produce json @Accept json @Tags Enterprise @Success 200 {object} codersdk.GroupSyncSettings @Param organization path string true "Organization ID or name" format(uuid) @Param request body codersdk.Pat
(rw http.ResponseWriter, r *http.Request)
| 142 | // @Param request body codersdk.PatchGroupIDPSyncConfigRequest true "New config values" |
| 143 | // @Router /api/v2/organizations/{organization}/settings/idpsync/groups/config [patch] |
| 144 | func (api *API) patchGroupIDPSyncConfig(rw http.ResponseWriter, r *http.Request) { |
| 145 | ctx := r.Context() |
| 146 | org := httpmw.OrganizationParam(r) |
| 147 | auditor := *api.AGPL.Auditor.Load() |
| 148 | aReq, commitAudit := audit.InitRequest[idpsync.GroupSyncSettings](rw, &audit.RequestParams{ |
| 149 | Audit: auditor, |
| 150 | Log: api.Logger, |
| 151 | Request: r, |
| 152 | Action: database.AuditActionWrite, |
| 153 | OrganizationID: org.ID, |
| 154 | }) |
| 155 | defer commitAudit() |
| 156 | |
| 157 | if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceIdpsyncSettings.InOrg(org.ID)) { |
| 158 | httpapi.Forbidden(rw) |
| 159 | return |
| 160 | } |
| 161 | |
| 162 | var req codersdk.PatchGroupIDPSyncConfigRequest |
| 163 | if !httpapi.Read(ctx, rw, r, &req) { |
| 164 | return |
| 165 | } |
| 166 | |
| 167 | var settings idpsync.GroupSyncSettings |
| 168 | //nolint:gocritic // Requires system context to update runtime config |
| 169 | sysCtx := dbauthz.AsSystemRestricted(ctx) |
| 170 | err := database.ReadModifyUpdate(api.Database, func(tx database.Store) error { |
| 171 | existing, err := api.IDPSync.GroupSyncSettings(sysCtx, org.ID, tx) |
| 172 | if err != nil { |
| 173 | return err |
| 174 | } |
| 175 | aReq.Old = *existing |
| 176 | |
| 177 | settings = idpsync.GroupSyncSettings{ |
| 178 | Field: req.Field, |
| 179 | RegexFilter: req.RegexFilter, |
| 180 | AutoCreateMissing: req.AutoCreateMissing, |
| 181 | LegacyNameMapping: existing.LegacyNameMapping, |
| 182 | Mapping: existing.Mapping, |
| 183 | } |
| 184 | |
| 185 | err = api.IDPSync.UpdateGroupSyncSettings(sysCtx, org.ID, tx, settings) |
| 186 | if err != nil { |
| 187 | return err |
| 188 | } |
| 189 | |
| 190 | return nil |
| 191 | }) |
| 192 | if err != nil { |
| 193 | httpapi.InternalServerError(rw, err) |
| 194 | return |
| 195 | } |
| 196 | |
| 197 | aReq.New = settings |
| 198 | httpapi.Write(ctx, rw, http.StatusOK, codersdk.GroupSyncSettings{ |
| 199 | Field: settings.Field, |
| 200 | RegexFilter: settings.RegexFilter, |
| 201 | AutoCreateMissing: settings.AutoCreateMissing, |
nothing calls this directly
no test coverage detected