@Summary Update organization @ID update-organization @Security CoderSessionToken @Accept json @Produce json @Tags Organizations @Param organization path string true "Organization ID or name" @Param request body codersdk.UpdateOrganizationRequest true "Patch organization request" @Success 200 {object
(rw http.ResponseWriter, r *http.Request)
| 31 | // @Success 200 {object} codersdk.Organization |
| 32 | // @Router /api/v2/organizations/{organization} [patch] |
| 33 | func (api *API) patchOrganization(rw http.ResponseWriter, r *http.Request) { |
| 34 | var ( |
| 35 | ctx = r.Context() |
| 36 | organization = httpmw.OrganizationParam(r) |
| 37 | auditor = api.AGPL.Auditor.Load() |
| 38 | aReq, commitAudit = audit.InitRequest[database.Organization](rw, &audit.RequestParams{ |
| 39 | Audit: *auditor, |
| 40 | Log: api.Logger, |
| 41 | Request: r, |
| 42 | Action: database.AuditActionWrite, |
| 43 | OrganizationID: organization.ID, |
| 44 | }) |
| 45 | ) |
| 46 | aReq.Old = organization |
| 47 | defer commitAudit() |
| 48 | |
| 49 | var req codersdk.UpdateOrganizationRequest |
| 50 | if !httpapi.Read(ctx, rw, r, &req) { |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | // "default" is a reserved name that always refers to the default org (much like the way we |
| 55 | // use "me" for users). |
| 56 | if req.Name == codersdk.DefaultOrganization { |
| 57 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 58 | Message: fmt.Sprintf("Organization name %q is reserved.", codersdk.DefaultOrganization), |
| 59 | }) |
| 60 | return |
| 61 | } |
| 62 | |
| 63 | err := database.ReadModifyUpdate(api.Database, func(tx database.Store) error { |
| 64 | var err error |
| 65 | organization, err = tx.GetOrganizationByID(ctx, organization.ID) |
| 66 | if err != nil { |
| 67 | return err |
| 68 | } |
| 69 | |
| 70 | updateOrgParams := database.UpdateOrganizationParams{ |
| 71 | UpdatedAt: dbtime.Now(), |
| 72 | ID: organization.ID, |
| 73 | Name: organization.Name, |
| 74 | DisplayName: organization.DisplayName, |
| 75 | Description: organization.Description, |
| 76 | Icon: organization.Icon, |
| 77 | } |
| 78 | |
| 79 | if req.Name != "" { |
| 80 | updateOrgParams.Name = req.Name |
| 81 | } |
| 82 | if req.DisplayName != "" { |
| 83 | updateOrgParams.DisplayName = req.DisplayName |
| 84 | } |
| 85 | if req.Description != nil { |
| 86 | updateOrgParams.Description = *req.Description |
| 87 | } |
| 88 | if req.Icon != nil { |
| 89 | updateOrgParams.Icon = *req.Icon |
| 90 | } |
nothing calls this directly
no test coverage detected