mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
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:
@ -487,6 +487,9 @@ func (api *API) postTemplateByOrganization(rw http.ResponseWriter, r *http.Reque
|
||||
}
|
||||
|
||||
// @Summary Get templates by organization
|
||||
// @Description Returns a list of templates for the specified organization.
|
||||
// @Description By default, only non-deprecated templates are returned.
|
||||
// @Description To include deprecated templates, specify `deprecated:true` in the search query.
|
||||
// @ID get-templates-by-organization
|
||||
// @Security CoderSessionToken
|
||||
// @Produce json
|
||||
@ -506,6 +509,9 @@ func (api *API) templatesByOrganization() http.HandlerFunc {
|
||||
}
|
||||
|
||||
// @Summary Get all templates
|
||||
// @Description Returns a list of templates.
|
||||
// @Description By default, only non-deprecated templates are returned.
|
||||
// @Description To include deprecated templates, specify `deprecated:true` in the search query.
|
||||
// @ID get-all-templates
|
||||
// @Security CoderSessionToken
|
||||
// @Produce json
|
||||
@ -540,6 +546,14 @@ func (api *API) fetchTemplates(mutate func(r *http.Request, arg *database.GetTem
|
||||
mutate(r, &args)
|
||||
}
|
||||
|
||||
// By default, deprecated templates are excluded unless explicitly requested
|
||||
if !args.Deprecated.Valid {
|
||||
args.Deprecated = sql.NullBool{
|
||||
Bool: false,
|
||||
Valid: true,
|
||||
}
|
||||
}
|
||||
|
||||
// Filter templates based on rbac permissions
|
||||
templates, err := api.Database.GetAuthorizedTemplates(ctx, args, prepared)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
|
Reference in New Issue
Block a user