Skip to content

chore: allow search by build params in workspace search filter #12694

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

Merged
merged 11 commits into from
Mar 22, 2024
49 changes: 49 additions & 0 deletions coderd/database/dbmem/dbmem.go
Original file line number Diff line number Diff line change
Expand Up @@ -8118,6 +8118,55 @@ func (q *FakeQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg database.
continue
}

if len(arg.HasParam) > 0 || len(arg.ParamNames) > 0 {
build, err := q.getLatestWorkspaceBuildByWorkspaceIDNoLock(ctx, workspace.ID)
if err != nil {
return nil, xerrors.Errorf("get latest build: %w", err)
}

params := make([]database.WorkspaceBuildParameter, 0)
for _, param := range q.workspaceBuildParameters {
if param.WorkspaceBuildID != build.ID {
continue
}
params = append(params, param)
}

var innerErr error
index := slices.IndexFunc(params, func(buildParam database.WorkspaceBuildParameter) bool {
// If hasParam matches, then we are done. This is a good match.
if slices.ContainsFunc(arg.HasParam, func(name string) bool {
return strings.EqualFold(buildParam.Name, name)
}) {
return true
}

// Check name + value
match := false
for i := range arg.ParamNames {
matchName := arg.ParamNames[i]
if !strings.EqualFold(matchName, buildParam.Name) {
continue
}

matchValue := arg.ParamValues[i]
if !strings.EqualFold(matchValue, buildParam.Value) {
continue
}
match = true
break
}

return match
})
if innerErr != nil {
return nil, xerrors.Errorf("error searching workspace build params: %w", innerErr)
}
if index < 0 {
continue
}
}

if arg.OwnerUsername != "" {
owner, err := q.getUserByIDNoLock(workspace.OwnerID)
if err == nil && !strings.EqualFold(arg.OwnerUsername, owner.Username) {
Expand Down
3 changes: 3 additions & 0 deletions coderd/database/modelqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,12 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
// The name comment is for metric tracking
query := fmt.Sprintf("-- name: GetAuthorizedWorkspaces :many\n%s", filtered)
rows, err := q.db.QueryContext(ctx, query,
pq.Array(arg.ParamNames),
pq.Array(arg.ParamValues),
arg.Deleted,
arg.Status,
arg.OwnerID,
pq.Array(arg.HasParam),
arg.OwnerUsername,
arg.TemplateName,
pq.Array(arg.TemplateIDs),
Expand Down
3 changes: 3 additions & 0 deletions coderd/database/querier.go

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

128 changes: 89 additions & 39 deletions coderd/database/queries.sql.go

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

Loading