mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
feat: don't return 200 for deleted workspaces (#1556)
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
@ -34,6 +35,40 @@ func (api *api) workspace(rw http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if !api.Authorize(rw, r, rbac.ActionRead,
|
||||
rbac.ResourceWorkspace.InOrg(workspace.OrganizationID).WithOwner(workspace.OwnerID.String()).WithID(workspace.ID.String())) {
|
||||
return
|
||||
}
|
||||
|
||||
// The `deleted` query parameter (which defaults to `false`) MUST match the
|
||||
// `Deleted` field on the workspace otherwise you will get a 410 Gone.
|
||||
var (
|
||||
deletedStr = r.URL.Query().Get("deleted")
|
||||
showDeleted = false
|
||||
)
|
||||
if deletedStr != "" {
|
||||
var err error
|
||||
showDeleted, err = strconv.ParseBool(deletedStr)
|
||||
if err != nil {
|
||||
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
|
||||
Message: fmt.Sprintf("invalid bool for 'deleted' query param: %s", err),
|
||||
})
|
||||
return
|
||||
}
|
||||
}
|
||||
if workspace.Deleted && !showDeleted {
|
||||
httpapi.Write(rw, http.StatusGone, httpapi.Response{
|
||||
Message: fmt.Sprintf("workspace %q was deleted, you can view this workspace by specifying '?deleted=true' and trying again", workspace.ID.String()),
|
||||
})
|
||||
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 {
|
||||
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
|
||||
|
Reference in New Issue
Block a user