Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79a19b6

Browse files
committed
chore: always use new codepath over deprecated
1 parentba9f777 commit79a19b6

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-
funcCreateWorkspaceByOrganization(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:=rangemutators {
1079-
mutator(&req)
1080-
}
1081-
workspace,err:=client.CreateWorkspace(context.Background(),organization,codersdk.Me,req)
1082-
require.NoError(t,err)
1083-
returnworkspace
1084-
}
1085-
10861067
funcCreateWorkspace(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
iftemplateAccessControl.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,userstring,requestCreateWorkspaceRequest) (Workspace,error) {
479-
res,err:=c.Request(ctx,http.MethodPost,fmt.Sprintf("/api/v2/organizations/%s/members/%s/workspaces",organizationID,user),request)
480-
iferr!=nil {
481-
returnWorkspace{},err
482-
}
483-
deferres.Body.Close()
484-
485-
ifres.StatusCode!=http.StatusCreated {
486-
returnWorkspace{},ReadBodyAsError(res)
487-
}
488-
489-
varworkspaceWorkspace
490-
returnworkspace,json.NewDecoder(res.Body).Decode(&workspace)
478+
func (c*Client)CreateWorkspace(ctx context.Context,_ uuid.UUID,userstring,requestCreateWorkspaceRequest) (Workspace,error) {
479+
returnc.CreateUserWorkspace(ctx,user,request)
491480
}
492481

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp