Create a new workspace for the currently authenticated user. @Summary Create user workspace by organization @Description Create a new workspace using a template. The request must @Description specify either the Template ID or the Template Version ID, @Description not both. If the Template ID is spe
(rw http.ResponseWriter, r *http.Request)
| 374 | // @Success 200 {object} codersdk.Workspace |
| 375 | // @Router /api/v2/organizations/{organization}/members/{user}/workspaces [post] |
| 376 | func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Request) { |
| 377 | var ( |
| 378 | ctx = r.Context() |
| 379 | apiKey = httpmw.APIKey(r) |
| 380 | auditor = api.Auditor.Load() |
| 381 | organization = httpmw.OrganizationParam(r) |
| 382 | member = httpmw.OrganizationMemberParam(r) |
| 383 | workspaceResourceInfo = audit.AdditionalFields{ |
| 384 | WorkspaceOwner: member.Username, |
| 385 | } |
| 386 | ) |
| 387 | |
| 388 | aReq, commitAudit := audit.InitRequest[database.WorkspaceTable](rw, &audit.RequestParams{ |
| 389 | Audit: *auditor, |
| 390 | Log: api.Logger, |
| 391 | Request: r, |
| 392 | Action: database.AuditActionCreate, |
| 393 | AdditionalFields: workspaceResourceInfo, |
| 394 | OrganizationID: organization.ID, |
| 395 | }) |
| 396 | |
| 397 | defer commitAudit() |
| 398 | |
| 399 | var req codersdk.CreateWorkspaceRequest |
| 400 | if !httpapi.Read(ctx, rw, r, &req) { |
| 401 | return |
| 402 | } |
| 403 | |
| 404 | owner := workspaceOwner{ |
| 405 | ID: member.UserID, |
| 406 | Username: member.Username, |
| 407 | AvatarURL: member.AvatarURL, |
| 408 | } |
| 409 | |
| 410 | w, err := createWorkspace(ctx, aReq, apiKey.UserID, api, owner, req, &createWorkspaceOptions{ |
| 411 | remoteAddr: r.RemoteAddr, |
| 412 | }) |
| 413 | if err != nil { |
| 414 | httperror.WriteResponseError(ctx, rw, err) |
| 415 | return |
| 416 | } |
| 417 | |
| 418 | httpapi.Write(ctx, rw, http.StatusCreated, w) |
| 419 | } |
| 420 | |
| 421 | // Create a new workspace for the currently authenticated user. |
| 422 | // |
nothing calls this directly
no test coverage detected