Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitefccece

Browse files
committed
restore list ?q query param
1 parentb015123 commitefccece

File tree

10 files changed

+297
-77
lines changed

10 files changed

+297
-77
lines changed

‎cli/exp_task_delete_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func TestExpTaskDelete(t *testing.T) {
5656
taskID:=uuid.MustParse(id1)
5757
returnfunc(w http.ResponseWriter,r*http.Request) {
5858
switch {
59-
caser.Method==http.MethodGet&&r.URL.Path=="/api/experimental/tasks"&&r.URL.Query().Get("owner")=="me":
59+
caser.Method==http.MethodGet&&r.URL.Path=="/api/experimental/tasks"&&r.URL.Query().Get("q")=="owner:\"me\"":
6060
c.nameResolves.Add(1)
6161
httpapi.Write(r.Context(),w,http.StatusOK,struct {
6262
Tasks []codersdk.Task`json:"tasks"`
@@ -110,7 +110,7 @@ func TestExpTaskDelete(t *testing.T) {
110110
firstID:=uuid.MustParse(id3)
111111
returnfunc(w http.ResponseWriter,r*http.Request) {
112112
switch {
113-
caser.Method==http.MethodGet&&r.URL.Path=="/api/experimental/tasks"&&r.URL.Query().Get("owner")=="me":
113+
caser.Method==http.MethodGet&&r.URL.Path=="/api/experimental/tasks"&&r.URL.Query().Get("q")=="owner:\"me\"":
114114
c.nameResolves.Add(1)
115115
httpapi.Write(r.Context(),w,http.StatusOK,struct {
116116
Tasks []codersdk.Task`json:"tasks"`
@@ -151,7 +151,7 @@ func TestExpTaskDelete(t *testing.T) {
151151
buildHandler:func(_*testCounters) http.HandlerFunc {
152152
returnfunc(w http.ResponseWriter,r*http.Request) {
153153
switch {
154-
caser.Method==http.MethodGet&&r.URL.Path=="/api/experimental/tasks"&&r.URL.Query().Get("owner")=="me":
154+
caser.Method==http.MethodGet&&r.URL.Path=="/api/experimental/tasks"&&r.URL.Query().Get("q")=="owner:\"me\"":
155155
httpapi.Write(r.Context(),w,http.StatusOK,struct {
156156
Tasks []codersdk.Task`json:"tasks"`
157157
Countint`json:"count"`
@@ -174,7 +174,7 @@ func TestExpTaskDelete(t *testing.T) {
174174
taskID:=uuid.MustParse(id5)
175175
returnfunc(w http.ResponseWriter,r*http.Request) {
176176
switch {
177-
caser.Method==http.MethodGet&&r.URL.Path=="/api/experimental/tasks"&&r.URL.Query().Get("owner")=="me":
177+
caser.Method==http.MethodGet&&r.URL.Path=="/api/experimental/tasks"&&r.URL.Query().Get("q")=="owner:\"me\"":
178178
c.nameResolves.Add(1)
179179
httpapi.Write(r.Context(),w,http.StatusOK,struct {
180180
Tasks []codersdk.Task`json:"tasks"`

‎cli/exp_task_status_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func Test_TaskStatus(t *testing.T) {
3737
returnfunc(w http.ResponseWriter,r*http.Request) {
3838
switchr.URL.Path {
3939
case"/api/experimental/tasks":
40-
ifr.URL.Query().Get("owner")=="me" {
40+
ifr.URL.Query().Get("q")=="owner:\"me\"" {
4141
httpapi.Write(ctx,w,http.StatusOK,struct {
4242
Tasks []codersdk.Task`json:"tasks"`
4343
Countint`json:"count"`
@@ -61,7 +61,7 @@ func Test_TaskStatus(t *testing.T) {
6161
returnfunc(w http.ResponseWriter,r*http.Request) {
6262
switchr.URL.Path {
6363
case"/api/experimental/tasks":
64-
ifr.URL.Query().Get("owner")=="me" {
64+
ifr.URL.Query().Get("q")=="owner:\"me\"" {
6565
httpapi.Write(ctx,w,http.StatusOK,struct {
6666
Tasks []codersdk.Task`json:"tasks"`
6767
Countint`json:"count"`
@@ -125,7 +125,7 @@ STATE CHANGED STATUS HEALTHY STATE MESSAGE
125125
returnfunc(w http.ResponseWriter,r*http.Request) {
126126
switchr.URL.Path {
127127
case"/api/experimental/tasks":
128-
ifr.URL.Query().Get("owner")=="me" {
128+
ifr.URL.Query().Get("q")=="owner:\"me\"" {
129129
// Return initial task state for --watch test
130130
httpapi.Write(ctx,w,http.StatusOK,struct {
131131
Tasks []codersdk.Task`json:"tasks"`
@@ -263,7 +263,7 @@ STATE CHANGED STATUS HEALTHY STATE MESSAGE
263263
returnfunc(w http.ResponseWriter,r*http.Request) {
264264
switchr.URL.Path {
265265
case"/api/experimental/tasks":
266-
ifr.URL.Query().Get("owner")=="me" {
266+
ifr.URL.Query().Get("q")=="owner:\"me\"" {
267267
httpapi.Write(ctx,w,http.StatusOK,struct {
268268
Tasks []codersdk.Task`json:"tasks"`
269269
Countint`json:"count"`

‎coderd/aitasks.go‎

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/coder/coder/v2/coderd/httpmw"
2323
"github.com/coder/coder/v2/coderd/rbac"
2424
"github.com/coder/coder/v2/coderd/rbac/policy"
25+
"github.com/coder/coder/v2/coderd/searchquery"
2526
"github.com/coder/coder/v2/coderd/taskname"
2627
"github.com/coder/coder/v2/codersdk"
2728

@@ -372,8 +373,7 @@ type tasksListResponse struct {
372373
// @ID list-tasks
373374
// @Security CoderSessionToken
374375
// @Tags Experimental
375-
// @Param owner query string false "Filter by owner (username, UUID, or 'me' for current user)"
376-
// @Param status query string false "Filter by task status (pending, initializing, active, paused, error, unknown)"
376+
// @Param q query string false "Search query for filtering tasks. Supports: owner:<username/uuid/me>, organization:<org-name/uuid>, status:<status>"
377377
// @Success 200 {object} coderd.tasksListResponse
378378
// @Router /api/experimental/tasks [get]
379379
//
@@ -384,47 +384,18 @@ func (api *API) tasksList(rw http.ResponseWriter, r *http.Request) {
384384
apiKey:=httpmw.APIKey(r)
385385

386386
// Parse query parameters for filtering tasks.
387-
ownerParam:=r.URL.Query().Get("owner")
388-
statusParam:=r.URL.Query().Get("status")
389-
390-
// Determine owner ID based on the owner parameter.
391-
varownerID uuid.UUID
392-
switchownerParam {
393-
casecodersdk.Me:
394-
ownerID=apiKey.UserID
395-
case"":
396-
// If ownerID is not set, list all tasks the user has access to.
397-
default:
398-
// Try to parse as UUID first.
399-
parsedUUID,err:=uuid.Parse(ownerParam)
400-
iferr==nil {
401-
ownerID=parsedUUID
402-
}elseiferr!=nil {
403-
// Otherwise, look up by username.
404-
user,err:=api.Database.GetUserByEmailOrUsername(ctx, database.GetUserByEmailOrUsernameParams{
405-
Username:ownerParam,
406-
})
407-
iferr!=nil {
408-
ifhttpapi.Is404Error(err) {
409-
httpapi.ResourceNotFound(rw)
410-
return
411-
}
412-
httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{
413-
Message:"Internal error fetching user.",
414-
Detail:err.Error(),
415-
})
416-
return
417-
}
418-
ownerID=user.ID
419-
}
387+
queryStr:=r.URL.Query().Get("q")
388+
filter,errs:=searchquery.Tasks(ctx,api.Database,queryStr,apiKey.UserID)
389+
iflen(errs)>0 {
390+
httpapi.Write(ctx,rw,http.StatusBadRequest, codersdk.Response{
391+
Message:"Invalid task search query.",
392+
Validations:errs,
393+
})
394+
return
420395
}
421396

422397
// Fetch all tasks matching the filters from the database.
423-
dbTasks,err:=api.Database.ListTasks(ctx, database.ListTasksParams{
424-
OwnerID:ownerID,
425-
OrganizationID:uuid.Nil,// TODO(mafredri): ?
426-
Status:statusParam,
427-
})
398+
dbTasks,err:=api.Database.ListTasks(ctx,filter)
428399
iferr!=nil {
429400
httpapi.Write(ctx,rw,http.StatusInternalServerError, codersdk.Response{
430401
Message:"Internal error fetching tasks.",

‎coderd/apidoc/docs.go‎

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json‎

Lines changed: 2 additions & 8 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/searchquery/search.go‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,43 @@ func AIBridgeInterceptions(ctx context.Context, db database.Store, query string,
391391
returnfilter,parser.Errors
392392
}
393393

394+
// Tasks parses a search query for tasks.
395+
//
396+
// Supported query parameters:
397+
// - owner: string (username, UUID, or 'me' for current user)
398+
// - organization: string (organization UUID or name)
399+
// - status: string (pending, initializing, active, paused, error, unknown)
400+
funcTasks(ctx context.Context,db database.Store,querystring,actorID uuid.UUID) (database.ListTasksParams, []codersdk.ValidationError) {
401+
filter:= database.ListTasksParams{
402+
OwnerID:uuid.Nil,
403+
OrganizationID:uuid.Nil,
404+
Status:"",
405+
}
406+
407+
ifquery=="" {
408+
returnfilter,nil
409+
}
410+
411+
// Always lowercase for all searches.
412+
query=strings.ToLower(query)
413+
values,errors:=searchTerms(query,func(termstring,values url.Values)error {
414+
// Default unqualified terms to owner
415+
values.Add("owner",term)
416+
returnnil
417+
})
418+
iflen(errors)>0 {
419+
returnfilter,errors
420+
}
421+
422+
parser:=httpapi.NewQueryParamParser()
423+
filter.OwnerID=parseUser(ctx,db,parser,values,"owner",actorID)
424+
filter.OrganizationID=parseOrganization(ctx,db,parser,values,"organization")
425+
filter.Status=parser.String(values,"","status")
426+
427+
parser.ErrorExcessParams(values)
428+
returnfilter,parser.Errors
429+
}
430+
394431
funcsearchTerms(querystring,defaultKeyfunc(termstring,values url.Values)error) (url.Values, []codersdk.ValidationError) {
395432
searchValues:=make(url.Values)
396433

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp