mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Workspaces filtering (#1972)
Co-authored-by: G r e y <grey@coder.com> Co-authored-by: Kira Pilot <kira@coder.com>
This commit is contained in:
co-authored by
G r e y
Kira Pilot
parent
ac6cb269db
commit
8b03e2b0e1
+10
-13
@@ -137,17 +137,14 @@ func (api *API) workspaces(rw http.ResponseWriter, r *http.Request) {
|
||||
// Empty strings mean no filter
|
||||
orgFilter := r.URL.Query().Get("organization_id")
|
||||
ownerFilter := r.URL.Query().Get("owner")
|
||||
nameFilter := r.URL.Query().Get("name")
|
||||
|
||||
filter := database.GetWorkspacesWithFilterParams{Deleted: false}
|
||||
if orgFilter != "" {
|
||||
orgID, err := uuid.Parse(orgFilter)
|
||||
if err != nil {
|
||||
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
|
||||
Message: fmt.Sprintf("organization_id must be a uuid: %s", err.Error()),
|
||||
})
|
||||
return
|
||||
if err == nil {
|
||||
filter.OrganizationID = orgID
|
||||
}
|
||||
filter.OrganizationID = orgID
|
||||
}
|
||||
if ownerFilter == "me" {
|
||||
filter.OwnerID = apiKey.UserID
|
||||
@@ -160,15 +157,15 @@ func (api *API) workspaces(rw http.ResponseWriter, r *http.Request) {
|
||||
Username: ownerFilter,
|
||||
Email: ownerFilter,
|
||||
})
|
||||
if err != nil {
|
||||
httpapi.Write(rw, http.StatusBadRequest, httpapi.Response{
|
||||
Message: "owner must be a uuid or username",
|
||||
})
|
||||
return
|
||||
if err == nil {
|
||||
filter.OwnerID = user.ID
|
||||
}
|
||||
userID = user.ID
|
||||
} else {
|
||||
filter.OwnerID = userID
|
||||
}
|
||||
filter.OwnerID = userID
|
||||
}
|
||||
if nameFilter != "" {
|
||||
filter.Name = nameFilter
|
||||
}
|
||||
|
||||
workspaces, err := api.Database.GetWorkspacesWithFilter(r.Context(), filter)
|
||||
|
||||
Reference in New Issue
Block a user