- Notifications
You must be signed in to change notification settings - Fork928
chore: always use new codepath over deprecated#14050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
c710840
bd4dd33
9901bde
13ede7f
005dcd3
ca28cea
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -464,7 +464,7 @@ func createWorkspace( | ||
templateID := req.TemplateID | ||
if templateID == uuid.Nil { | ||
templateVersion, err := api.Database.GetTemplateVersionByID(ctx, req.TemplateVersionID) | ||
ifhttpapi.Is404Error(err) { | ||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ | ||
Message: fmt.Sprintf("Template version %q doesn't exist.", templateID.String()), | ||
Validations: []codersdk.ValidationError{{ | ||
@@ -498,7 +498,7 @@ func createWorkspace( | ||
} | ||
template, err := api.Database.GetTemplateByID(ctx, templateID) | ||
ifhttpapi.Is404Error(err) { | ||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ | ||
Comment on lines +501 to 502 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. maybe we should actually send a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Since it the request is trying to create a workspace, I am not sure if a 404 makes much sense to the caller? The error indicates why the request failed, being the template does not exist. | ||
Message: fmt.Sprintf("Template %q doesn't exist.", templateID.String()), | ||
Validations: []codersdk.ValidationError{{ | ||
@@ -521,8 +521,18 @@ func createWorkspace( | ||
}) | ||
return | ||
} | ||
// Update audit log's organization | ||
auditReq.UpdateOrganizationID(template.OrganizationID) | ||
// Do this upfront to save work. If this fails, the rest of the work | ||
// would be wasted. | ||
if !api.Authorize(r, policy.ActionCreate, | ||
rbac.ResourceWorkspace.InOrg(template.OrganizationID).WithOwner(owner.ID.String())) { | ||
httpapi.ResourceNotFound(rw) | ||
return | ||
} | ||
templateAccessControl := (*(api.AccessControlStore.Load())).GetTemplateAccessControl(template) | ||
if templateAccessControl.IsDeprecated() { | ||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ | ||
@@ -578,7 +588,7 @@ func createWorkspace( | ||
// read other workspaces. Ideally we check the error on create and look for | ||
// a postgres conflict error. | ||
workspace, err := api.Database.GetWorkspaceByOwnerIDAndName(ctx, database.GetWorkspaceByOwnerIDAndNameParams{ | ||
OwnerID:owner.ID, | ||
Name: req.Name, | ||
}) | ||
if err == nil { | ||
@@ -611,7 +621,7 @@ func createWorkspace( | ||
ID: uuid.New(), | ||
CreatedAt: now, | ||
UpdatedAt: now, | ||
OwnerID:owner.ID, | ||
OrganizationID: template.OrganizationID, | ||
TemplateID: template.ID, | ||
Name: req.Name, | ||
@@ -679,8 +689,8 @@ func createWorkspace( | ||
ProvisionerJob: *provisionerJob, | ||
QueuePosition: 0, | ||
}, | ||
owner.Username, | ||
owner.AvatarURL, | ||
[]database.WorkspaceResource{}, | ||
[]database.WorkspaceResourceMetadatum{}, | ||
[]database.WorkspaceAgent{}, | ||
@@ -702,8 +712,8 @@ func createWorkspace( | ||
workspace, | ||
apiBuild, | ||
template, | ||
owner.Username, | ||
owner.AvatarURL, | ||
api.Options.AllowWorkspaceRenames, | ||
) | ||
if err != nil { | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -475,19 +475,8 @@ func (c *Client) TemplateByName(ctx context.Context, organizationID uuid.UUID, n | ||
// CreateWorkspace creates a new workspace for the template specified. | ||
// | ||
// Deprecated: Use CreateUserWorkspace instead. | ||
func (c *Client) CreateWorkspace(ctx context.Context, _ uuid.UUID, user string, request CreateWorkspaceRequest) (Workspace, error) { | ||
return c.CreateUserWorkspace(ctx, user, request) | ||
Comment on lines +478 to +479 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. nice approach! | ||
} | ||
// CreateUserWorkspace creates a new workspace for the template specified. | ||
Uh oh!
There was an error while loading.Please reload this page.