@Summary Update group IdP Sync settings by organization @ID update-group-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.GroupSyncSettings true "
(rw http.ResponseWriter, r *http.Request)
| 58 | // @Success 200 {object} codersdk.GroupSyncSettings |
| 59 | // @Router /api/v2/organizations/{organization}/settings/idpsync/groups [patch] |
| 60 | func (api *API) patchGroupIDPSyncSettings(rw http.ResponseWriter, r *http.Request) { |
| 61 | ctx := r.Context() |
| 62 | org := httpmw.OrganizationParam(r) |
| 63 | auditor := *api.AGPL.Auditor.Load() |
| 64 | aReq, commitAudit := audit.InitRequest[idpsync.GroupSyncSettings](rw, &audit.RequestParams{ |
| 65 | Audit: auditor, |
| 66 | Log: api.Logger, |
| 67 | Request: r, |
| 68 | Action: database.AuditActionWrite, |
| 69 | OrganizationID: org.ID, |
| 70 | }) |
| 71 | defer commitAudit() |
| 72 | |
| 73 | if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceIdpsyncSettings.InOrg(org.ID)) { |
| 74 | httpapi.Forbidden(rw) |
| 75 | return |
| 76 | } |
| 77 | |
| 78 | var req codersdk.GroupSyncSettings |
| 79 | if !httpapi.Read(ctx, rw, r, &req) { |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | if len(req.LegacyNameMapping) > 0 { |
| 84 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 85 | Message: "Unexpected field 'legacy_group_name_mapping'. Field not allowed, set to null or remove it.", |
| 86 | Detail: "legacy_group_name_mapping is deprecated, use mapping instead", |
| 87 | Validations: []codersdk.ValidationError{ |
| 88 | { |
| 89 | Field: "legacy_group_name_mapping", |
| 90 | Detail: "field is not allowed", |
| 91 | }, |
| 92 | }, |
| 93 | }) |
| 94 | return |
| 95 | } |
| 96 | |
| 97 | //nolint:gocritic // Requires system context to update runtime config |
| 98 | sysCtx := dbauthz.AsSystemRestricted(ctx) |
| 99 | existing, err := api.IDPSync.GroupSyncSettings(sysCtx, org.ID, api.Database) |
| 100 | if err != nil { |
| 101 | httpapi.InternalServerError(rw, err) |
| 102 | return |
| 103 | } |
| 104 | aReq.Old = *existing |
| 105 | |
| 106 | err = api.IDPSync.UpdateGroupSyncSettings(sysCtx, org.ID, api.Database, idpsync.GroupSyncSettings{ |
| 107 | Field: req.Field, |
| 108 | Mapping: req.Mapping, |
| 109 | RegexFilter: req.RegexFilter, |
| 110 | AutoCreateMissing: req.AutoCreateMissing, |
| 111 | LegacyNameMapping: req.LegacyNameMapping, |
| 112 | }) |
| 113 | if err != nil { |
| 114 | httpapi.InternalServerError(rw, err) |
| 115 | return |
| 116 | } |
| 117 |
nothing calls this directly
no test coverage detected