From 2f6f8b9520fefc098e0397e16285b9444e2fdf91 Mon Sep 17 00:00:00 2001 From: Jon Ayers Date: Tue, 23 Jun 2026 10:16:17 -0500 Subject: [PATCH] feat: add workspace autostop reminder template (#26429) --- coderd/inboxnotifications.go | 1 + coderd/notifications/events.go | 1 + coderd/notifications/notifications_test.go | 13 +++ ...plateWorkspaceAutostopReminder.html.golden | 82 +++++++++++++++++++ ...plateWorkspaceAutostopReminder.json.golden | 29 +++++++ docs/admin/monitoring/notifications/index.md | 1 + 6 files changed, 127 insertions(+) create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutostopReminder.html.golden create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutostopReminder.json.golden diff --git a/coderd/inboxnotifications.go b/coderd/inboxnotifications.go index 0ff8b8ce42..c18748fb9d 100644 --- a/coderd/inboxnotifications.go +++ b/coderd/inboxnotifications.go @@ -37,6 +37,7 @@ var fallbackIcons = map[uuid.UUID]string{ notifications.TemplateWorkspaceDormant: codersdk.InboxNotificationFallbackIconWorkspace, notifications.TemplateWorkspaceAutoUpdated: codersdk.InboxNotificationFallbackIconWorkspace, notifications.TemplateWorkspaceMarkedForDeletion: codersdk.InboxNotificationFallbackIconWorkspace, + notifications.TemplateWorkspaceAutostopReminder: codersdk.InboxNotificationFallbackIconWorkspace, notifications.TemplateWorkspaceManualBuildFailed: codersdk.InboxNotificationFallbackIconWorkspace, notifications.TemplateWorkspaceOutOfMemory: codersdk.InboxNotificationFallbackIconWorkspace, notifications.TemplateWorkspaceOutOfDisk: codersdk.InboxNotificationFallbackIconWorkspace, diff --git a/coderd/notifications/events.go b/coderd/notifications/events.go index 46063d97c6..f586df9fa4 100644 --- a/coderd/notifications/events.go +++ b/coderd/notifications/events.go @@ -15,6 +15,7 @@ var ( TemplateWorkspaceDormant = uuid.MustParse("0ea69165-ec14-4314-91f1-69566ac3c5a0") TemplateWorkspaceAutoUpdated = uuid.MustParse("c34a0c09-0704-4cac-bd1c-0c0146811c2b") TemplateWorkspaceMarkedForDeletion = uuid.MustParse("51ce2fdf-c9ca-4be1-8d70-628674f9bc42") + TemplateWorkspaceAutostopReminder = uuid.MustParse("6f6cb984-c167-4fa5-bb87-1058dd642779") TemplateWorkspaceManualBuildFailed = uuid.MustParse("2faeee0f-26cb-4e96-821c-85ccb9f71513") TemplateWorkspaceOutOfMemory = uuid.MustParse("a9d027b4-ac49-4fb1-9f6d-45af15f64e7a") TemplateWorkspaceOutOfDisk = uuid.MustParse("f047f6a3-5713-40f7-85aa-0394cce9fa3a") diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 036dd5c096..aaceb4fe3c 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -843,6 +843,19 @@ func TestNotificationTemplates_Golden(t *testing.T) { }, }, }, + { + name: "TemplateWorkspaceAutostopReminder", + id: notifications.TemplateWorkspaceAutostopReminder, + payload: types.MessagePayload{ + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", + Labels: map[string]string{ + "workspace": "bobby-workspace", + "deadline": "2024-03-15 14:00 UTC", + }, + }, + }, { name: "TemplateUserAccountCreated", id: notifications.TemplateUserAccountCreated, diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutostopReminder.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutostopReminder.html.golden new file mode 100644 index 0000000000..5de6e57afd --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutostopReminder.html.golden @@ -0,0 +1,82 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Your workspace "bobby-workspace" will stop soon +Message-Id: 02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:06 +0000 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +MIME-Version: 1.0 + +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +Your workspace bobby-workspace is scheduled to automatically stop at 2024-0= +3-15 14:00 UTC. + +Connect to it or extend the deadline to keep it running. + + +View workspace: http://test.com/@bobby/bobby-workspace + +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Your workspace "bobby-workspace" will stop soon + + +
+
+ 3D"Cod= +
+

+ Your workspace "bobby-workspace" will stop soon +

+
+

Hi Bobby,

+

Your workspace bobby-workspace is scheduled to = +automatically stop at 2024-03-15 14:00 UTC.

+ +

Connect to it or extend the deadline to keep it running.

+
+
+ =20 + + View workspace + + =20 +
+
+

© 2024 Coder. All rights reserved - h= +ttp://test.com

+

Click here to manage your notification = +settings

+

Stop receiving emails like this

+
+
+ + + +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutostopReminder.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutostopReminder.json.golden new file mode 100644 index 0000000000..5adad98d69 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutostopReminder.json.golden @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "00000000-0000-0000-0000-000000000000", + "payload": { + "_version": "1.2", + "notification_name": "Workspace Autostop Reminder", + "notification_template_id": "00000000-0000-0000-0000-000000000000", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View workspace", + "url": "http://test.com/@bobby/bobby-workspace" + } + ], + "labels": { + "deadline": "2024-03-15 14:00 UTC", + "workspace": "bobby-workspace" + }, + "data": null, + "targets": null + }, + "title": "Your workspace \"bobby-workspace\" will stop soon", + "title_markdown": "Your workspace \"bobby-workspace\" will stop soon", + "body": "Your workspace bobby-workspace is scheduled to automatically stop at 2024-03-15 14:00 UTC.\n\nConnect to it or extend the deadline to keep it running.", + "body_markdown": "Your workspace **bobby-workspace** is scheduled to automatically stop at 2024-03-15 14:00 UTC.\n\nConnect to it or extend the deadline to keep it running." +} \ No newline at end of file diff --git a/docs/admin/monitoring/notifications/index.md b/docs/admin/monitoring/notifications/index.md index 4abbe547aa..e965166802 100644 --- a/docs/admin/monitoring/notifications/index.md +++ b/docs/admin/monitoring/notifications/index.md @@ -51,6 +51,7 @@ These notifications are sent to users themselves: These notifications are sent to the workspace owner: - Workspace automatic build failure +- Workspace autostop reminder - Workspace created - Workspace deleted - Workspace manual build failure