-
Notifications
You must be signed in to change notification settings - Fork 881
feat: added include_deleted to getWorkspaceByOwnerAndName #2164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
142ad4e
5c77ea4
31f4013
9389df3
769ea99
f8a844c
56bceb6
ee1f417
28c2db6
5381554
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -165,10 +165,32 @@ func (api *API) workspaceByOwnerAndName(rw http.ResponseWriter, r *http.Request) | |||||||||||||
owner := httpmw.UserParam(r) | ||||||||||||||
workspaceName := chi.URLParam(r, "workspacename") | ||||||||||||||
|
||||||||||||||
includeDeleted := false | ||||||||||||||
if s := r.URL.Query().Get("include_deleted"); s != "" { | ||||||||||||||
var err error | ||||||||||||||
includeDeleted, err = strconv.ParseBool(s) | ||||||||||||||
if err != nil { | ||||||||||||||
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{ | ||||||||||||||
Message: fmt.Sprintf("Invalid boolean value %q for \"include_deleted\" query param.", s), | ||||||||||||||
Validations: []httpapi.Error{ | ||||||||||||||
{Field: "include_deleted", Detail: "Must be a valid boolean"}, | ||||||||||||||
}, | ||||||||||||||
}) | ||||||||||||||
return | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
workspace, err := api.Database.GetWorkspaceByOwnerIDAndName(r.Context(), database.GetWorkspaceByOwnerIDAndNameParams{ | ||||||||||||||
OwnerID: owner.ID, | ||||||||||||||
Name: workspaceName, | ||||||||||||||
}) | ||||||||||||||
if includeDeleted && errors.Is(err, sql.ErrNoRows) { | ||||||||||||||
workspace, err = api.Database.GetWorkspaceByOwnerIDAndName(r.Context(), database.GetWorkspaceByOwnerIDAndNameParams{ | ||||||||||||||
OwnerID: owner.ID, | ||||||||||||||
Name: workspaceName, | ||||||||||||||
Deleted: includeDeleted, | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this works as intended. The param here in the SQL matches for So if you set this to true, the workspace will not show if the workspace is deleted. We will need to update the SQL too, or just always return deleted workspaces by default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See how it's handled here: Lines 57 to 62 in 454aea7
I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Emyrk Hmm, testing it in the UI seems to work.
In either case, if we get nothing back, we then go into the Let me know if I'm misunderstanding your comment! |
||||||||||||||
}) | ||||||||||||||
} | ||||||||||||||
if errors.Is(err, sql.ErrNoRows) { | ||||||||||||||
// Do not leak information if the workspace exists or not | ||||||||||||||
httpapi.Forbidden(rw) | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍