From 665441ec49eceb5dbbf150814b3fecccdbef5e9a Mon Sep 17 00:00:00 2001 From: Danielle Maywood Date: Tue, 20 May 2025 11:14:50 +0000 Subject: [PATCH 1/2] fix(coderd/notifications): only show reason if present for workspace autoupdated Fixes https://github.com/coder/coder/issues/17930 Update the `WorkspaceAutoUpdated` notification to only display the reason if it is present. --- ...00328_fix_workspace_update_reason.down.sql | 4 + .../000328_fix_workspace_update_reason.up.sql | 4 + coderd/notifications/notifications_test.go | 13 ++++ ...WorkspaceAutoUpdated_NoMessage.html.golden | 78 +++++++++++++++++++ ...WorkspaceAutoUpdated_NoMessage.json.golden | 29 +++++++ 5 files changed, 128 insertions(+) create mode 100644 coderd/database/migrations/000328_fix_workspace_update_reason.down.sql create mode 100644 coderd/database/migrations/000328_fix_workspace_update_reason.up.sql create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated_NoMessage.html.golden create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated_NoMessage.json.golden diff --git a/coderd/database/migrations/000328_fix_workspace_update_reason.down.sql b/coderd/database/migrations/000328_fix_workspace_update_reason.down.sql new file mode 100644 index 0000000000000..ccc76c1cb9425 --- /dev/null +++ b/coderd/database/migrations/000328_fix_workspace_update_reason.down.sql @@ -0,0 +1,4 @@ +UPDATE notification_templates +SET body_template = E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).\n\n' || + E'Reason for update: **{{.Labels.template_version_message}}**.' +WHERE id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; diff --git a/coderd/database/migrations/000328_fix_workspace_update_reason.up.sql b/coderd/database/migrations/000328_fix_workspace_update_reason.up.sql new file mode 100644 index 0000000000000..4d90a3d2f8a9b --- /dev/null +++ b/coderd/database/migrations/000328_fix_workspace_update_reason.up.sql @@ -0,0 +1,4 @@ +UPDATE notification_templates +SET body_template = E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).' || + E'{{if .Labels.template_version_message}}\n\nReason for update: **{{.Labels.template_version_message}}**.{{end}}' +WHERE id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 8f8a3c82441e0..353460c723fe6 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -845,6 +845,19 @@ func TestNotificationTemplates_Golden(t *testing.T) { }, }, }, + { + name: "TemplateWorkspaceAutoUpdated_NoMessage", + id: notifications.TemplateWorkspaceAutoUpdated, + payload: types.MessagePayload{ + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", + Labels: map[string]string{ + "name": "bobby-workspace", + "template_version_name": "1.0", + }, + }, + }, { name: "TemplateWorkspaceMarkedForDeletion", id: notifications.TemplateWorkspaceMarkedForDeletion, diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated_NoMessage.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated_NoMessage.html.golden new file mode 100644 index 0000000000000..6aef0a83516d6 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated_NoMessage.html.golden @@ -0,0 +1,78 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Workspace "bobby-workspace" updated automatically +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 has been updated automatically to the latest= + template version (1.0). + + +View workspace: http://test.com/@bobby/bobby-workspace + +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Workspace "bobby-workspace" updated automatically + + +
+
+ 3D"Cod= +
+

+ Workspace "bobby-workspace" updated automatically +

+
+

Hi Bobby,

+

Your workspace bobby-workspace has been updated= + automatically to the latest template version (1.0).

+
+
+ =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/TemplateWorkspaceAutoUpdated_NoMessage.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated_NoMessage.json.golden new file mode 100644 index 0000000000000..eb03da0557b4c --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated_NoMessage.json.golden @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "00000000-0000-0000-0000-000000000000", + "payload": { + "_version": "1.2", + "notification_name": "Workspace Updated Automatically", + "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": { + "name": "bobby-workspace", + "template_version_name": "1.0" + }, + "data": null, + "targets": null + }, + "title": "Workspace \"bobby-workspace\" updated automatically", + "title_markdown": "Workspace \"bobby-workspace\" updated automatically", + "body": "Your workspace bobby-workspace has been updated automatically to the latest template version (1.0).", + "body_markdown": "Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0)." +} \ No newline at end of file From 5fb0a5b7279a837da672479f494248b74d263a00 Mon Sep 17 00:00:00 2001 From: Danielle Maywood Date: Tue, 20 May 2025 14:05:16 +0000 Subject: [PATCH 2/2] chore: change approach --- coderd/autobuild/lifecycle_executor.go | 7 +- ...00328_fix_workspace_update_reason.down.sql | 4 - .../000328_fix_workspace_update_reason.up.sql | 4 - coderd/notifications/notifications_test.go | 13 ---- ...WorkspaceAutoUpdated_NoMessage.html.golden | 78 ------------------- ...WorkspaceAutoUpdated_NoMessage.json.golden | 29 ------- 6 files changed, 6 insertions(+), 129 deletions(-) delete mode 100644 coderd/database/migrations/000328_fix_workspace_update_reason.down.sql delete mode 100644 coderd/database/migrations/000328_fix_workspace_update_reason.up.sql delete mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated_NoMessage.html.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated_NoMessage.json.golden diff --git a/coderd/autobuild/lifecycle_executor.go b/coderd/autobuild/lifecycle_executor.go index cc4e48b43544c..eedcc812bb19c 100644 --- a/coderd/autobuild/lifecycle_executor.go +++ b/coderd/autobuild/lifecycle_executor.go @@ -349,13 +349,18 @@ func (e *Executor) runOnce(t time.Time) Stats { nextBuildReason = string(nextBuild.Reason) } + templateVersionMessage := activeTemplateVersion.Message + if templateVersionMessage == "" { + templateVersionMessage = "None provided" + } + if _, err := e.notificationsEnqueuer.Enqueue(e.ctx, ws.OwnerID, notifications.TemplateWorkspaceAutoUpdated, map[string]string{ "name": ws.Name, "initiator": "autobuild", "reason": nextBuildReason, "template_version_name": activeTemplateVersion.Name, - "template_version_message": activeTemplateVersion.Message, + "template_version_message": templateVersionMessage, }, "autobuild", // Associate this notification with all the related entities. ws.ID, ws.OwnerID, ws.TemplateID, ws.OrganizationID, diff --git a/coderd/database/migrations/000328_fix_workspace_update_reason.down.sql b/coderd/database/migrations/000328_fix_workspace_update_reason.down.sql deleted file mode 100644 index ccc76c1cb9425..0000000000000 --- a/coderd/database/migrations/000328_fix_workspace_update_reason.down.sql +++ /dev/null @@ -1,4 +0,0 @@ -UPDATE notification_templates -SET body_template = E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).\n\n' || - E'Reason for update: **{{.Labels.template_version_message}}**.' -WHERE id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; diff --git a/coderd/database/migrations/000328_fix_workspace_update_reason.up.sql b/coderd/database/migrations/000328_fix_workspace_update_reason.up.sql deleted file mode 100644 index 4d90a3d2f8a9b..0000000000000 --- a/coderd/database/migrations/000328_fix_workspace_update_reason.up.sql +++ /dev/null @@ -1,4 +0,0 @@ -UPDATE notification_templates -SET body_template = E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).' || - E'{{if .Labels.template_version_message}}\n\nReason for update: **{{.Labels.template_version_message}}**.{{end}}' -WHERE id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 353460c723fe6..8f8a3c82441e0 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -845,19 +845,6 @@ func TestNotificationTemplates_Golden(t *testing.T) { }, }, }, - { - name: "TemplateWorkspaceAutoUpdated_NoMessage", - id: notifications.TemplateWorkspaceAutoUpdated, - payload: types.MessagePayload{ - UserName: "Bobby", - UserEmail: "bobby@coder.com", - UserUsername: "bobby", - Labels: map[string]string{ - "name": "bobby-workspace", - "template_version_name": "1.0", - }, - }, - }, { name: "TemplateWorkspaceMarkedForDeletion", id: notifications.TemplateWorkspaceMarkedForDeletion, diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated_NoMessage.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated_NoMessage.html.golden deleted file mode 100644 index 6aef0a83516d6..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated_NoMessage.html.golden +++ /dev/null @@ -1,78 +0,0 @@ -From: system@coder.com -To: bobby@coder.com -Subject: Workspace "bobby-workspace" updated automatically -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 has been updated automatically to the latest= - template version (1.0). - - -View workspace: http://test.com/@bobby/bobby-workspace - ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 -Content-Transfer-Encoding: quoted-printable -Content-Type: text/html; charset=UTF-8 - - - - - - - Workspace "bobby-workspace" updated automatically - - -
-
- 3D"Cod= -
-

- Workspace "bobby-workspace" updated automatically -

-
-

Hi Bobby,

-

Your workspace bobby-workspace has been updated= - automatically to the latest template version (1.0).

-
-
- =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/TemplateWorkspaceAutoUpdated_NoMessage.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated_NoMessage.json.golden deleted file mode 100644 index eb03da0557b4c..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated_NoMessage.json.golden +++ /dev/null @@ -1,29 +0,0 @@ -{ - "_version": "1.1", - "msg_id": "00000000-0000-0000-0000-000000000000", - "payload": { - "_version": "1.2", - "notification_name": "Workspace Updated Automatically", - "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": { - "name": "bobby-workspace", - "template_version_name": "1.0" - }, - "data": null, - "targets": null - }, - "title": "Workspace \"bobby-workspace\" updated automatically", - "title_markdown": "Workspace \"bobby-workspace\" updated automatically", - "body": "Your workspace bobby-workspace has been updated automatically to the latest template version (1.0).", - "body_markdown": "Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0)." -} \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy