Skip to content

Commit d8e00c2

Browse files
committed
feat(coderd/notifications): provide additional context to workspace notifications
1 parent 98e7501 commit d8e00c2

8 files changed

+44
-14
lines changed
Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,103 @@
1+
-- https://github.com/coder/coder/issues/14893
2+
3+
-- UserAccountSuspended
14
UPDATE notification_templates
25
SET
3-
body_template = E'Hi {{.UserName}},\n\n' ||
6+
body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n
47
E'User account **{{.Labels.suspended_account_name}}** has been suspended.\n\n' ||
8+
-- Mention the real name of the user who suspended the account:
59
E'The newly suspended account belongs to **{{.Labels.suspended_account_user_name}}** and was suspended by **{{.Labels.account_suspender_user_name}}**.'
610
WHERE
711
id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d';
812

13+
-- YourAccountSuspended
914
UPDATE notification_templates
1015
SET
11-
body_template = E'Hi {{.UserName}},\n\n' ||
16+
body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n
17+
-- Mention who suspended the account:
1218
E'Your account **{{.Labels.suspended_account_name}}** has been suspended by **{{.Labels.account_suspender_user_name}}**'
1319
WHERE
1420
id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff';
1521

22+
-- UserAccountActivated
1623
UPDATE notification_templates
1724
SET
18-
body_template = E'Hi {{.UserName}},\n\n' ||
25+
body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n
1926
E'User account **{{.Labels.activated_account_name}}** has been activated.\n\n' ||
27+
-- Mention the real name of the user who activated the account:
2028
E'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.'
2129
WHERE
2230
id = '9f5af851-8408-4e73-a7a1-c6502ba46689';
2331

32+
-- YourAccountActivated
2433
UPDATE notification_templates
2534
SET
26-
body_template = E'Hi {{.UserName}},\n\n' ||
35+
body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n
36+
-- Mention who activated the account:
2737
E'Your account **{{.Labels.activated_account_name}}** has been activated by **{{.Labels.account_activator_user_name}}**.'
2838
WHERE
2939
id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4';
3040

41+
-- UserAccountCreated
3142
UPDATE notification_templates
3243
SET
3344
body_template = E'Hi {{.UserName}},\n\n' ||
3445
E'New user account **{{.Labels.created_account_name}}** has been created.\n\n' ||
46+
-- Mention the real name of the user who created the account:
3547
E'This new user account was created for **{{.Labels.created_account_user_name}}** by **{{.Labels.account_creator}}**'
3648
WHERE
3749
id = '4e19c0ac-94e1-4532-9515-d1801aa283b2';
3850

51+
-- UserAccountDeleted
3952
UPDATE notification_templates
4053
SET
4154
body_template = E'Hi {{.UserName}},\n\n' ||
4255
E'User account **{{.Labels.deleted_account_name}}** has been deleted.\n\n' ||
56+
-- Mention the real name of the user who deleted the account:
4357
E'The deleted account belonged to **{{.Labels.deleted_account_user_name}}** and was deleted by **{{.Labels.account_deleter_user_name}}**.'
4458
WHERE
4559
id = 'f44d9314-ad03-4bc8-95d0-5cad491da6b6';
4660

61+
-- TemplateDeleted
4762
UPDATE notification_templates
4863
SET
49-
body_template = E'Hi {{.UserName}}\n\n' ||
64+
body_template = E'Hi {{.UserName}}i,\n\n' || -- Add a comma
5065
E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.\n\n' ||
51-
E'The templates display name was **{{.Labels.display_name}}**.'
66+
-- Mention template display name:
67+
E'The template''s display name was **{{.Labels.display_name}}**.'
5268
WHERE
5369
id = '29a09665-2a4c-403f-9648-54301670e7be';
5470

71+
-- WorkspaceAutoUpdated
5572
UPDATE notification_templates
56-
SET body_template = E'Hi {{.UserName}}\n\n' ||
73+
SET body_template = E'Hi {{.UserName}},\n\n' || -- Add a comma and a \n
74+
-- Add a \n:
5775
E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).\n\n' ||
5876
E'Reason for update: **{{.Labels.template_version_message}}**'
5977
WHERE
6078
id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b';
6179

80+
-- WorkspaceAutoBuildFailed
6281
UPDATE notification_templates
6382
SET
64-
body_template = E'Hi {{.UserName}}\n\n' ||
83+
body_template = E'Hi {{.UserName}},\n\n' || -- Add a comma
84+
-- Add a \n after:
6585
E'Automatic build of your workspace **{{.Labels.name}}** failed.\n\n' ||
6686
E'The specified reason was "**{{.Labels.reason}}**".'
6787
WHERE
6888
id = '381df2a9-c0c0-4749-420f-80a9280c66f9';
6989

90+
-- WorkspaceDeleted
7091
UPDATE notification_templates
7192
SET
72-
body_template = E'Hi {{.UserName}},\n\n' ||
93+
body_template = E'Hi {{.UserName}},\n\n' || -- Add a comma
94+
-- Add a \n after:
7395
E'Your workspace **{{.Labels.name}}** was deleted.\n\n' ||
7496
E'The specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".'
7597
WHERE
7698
id = 'f517da0b-cdc9-410f-ab89-a86107c420ed';
7799

100+
-- WorkspaceDormant
78101
UPDATE notification_templates
79102
SET
80103
body_template = E'Hi {{.UserName}}\n\n,' || -- add comma
@@ -84,6 +107,7 @@ SET
84107
WHERE
85108
id = '0ea69165-ec14-4314-91f1-69566ac3c5a0';
86109

110+
-- WorkspaceMarkedForDeletion
87111
UPDATE notification_templates
88112
SET
89113
body_template = E'Hi {{.UserName}}\n\n,' || -- add comma
@@ -92,10 +116,13 @@ SET
92116
WHERE
93117
id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42';
94118

119+
-- WorkspaceManualBuildFailed
95120
UPDATE notification_templates
96121
SET
97122
body_template = E'Hi {{.UserName}},\n\n' ||
98123
E'A manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\n\n' ||
124+
-- Mention template display name:
125+
E'The template''s display name was **{{.Labels.template_display_name}}**.' ||
99126
E'The workspace build was initiated by **{{.Labels.initiator}}**.'
100127
WHERE
101128
id = '2faeee0f-26cb-4e96-821c-85ccb9f71513';

coderd/notifications/notifications_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ func TestNotificationTemplates_Golden(t *testing.T) {
846846
Labels: map[string]string{
847847
"name": "bobby-workspace",
848848
"template_name": "bobby-template",
849+
"template_display_name": "William's Template",
849850
"template_version_name": "bobby-template-version",
850851
"initiator": "joe",
851852
"workspace_owner_username": "mrbobby",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Hi Bobby
1+
Hi Bobbyi,
22

33
The template **bobby-template** was deleted by **rob**.
44

5-
The templates display name was **Bobby's Template**.
5+
The template's display name was **Bobby's Template**.

coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Hi Bobby
1+
Hi Bobby,
22

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

coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Hi Bobby
1+
Hi Bobby,
22

33
Automatic build of your workspace **bobby-workspace** failed.
44

coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Hi Bobby,
22

33
A manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).
44

5-
The workspace build was initiated by **joe**.
5+
The template's display name was **William's Template**.The workspace build was initiated by **joe**.

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,7 @@ func (s *server) notifyWorkspaceManualBuildFailed(ctx context.Context, workspace
11281128
map[string]string{
11291129
"name": workspace.Name,
11301130
"template_name": template.Name,
1131+
"template_display_name": template.DisplayName,
11311132
"template_version_name": templateVersion.Name,
11321133
"initiator": build.InitiatorByUsername,
11331134
"workspace_owner_username": workspaceOwner.Username,

coderd/provisionerdserver/provisionerdserver_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,7 @@ func TestNotifications(t *testing.T) {
18601860
assert.Contains(t, notifEnq.Sent[0].Targets, user.ID)
18611861
assert.Equal(t, workspace.Name, notifEnq.Sent[0].Labels["name"])
18621862
assert.Equal(t, template.Name, notifEnq.Sent[0].Labels["template_name"])
1863+
assert.Equal(t, template.DisplayName, notifEnq.Sent[0].Labels["template_display_name"])
18631864
assert.Equal(t, version.Name, notifEnq.Sent[0].Labels["template_version_name"])
18641865
assert.Equal(t, user.Username, notifEnq.Sent[0].Labels["initiator"])
18651866
assert.Equal(t, user.Username, notifEnq.Sent[0].Labels["workspace_owner_username"])

0 commit comments

Comments
 (0)