Skip to content

Commit 79a19b6

Browse files
committed
chore: always use new codepath over deprecated
1 parent ba9f777 commit 79a19b6

File tree

4 files changed

+14
-32
lines changed

4 files changed

+14
-32
lines changed

coderd/audit/request.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type Request[T Auditable] struct {
5151
Action database.AuditAction
5252
}
5353

54+
// UpdateOrganizationID can be used if the organization ID is not known
55+
// at the initiation of an audit log request.
5456
func (r *Request[T]) UpdateOrganizationID(id uuid.UUID) {
5557
r.params.OrganizationID = id
5658
}

coderd/coderdtest/coderdtest.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,25 +1064,6 @@ func (w WorkspaceAgentWaiter) Wait() []codersdk.WorkspaceResource {
10641064
// CreateWorkspace creates a workspace for the user and template provided.
10651065
// A random name is generated for it.
10661066
// To customize the defaults, pass a mutator func.
1067-
//
1068-
// Deprecated: Use CreateWorkspace.
1069-
func CreateWorkspaceByOrganization(t testing.TB, client *codersdk.Client, organization uuid.UUID, templateID uuid.UUID, mutators ...func(*codersdk.CreateWorkspaceRequest)) codersdk.Workspace {
1070-
t.Helper()
1071-
req := codersdk.CreateWorkspaceRequest{
1072-
TemplateID: templateID,
1073-
Name: RandomUsername(t),
1074-
AutostartSchedule: ptr.Ref("CRON_TZ=US/Central 30 9 * * 1-5"),
1075-
TTLMillis: ptr.Ref((8 * time.Hour).Milliseconds()),
1076-
AutomaticUpdates: codersdk.AutomaticUpdatesNever,
1077-
}
1078-
for _, mutator := range mutators {
1079-
mutator(&req)
1080-
}
1081-
workspace, err := client.CreateWorkspace(context.Background(), organization, codersdk.Me, req)
1082-
require.NoError(t, err)
1083-
return workspace
1084-
}
1085-
10861067
func CreateWorkspace(t testing.TB, client *codersdk.Client, templateID uuid.UUID, mutators ...func(*codersdk.CreateWorkspaceRequest)) codersdk.Workspace {
10871068
t.Helper()
10881069
req := codersdk.CreateWorkspaceRequest{

coderd/workspaces.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,8 +510,18 @@ func createWorkspace(
510510
})
511511
return
512512
}
513+
514+
// Update audit log's organization
513515
auditReq.UpdateOrganizationID(template.OrganizationID)
514516

517+
// Do this upfront to save work. If this fails, the rest of the work
518+
// would be wasted.
519+
if !api.Authorize(r, policy.ActionCreate,
520+
rbac.ResourceWorkspace.InOrg(template.OrganizationID).WithOwner(user.ID.String())) {
521+
httpapi.ResourceNotFound(rw)
522+
return
523+
}
524+
515525
templateAccessControl := (*(api.AccessControlStore.Load())).GetTemplateAccessControl(template)
516526
if templateAccessControl.IsDeprecated() {
517527
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{

codersdk/organizations.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -475,19 +475,8 @@ func (c *Client) TemplateByName(ctx context.Context, organizationID uuid.UUID, n
475475
// CreateWorkspace creates a new workspace for the template specified.
476476
//
477477
// Deprecated: Use CreateUserWorkspace instead.
478-
func (c *Client) CreateWorkspace(ctx context.Context, organizationID uuid.UUID, user string, request CreateWorkspaceRequest) (Workspace, error) {
479-
res, err := c.Request(ctx, http.MethodPost, fmt.Sprintf("/api/v2/organizations/%s/members/%s/workspaces", organizationID, user), request)
480-
if err != nil {
481-
return Workspace{}, err
482-
}
483-
defer res.Body.Close()
484-
485-
if res.StatusCode != http.StatusCreated {
486-
return Workspace{}, ReadBodyAsError(res)
487-
}
488-
489-
var workspace Workspace
490-
return workspace, json.NewDecoder(res.Body).Decode(&workspace)
478+
func (c *Client) CreateWorkspace(ctx context.Context, _ uuid.UUID, user string, request CreateWorkspaceRequest) (Workspace, error) {
479+
return c.CreateUserWorkspace(ctx, user, request)
491480
}
492481

493482
// CreateUserWorkspace creates a new workspace for the template specified.

0 commit comments

Comments
 (0)