Skip to content
Prev Previous commit
Next Next commit
add task deleted filter
  • Loading branch information
johnstcn committed Nov 3, 2025
commit cdeebf8b9bd016541cad6ed0e4659c33bedae360
4 changes: 2 additions & 2 deletions coderd/database/dbauthz/dbauthz.go
Original file line number Diff line number Diff line change
Expand Up @@ -2989,8 +2989,8 @@ func (q *querier) GetTaskByID(ctx context.Context, id uuid.UUID) (database.Task,
return fetch(q.log, q.auth, q.db.GetTaskByID)(ctx, id)
}

func (q *querier) GetTaskByOwnerIDAndName(ctx context.Context, arg database.GetTaskByOwnerIDAndNameParams) (database.Task, error) {
return fetch(q.log, q.auth, q.db.GetTaskByOwnerIDAndName)(ctx, arg)
func (q *querier) GetTaskByOwnerIDAndName(ctx context.Context, arg database.GetTaskByOwnerIDAndNameParams) ([]database.Task, error) {
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.GetTaskByOwnerIDAndName)(ctx, arg)
}

func (q *querier) GetTaskByWorkspaceID(ctx context.Context, workspaceID uuid.UUID) (database.Task, error) {
Expand Down
1 change: 1 addition & 0 deletions coderd/database/dbauthz/dbauthz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,7 @@ func (s *MethodTestSuite) TestTasks() {
dbm.EXPECT().GetTaskByOwnerIDAndName(gomock.Any(), database.GetTaskByOwnerIDAndNameParams{
OwnerID: task.OwnerID,
Name: task.Name,
Deleted: false,
}).Return(task, nil).AnyTimes()
check.Args(database.GetTaskByOwnerIDAndNameParams{
OwnerID: task.OwnerID,
Expand Down
2 changes: 1 addition & 1 deletion coderd/database/dbmetrics/querymetrics.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions coderd/database/dbmock/dbmock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion coderd/database/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 51 additions & 29 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions coderd/database/queries/tasks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ SELECT * FROM tasks_with_status WHERE id = @id::uuid;
-- name: GetTaskByWorkspaceID :one
SELECT * FROM tasks_with_status WHERE workspace_id = @workspace_id::uuid;

-- name: GetTaskByOwnerIDAndName :one
SELECT * FROM tasks_with_status
WHERE owner_id = @owner_id::uuid
AND LOWER(name) = LOWER(@name::text);
-- name: GetTaskByOwnerIDAndName :many
SELECT * FROM tasks_with_status
WHERE
owner_id = @owner_id::uuid
AND CASE WHEN @deleted
THEN deleted_at IS NOT NULL
ELSE deleted_at IS NULL
END
AND LOWER(name) = LOWER(@name::text);

-- name: ListTasks :many
SELECT * FROM tasks_with_status tws
Expand Down
6 changes: 5 additions & 1 deletion coderd/httpmw/taskparam.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,13 @@ func fetchTaskWithFallback(ctx context.Context, db database.Store, taskParam str
task, err := db.GetTaskByOwnerIDAndName(ctx, database.GetTaskByOwnerIDAndNameParams{
OwnerID: ownerID,
Name: taskParam,
Deleted: false,
})
if err != nil {
return database.Task{}, xerrors.Errorf("fetch task by name: %w", err)
}
return task, nil
if len(task) == 0 {
return database.Task{}, sql.ErrNoRows
}
return task[0], nil
}
Loading