diff --git a/coderd/workspaces.go b/coderd/workspaces.go index 3b9ea88ecc91a..23c142bcdf873 100644 --- a/coderd/workspaces.go +++ b/coderd/workspaces.go @@ -60,12 +60,6 @@ func (api *API) workspace(rw http.ResponseWriter, r *http.Request) { }) return } - if !workspace.Deleted && showDeleted { - httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{ - Message: fmt.Sprintf("Workspace %q is not deleted, please remove '?deleted=true' and try again", workspace.ID.String()), - }) - return - } build, err := api.Database.GetLatestWorkspaceBuildByWorkspaceID(r.Context(), workspace.ID) if err != nil { diff --git a/coderd/workspaces_test.go b/coderd/workspaces_test.go index c7b0e28f3b391..e7fa0855e0bdf 100644 --- a/coderd/workspaces_test.go +++ b/coderd/workspaces_test.go @@ -46,10 +46,9 @@ func TestWorkspace(t *testing.T) { workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID) coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID) - // Getting with deleted=true should fail. + // Getting with deleted=true should still work. _, err := client.DeletedWorkspace(context.Background(), workspace.ID) - require.Error(t, err) - require.ErrorContains(t, err, "400") // bad request + require.NoError(t, err) // Delete the workspace build, err := client.CreateWorkspaceBuild(context.Background(), workspace.ID, codersdk.CreateWorkspaceBuildRequest{ diff --git a/codersdk/client.go b/codersdk/client.go index c8e613a631202..78a266db02202 100644 --- a/codersdk/client.go +++ b/codersdk/client.go @@ -36,14 +36,6 @@ type Client struct { type requestOption func(*http.Request) -func queryParam(k, v string) requestOption { - return func(r *http.Request) { - q := r.URL.Query() - q.Set(k, v) - r.URL.RawQuery = q.Encode() - } -} - // Request performs an HTTP request with the body provided. // The caller is responsible for closing the response body. func (c *Client) Request(ctx context.Context, method, path string, body interface{}, opts ...requestOption) (*http.Response, error) { diff --git a/codersdk/workspaces.go b/codersdk/workspaces.go index 0d9aadccedca1..3e81645957314 100644 --- a/codersdk/workspaces.go +++ b/codersdk/workspaces.go @@ -38,6 +38,22 @@ type CreateWorkspaceBuildRequest struct { ProvisionerState []byte `json:"state,omitempty"` } +type WorkspaceOptions struct { + Deleted bool `json:"deleted,omitempty"` +} + +// asRequestOption returns a function that can be used in (*Client).Request. +// It modifies the request query parameters. +func (o WorkspaceOptions) asRequestOption() requestOption { + return func(r *http.Request) { + q := r.URL.Query() + if o.Deleted { + q.Set("deleted", "true") + } + r.URL.RawQuery = q.Encode() + } +} + // Workspace returns a single workspace. func (c *Client) Workspace(ctx context.Context, id uuid.UUID) (Workspace, error) { return c.getWorkspace(ctx, id) @@ -45,7 +61,10 @@ func (c *Client) Workspace(ctx context.Context, id uuid.UUID) (Workspace, error) // DeletedWorkspace returns a single workspace that was deleted. func (c *Client) DeletedWorkspace(ctx context.Context, id uuid.UUID) (Workspace, error) { - return c.getWorkspace(ctx, id, queryParam("deleted", "true")) + o := WorkspaceOptions{ + Deleted: true, + } + return c.getWorkspace(ctx, id, o.asRequestOption()) } func (c *Client) getWorkspace(ctx context.Context, id uuid.UUID, opts ...requestOption) (Workspace, error) { diff --git a/site/src/api/typesGenerated.ts b/site/src/api/typesGenerated.ts index 1f227c08aa88e..8e71d52a3906c 100644 --- a/site/src/api/typesGenerated.ts +++ b/site/src/api/typesGenerated.ts @@ -221,7 +221,7 @@ export interface ProvisionerJobLog { readonly output: string } -// From codersdk/workspaces.go:182:6 +// From codersdk/workspaces.go:201:6 export interface PutExtendWorkspaceRequest { readonly deadline: string } @@ -298,12 +298,12 @@ export interface UpdateUserProfileRequest { readonly username: string } -// From codersdk/workspaces.go:141:6 +// From codersdk/workspaces.go:160:6 export interface UpdateWorkspaceAutostartRequest { readonly schedule?: string } -// From codersdk/workspaces.go:161:6 +// From codersdk/workspaces.go:180:6 export interface UpdateWorkspaceTTLRequest { readonly ttl_ms?: number } @@ -445,18 +445,23 @@ export interface WorkspaceBuild { readonly deadline: string } -// From codersdk/workspaces.go:64:6 +// From codersdk/workspaces.go:83:6 export interface WorkspaceBuildsRequest extends Pagination { readonly WorkspaceID: string } -// From codersdk/workspaces.go:200:6 +// From codersdk/workspaces.go:219:6 export interface WorkspaceFilter { readonly organization_id?: string readonly owner?: string readonly name?: string } +// From codersdk/workspaces.go:41:6 +export interface WorkspaceOptions { + readonly deleted?: boolean +} + // From codersdk/workspaceresources.go:21:6 export interface WorkspaceResource { readonly id: string
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: