@Summary Invalidate presets for template @ID invalidate-presets-for-template @Security CoderSessionToken @Produce json @Tags Enterprise @Param template path string true "Template ID" format(uuid) @Success 200 {object} codersdk.InvalidatePresetsResponse @Router /api/v2/templates/{template}/prebuilds/
(rw http.ResponseWriter, r *http.Request)
| 375 | // @Success 200 {object} codersdk.InvalidatePresetsResponse |
| 376 | // @Router /api/v2/templates/{template}/prebuilds/invalidate [post] |
| 377 | func (api *API) postInvalidateTemplatePresets(rw http.ResponseWriter, r *http.Request) { |
| 378 | ctx := r.Context() |
| 379 | template := httpmw.TemplateParam(r) |
| 380 | |
| 381 | // Authorization: user must be able to update the template |
| 382 | if !api.Authorize(r, policy.ActionUpdate, template) { |
| 383 | httpapi.ResourceNotFound(rw) |
| 384 | return |
| 385 | } |
| 386 | |
| 387 | // Update last_invalidated_at for all presets of the active template version |
| 388 | invalidatedPresets, err := api.Database.UpdatePresetsLastInvalidatedAt(ctx, database.UpdatePresetsLastInvalidatedAtParams{ |
| 389 | TemplateID: template.ID, |
| 390 | LastInvalidatedAt: sql.NullTime{Time: api.Clock.Now(), Valid: true}, |
| 391 | }) |
| 392 | if err != nil { |
| 393 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 394 | Message: "Failed to invalidate presets.", |
| 395 | Detail: err.Error(), |
| 396 | }) |
| 397 | return |
| 398 | } |
| 399 | |
| 400 | api.Logger.Info(ctx, "invalidated presets", |
| 401 | slog.F("template_id", template.ID), |
| 402 | slog.F("template_name", template.Name), |
| 403 | slog.F("preset_count", len(invalidatedPresets)), |
| 404 | ) |
| 405 | |
| 406 | invalidated := db2sdk.InvalidatedPresets(invalidatedPresets) |
| 407 | if invalidated == nil { |
| 408 | invalidated = []codersdk.InvalidatedPreset{} // need to avoid nil value |
| 409 | } |
| 410 | |
| 411 | httpapi.Write(ctx, rw, http.StatusOK, codersdk.InvalidatePresetsResponse{ |
| 412 | Invalidated: invalidated, |
| 413 | }) |
| 414 | } |
nothing calls this directly
no test coverage detected