MCPcopy Index your code
hub / github.com/coder/coder / postWorkspacesByOrganization

Method postWorkspacesByOrganization

coderd/workspaces.go:376–419  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

374// @Success 200 {object} codersdk.Workspace
375// @Router /api/v2/organizations/{organization}/members/{user}/workspaces [post]
376func (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//

Callers

nothing calls this directly

Calls 10

APIKeyFunction · 0.92
OrganizationParamFunction · 0.92
OrganizationMemberParamFunction · 0.92
InitRequestFunction · 0.92
ReadFunction · 0.92
WriteResponseErrorFunction · 0.92
WriteFunction · 0.92
createWorkspaceFunction · 0.70
ContextMethod · 0.65
LoadMethod · 0.45

Tested by

no test coverage detected