fix(coderd): list templates returns non-deprecated templates by default (#17747)

## Description

Modifies the behaviour of the "list templates" API endpoints to return
non-deprecated templates by default. Users can still query for
deprecated templates by specifying the `deprecated=true` query
parameter.

**Note:** The deprecation feature is an enterprise-level feature

## Affected Endpoints
* /api/v2/organizations/{organization}/templates
* /api/v2/templates

Fixes #17565
This commit is contained in:
Susana Ferreira
2025-05-13 12:44:46 +01:00
committed by GitHub
parent 7f056da088
commit 599bb35a04
6 changed files with 329 additions and 1 deletions

View File

@ -1380,6 +1380,12 @@ func (q *FakeQuerier) getProvisionerJobsByIDsWithQueuePositionLockedGlobalQueue(
return jobs, nil
}
// isDeprecated returns true if the template is deprecated.
// A template is considered deprecated when it has a deprecation message.
func isDeprecated(template database.Template) bool {
return template.Deprecated != ""
}
func (*FakeQuerier) AcquireLock(_ context.Context, _ int64) error {
return xerrors.New("AcquireLock must only be called within a transaction")
}
@ -13023,7 +13029,17 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G
if arg.ExactName != "" && !strings.EqualFold(template.Name, arg.ExactName) {
continue
}
if arg.Deprecated.Valid && arg.Deprecated.Bool == (template.Deprecated != "") {
// Filters templates based on the search query filter 'Deprecated' status
// Matching SQL logic:
// -- Filter by deprecated
// AND CASE
// WHEN :deprecated IS NOT NULL THEN
// CASE
// WHEN :deprecated THEN deprecated != ''
// ELSE deprecated = ''
// END
// ELSE true
if arg.Deprecated.Valid && arg.Deprecated.Bool != isDeprecated(template) {
continue
}
if arg.FuzzyName != "" {