Skip to content

Commit 1253ec1

Browse files
committed
feat: add workspaces/acl [delete] endpoint
1 parent db76496 commit 1253ec1

File tree

5 files changed

+126
-0
lines changed

5 files changed

+126
-0
lines changed

coderd/apidoc/docs.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ func New(options *Options) *API {
14571457

14581458
r.Get("/", api.workspaceACL)
14591459
r.Patch("/", api.patchWorkspaceACL)
1460+
r.Delete("/", api.deleteWorkspaceACL)
14601461
})
14611462
})
14621463
})

coderd/workspaces.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,53 @@ type workspaceData struct {
23562356
allowRenames bool
23572357
}
23582358

2359+
// @Summary Completely clears the workspace's user and group ACLs.
2360+
// @ID completely-clears-the-workspaces-user-and-group-acls
2361+
// @Security CoderSessionToken
2362+
// @Tags Workspaces
2363+
// @Param workspace path string true "Workspace ID" format(uuid)
2364+
// @Success 204
2365+
// @Router /workspaces/{workspace}/acl [delete]
2366+
func (api *API) deleteWorkspaceACL(rw http.ResponseWriter, r *http.Request) {
2367+
var (
2368+
ctx = r.Context()
2369+
workspace = httpmw.WorkspaceParam(r)
2370+
auditor = api.Auditor.Load()
2371+
aReq, commitAuditor = audit.InitRequest[database.WorkspaceTable](rw, &audit.RequestParams{
2372+
Audit: *auditor,
2373+
Log: api.Logger,
2374+
Request: r,
2375+
Action: database.AuditActionWrite,
2376+
OrganizationID: workspace.OrganizationID,
2377+
})
2378+
)
2379+
2380+
defer commitAuditor()
2381+
aReq.Old = workspace.WorkspaceTable()
2382+
2383+
err := api.Database.InTx(func(tx database.Store) error {
2384+
err := api.Database.DeleteWorkspaceACLByID(ctx, workspace.ID)
2385+
if err != nil {
2386+
return xerrors.Errorf("delete workspace by ID: %w", err)
2387+
}
2388+
2389+
workspace, err = api.Database.GetWorkspaceByID(ctx, workspace.ID)
2390+
if err != nil {
2391+
return xerrors.Errorf("get updated workspace by ID: %w", err)
2392+
}
2393+
2394+
return nil
2395+
}, nil)
2396+
if err != nil {
2397+
httpapi.InternalServerError(rw, err)
2398+
return
2399+
}
2400+
2401+
aReq.New = workspace.WorkspaceTable()
2402+
2403+
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
2404+
}
2405+
23592406
// workspacesData only returns the data the caller can access. If the caller
23602407
// does not have the correct perms to read a given template, the template will
23612408
// not be returned.

docs/reference/api/workspaces.md

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)