feat: Allow admins to create workspaces (#4183)

Fixes #3263.

This is now possible via the API, but still isn't possible via the UI.
This commit is contained in:
Kyle Carberry
2022-09-23 20:17:10 -05:00
committed by GitHub
parent 266a3b24e7
commit 3c215a83b6
9 changed files with 23 additions and 21 deletions
+6 -5
View File
@@ -222,6 +222,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
organization = httpmw.OrganizationParam(r)
apiKey = httpmw.APIKey(r)
auditor = api.Auditor.Load()
user = httpmw.UserParam(r)
aReq, commitAudit = audit.InitRequest[database.Workspace](rw, &audit.RequestParams{
Audit: *auditor,
Log: api.Logger,
@@ -232,7 +233,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
defer commitAudit()
if !api.Authorize(r, rbac.ActionCreate,
rbac.ResourceWorkspace.InOrg(organization.ID).WithOwner(apiKey.UserID.String())) {
rbac.ResourceWorkspace.InOrg(organization.ID).WithOwner(user.ID.String())) {
httpapi.ResourceNotFound(rw)
return
}
@@ -292,7 +293,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
}
workspace, err := api.Database.GetWorkspaceByOwnerIDAndName(ctx, database.GetWorkspaceByOwnerIDAndNameParams{
OwnerID: apiKey.UserID,
OwnerID: user.ID,
Name: createWorkspace.Name,
})
if err == nil {
@@ -359,7 +360,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
ID: uuid.New(),
CreatedAt: now,
UpdatedAt: now,
OwnerID: apiKey.UserID,
OwnerID: user.ID,
OrganizationID: template.OrganizationID,
TemplateID: template.ID,
Name: createWorkspace.Name,
@@ -441,7 +442,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
aReq.New = workspace
users, err := api.Database.GetUsersByIDs(ctx, database.GetUsersByIDsParams{
IDs: []uuid.UUID{apiKey.UserID, workspaceBuild.InitiatorID},
IDs: []uuid.UUID{user.ID, workspaceBuild.InitiatorID},
})
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
@@ -478,7 +479,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
workspace,
apiBuild,
template,
findUser(apiKey.UserID, users),
findUser(user.ID, users),
))
}