mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(coderd): show correct deletion time in dormancy notification (#26488)
The dormancy notification's "will be automatically deleted in X" sentence rendered the dormancy threshold instead of the auto-delete duration. A 30-day threshold rendered as "4 weeks" even when auto-delete was 90 days; a 60-day threshold rendered as "1 month" with a 7-day auto-delete. Render the countdown from the auto-delete setting, and skip the deletion sentence entirely when auto-delete is disabled so the notification no longer promises a deletion that will never happen.
This commit is contained in:
+13
-18
@@ -1448,29 +1448,24 @@ func (api *API) putWorkspaceDormant(rw http.ResponseWriter, r *http.Request) {
|
||||
)
|
||||
}
|
||||
|
||||
tmpl, tmplErr := api.Database.GetTemplateByID(ctx, newWorkspace.TemplateID)
|
||||
if tmplErr != nil {
|
||||
api.Logger.Warn(
|
||||
ctx,
|
||||
"failed to fetch the template of the workspace marked as dormant",
|
||||
slog.Error(err),
|
||||
slog.F("workspace_id", newWorkspace.ID),
|
||||
slog.F("template_id", newWorkspace.TemplateID),
|
||||
)
|
||||
}
|
||||
|
||||
if initiatorErr == nil && tmplErr == nil {
|
||||
dormantTime := dbtime.Time(now).Add(time.Duration(tmpl.TimeTilDormant))
|
||||
if initiatorErr == nil {
|
||||
labels := map[string]string{
|
||||
"name": newWorkspace.Name,
|
||||
"reason": "a " + initiator.Username + " request",
|
||||
}
|
||||
// DeletingAt is set by the UPDATE only when the template's
|
||||
// time_til_dormant_autodelete is non-zero, so skip the label when
|
||||
// auto-delete is disabled so the body omits the deletion
|
||||
// timeline.
|
||||
if newWorkspace.DeletingAt.Valid {
|
||||
labels["timeTilDelete"] = humanize.Time(newWorkspace.DeletingAt.Time)
|
||||
}
|
||||
_, err = api.NotificationsEnqueuer.Enqueue(
|
||||
// nolint:gocritic // Need notifier actor to enqueue notifications
|
||||
dbauthz.AsNotifier(ctx),
|
||||
newWorkspace.OwnerID,
|
||||
notifications.TemplateWorkspaceDormant,
|
||||
map[string]string{
|
||||
"name": newWorkspace.Name,
|
||||
"reason": "a " + initiator.Username + " request",
|
||||
"timeTilDormant": humanize.Time(dormantTime),
|
||||
},
|
||||
labels,
|
||||
"api",
|
||||
newWorkspace.ID,
|
||||
newWorkspace.OwnerID,
|
||||
|
||||
Reference in New Issue
Block a user