Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d02269

Browse files
authored
feat(coderd/notifications): improve notification format consistency (#14967)
This Pull request addresses the more trivial items in#14893.These were simple formatting changes that I was able to fix despitelimited context.Some more changes are required for which I will have to dig a bit deeperinto how the template contexts are populated. I'm happy to add those tothis PR or create a subsequent PR.
1 parent26df33a commit9d02269

File tree

24 files changed

+366
-60
lines changed

24 files changed

+366
-60
lines changed

‎Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ update-golden-files: \
667667
enterprise/tailnet/testdata/.gen-golden\
668668
tailnet/testdata/.gen-golden\
669669
coderd/.gen-golden\
670+
coderd/notifications/.gen-golden\
670671
provisioner/terraform/testdata/.gen-golden
671672
.PHONY: update-golden-files
672673

@@ -698,6 +699,10 @@ coderd/.gen-golden: $(wildcard coderd/testdata/*/*.golden) $(GO_SRC_FILES) $(wil
698699
gotest ./coderd -run="Test.*Golden$$" -update
699700
touch"$@"
700701

702+
coderd/notifications/.gen-golden:$(wildcard coderd/notifications/testdata/*/*.golden)$(GO_SRC_FILES)$(wildcard coderd/notifications/*_test.go)
703+
gotest ./coderd/notifications -run="Test.*Golden$$" -update
704+
touch"$@"
705+
701706
provisioner/terraform/testdata/.gen-golden:$(wildcard provisioner/terraform/testdata/*/*.golden)$(GO_SRC_FILES)$(wildcard provisioner/terraform/*_test.go)
702707
gotest ./provisioner/terraform -run="Test.*Golden$$" -update
703708
touch"$@"
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
UPDATE notification_templates
2+
SET
3+
body_template= E'Hi {{.UserName}},\nUser account **{{.Labels.suspended_account_name}}** has been suspended.'
4+
WHERE
5+
id='b02ddd82-4733-4d02-a2d7-c36f3598997d';
6+
7+
UPDATE notification_templates
8+
SET
9+
body_template= E'Hi {{.UserName}},\nYour account **{{.Labels.suspended_account_name}}** has been suspended.'
10+
WHERE
11+
id='6a2f0609-9b69-4d36-a989-9f5925b6cbff';
12+
13+
UPDATE notification_templates
14+
SET
15+
body_template= E'Hi {{.UserName}},\nUser account **{{.Labels.activated_account_name}}** has been activated.'
16+
WHERE
17+
id='9f5af851-8408-4e73-a7a1-c6502ba46689';
18+
19+
UPDATE notification_templates
20+
SET
21+
body_template= E'Hi {{.UserName}},\nYour account **{{.Labels.activated_account_name}}** has been activated.'
22+
WHERE
23+
id='1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4';
24+
25+
UPDATE notification_templates
26+
SET
27+
body_template= E'Hi {{.UserName}},\n\New user account **{{.Labels.created_account_name}}** has been created.'
28+
WHERE
29+
id='4e19c0ac-94e1-4532-9515-d1801aa283b2';
30+
31+
UPDATE notification_templates
32+
SET
33+
body_template= E'Hi {{.UserName}},\n\nUser account **{{.Labels.deleted_account_name}}** has been deleted.'
34+
WHERE
35+
id='f44d9314-ad03-4bc8-95d0-5cad491da6b6';
36+
37+
UPDATE notification_templates
38+
SET
39+
body_template= E'Hi {{.UserName}}\n\n'||
40+
E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.'
41+
WHERE
42+
id='29a09665-2a4c-403f-9648-54301670e7be';
43+
44+
UPDATE notification_templates
45+
SET body_template= E'Hi {{.UserName}}\n'||
46+
E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).\n'||
47+
E'Reason for update: **{{.Labels.template_version_message}}**'
48+
WHERE
49+
id='c34a0c09-0704-4cac-bd1c-0c0146811c2b';
50+
51+
UPDATE notification_templates
52+
SET
53+
body_template= E'Hi {{.UserName}}\n\nYour workspace **{{.Labels.name}}** was deleted.\nThe specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".'
54+
WHERE
55+
id='381df2a9-c0c0-4749-420f-80a9280c66f9';
56+
57+
UPDATE notification_templates
58+
SET
59+
body_template= E'Hi {{.UserName}}\n\nYour workspace **{{.Labels.name}}** was deleted.\nThe specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".'
60+
WHERE
61+
id='f517da0b-cdc9-410f-ab89-a86107c420ed';
62+
63+
UPDATE notification_templates
64+
SET
65+
body_template= E'Hi {{.UserName}}\n\n'||
66+
E'Your workspace **{{.Labels.name}}** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of {{.Labels.reason}}.\n'||
67+
E'Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after {{.Labels.timeTilDormant}} of inactivity.\n'||
68+
E'To prevent deletion, use your workspace with the link below.'
69+
WHERE
70+
id='0ea69165-ec14-4314-91f1-69566ac3c5a0';
71+
72+
UPDATE notification_templates
73+
SET
74+
body_template= E'Hi {{.UserName}}\n\n'||
75+
E'Your workspace **{{.Labels.name}}** has been marked for **deletion** after {{.Labels.timeTilDormant}} of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of {{.Labels.reason}}.\n'||
76+
E'To prevent deletion, use your workspace with the link below.'
77+
WHERE
78+
id='51ce2fdf-c9ca-4be1-8d70-628674f9bc42';
79+
80+
UPDATE notification_templates
81+
SET
82+
body_template= E'Hi {{.UserName}},\n\nA manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\nThe workspace build was initiated by **{{.Labels.initiator}}**.'
83+
WHERE
84+
id='2faeee0f-26cb-4e96-821c-85ccb9f71513';
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
-- https://github.com/coder/coder/issues/14893
2+
3+
-- UserAccountSuspended
4+
UPDATE notification_templates
5+
SET
6+
body_template= E'Hi {{.UserName}},\n\n'||-- Add a \n
7+
E'User account **{{.Labels.suspended_account_name}}** has been suspended.\n\n'||
8+
-- Mention the real name of the user who suspended the account:
9+
E'The newly suspended account belongs to **{{.Labels.suspended_account_user_name}}** and was suspended by **{{.Labels.account_suspender_user_name}}**.'
10+
WHERE
11+
id='b02ddd82-4733-4d02-a2d7-c36f3598997d';
12+
13+
-- YourAccountSuspended
14+
UPDATE notification_templates
15+
SET
16+
body_template= E'Hi {{.UserName}},\n\n'||-- Add a \n
17+
-- Mention who suspended the account:
18+
E'Your account **{{.Labels.suspended_account_name}}** has been suspended by **{{.Labels.account_suspender_user_name}}**.'
19+
WHERE
20+
id='6a2f0609-9b69-4d36-a989-9f5925b6cbff';
21+
22+
-- UserAccountActivated
23+
UPDATE notification_templates
24+
SET
25+
body_template= E'Hi {{.UserName}},\n\n'||-- Add a \n
26+
E'User account **{{.Labels.activated_account_name}}** has been activated.\n\n'||
27+
-- Mention the real name of the user who activated the account:
28+
E'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.'
29+
WHERE
30+
id='9f5af851-8408-4e73-a7a1-c6502ba46689';
31+
32+
-- YourAccountActivated
33+
UPDATE notification_templates
34+
SET
35+
body_template= E'Hi {{.UserName}},\n\n'||-- Add a \n
36+
-- Mention who activated the account:
37+
E'Your account **{{.Labels.activated_account_name}}** has been activated by **{{.Labels.account_activator_user_name}}**.'
38+
WHERE
39+
id='1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4';
40+
41+
-- UserAccountCreated
42+
UPDATE notification_templates
43+
SET
44+
body_template= E'Hi {{.UserName}},\n\n'||
45+
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:
47+
E'This new user account was created for **{{.Labels.created_account_user_name}}** by **{{.Labels.account_creator}}**.'
48+
WHERE
49+
id='4e19c0ac-94e1-4532-9515-d1801aa283b2';
50+
51+
-- UserAccountDeleted
52+
UPDATE notification_templates
53+
SET
54+
body_template= E'Hi {{.UserName}},\n\n'||
55+
E'User account **{{.Labels.deleted_account_name}}** has been deleted.\n\n'||
56+
-- Mention the real name of the user who deleted the account:
57+
E'The deleted account belonged to **{{.Labels.deleted_account_user_name}}** and was deleted by **{{.Labels.account_deleter_user_name}}**.'
58+
WHERE
59+
id='f44d9314-ad03-4bc8-95d0-5cad491da6b6';
60+
61+
-- TemplateDeleted
62+
UPDATE notification_templates
63+
SET
64+
body_template= E'Hi {{.UserName}},\n\n'||-- Add a comma
65+
E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.\n\n'||
66+
-- Mention template display name:
67+
E'The template''s display name was **{{.Labels.display_name}}**.'
68+
WHERE
69+
id='29a09665-2a4c-403f-9648-54301670e7be';
70+
71+
-- WorkspaceAutoUpdated
72+
UPDATE notification_templates
73+
SET body_template= E'Hi {{.UserName}},\n\n'||-- Add a comma and a \n
74+
-- Add a \n:
75+
E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).\n\n'||
76+
E'Reason for update: **{{.Labels.template_version_message}}**.'
77+
WHERE
78+
id='c34a0c09-0704-4cac-bd1c-0c0146811c2b';
79+
80+
-- WorkspaceAutoBuildFailed
81+
UPDATE notification_templates
82+
SET
83+
body_template= E'Hi {{.UserName}},\n\n'||-- Add a comma
84+
-- Add a \n after:
85+
E'Automatic build of your workspace **{{.Labels.name}}** failed.\n\n'||
86+
E'The specified reason was "**{{.Labels.reason}}**".'
87+
WHERE
88+
id='381df2a9-c0c0-4749-420f-80a9280c66f9';
89+
90+
-- WorkspaceDeleted
91+
UPDATE notification_templates
92+
SET
93+
body_template= E'Hi {{.UserName}},\n\n'||-- Add a comma
94+
-- Add a \n after:
95+
E'Your workspace **{{.Labels.name}}** was deleted.\n\n'||
96+
E'The specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".'
97+
WHERE
98+
id='f517da0b-cdc9-410f-ab89-a86107c420ed';
99+
100+
-- WorkspaceDormant
101+
UPDATE notification_templates
102+
SET
103+
body_template= E'Hi {{.UserName}},\n\n'||-- add comma
104+
E'Your workspace **{{.Labels.name}}** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of {{.Labels.reason}}.\n'||
105+
E'Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after {{.Labels.timeTilDormant}} of inactivity.\n'||
106+
E'To prevent deletion, use your workspace with the link below.'
107+
WHERE
108+
id='0ea69165-ec14-4314-91f1-69566ac3c5a0';
109+
110+
-- WorkspaceMarkedForDeletion
111+
UPDATE notification_templates
112+
SET
113+
body_template= E'Hi {{.UserName}},\n\n'||-- add comma
114+
E'Your workspace **{{.Labels.name}}** has been marked for **deletion** after {{.Labels.timeTilDormant}} of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of {{.Labels.reason}}.\n'||
115+
E'To prevent deletion, use your workspace with the link below.'
116+
WHERE
117+
id='51ce2fdf-c9ca-4be1-8d70-628674f9bc42';
118+
119+
-- WorkspaceManualBuildFailed
120+
UPDATE notification_templates
121+
SET
122+
body_template= E'Hi {{.UserName}},\n\n'||
123+
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}}**.'||
126+
E'The workspace build was initiated by **{{.Labels.initiator}}**.'
127+
WHERE
128+
id='2faeee0f-26cb-4e96-821c-85ccb9f71513';

‎coderd/notifications/notifications_test.go

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ func enumerateAllTemplates(t *testing.T) ([]string, error) {
684684
returnout,nil
685685
}
686686

687-
funcTestNotificationTemplatesCanRender(t*testing.T) {
687+
funcTestNotificationTemplates_Golden(t*testing.T) {
688688
t.Parallel()
689689

690690
if!dbtestutil.WillUsePostgres() {
@@ -764,7 +764,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
764764
payload: types.MessagePayload{
765765
UserName:"Bobby",
766766
Labels:map[string]string{
767-
"created_account_name":"bobby",
767+
"created_account_name":"bobby",
768+
"created_account_user_name":"William Tables",
769+
"account_creator":"rob",
768770
},
769771
},
770772
},
@@ -774,7 +776,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
774776
payload: types.MessagePayload{
775777
UserName:"Bobby",
776778
Labels:map[string]string{
777-
"deleted_account_name":"bobby",
779+
"deleted_account_name":"bobby",
780+
"deleted_account_user_name":"william tables",
781+
"account_deleter_user_name":"rob",
778782
},
779783
},
780784
},
@@ -784,7 +788,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
784788
payload: types.MessagePayload{
785789
UserName:"Bobby",
786790
Labels:map[string]string{
787-
"suspended_account_name":"bobby",
791+
"suspended_account_name":"bobby",
792+
"suspended_account_user_name":"william tables",
793+
"account_suspender_user_name":"rob",
788794
},
789795
},
790796
},
@@ -794,7 +800,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
794800
payload: types.MessagePayload{
795801
UserName:"Bobby",
796802
Labels:map[string]string{
797-
"activated_account_name":"bobby",
803+
"activated_account_name":"bobby",
804+
"activated_account_user_name":"william tables",
805+
"account_activator_user_name":"rob",
798806
},
799807
},
800808
},
@@ -804,7 +812,8 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
804812
payload: types.MessagePayload{
805813
UserName:"Bobby",
806814
Labels:map[string]string{
807-
"suspended_account_name":"bobby",
815+
"suspended_account_name":"bobby",
816+
"account_suspender_user_name":"rob",
808817
},
809818
},
810819
},
@@ -814,7 +823,8 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
814823
payload: types.MessagePayload{
815824
UserName:"Bobby",
816825
Labels:map[string]string{
817-
"activated_account_name":"bobby",
826+
"activated_account_name":"bobby",
827+
"account_activator_user_name":"rob",
818828
},
819829
},
820830
},
@@ -824,8 +834,9 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
824834
payload: types.MessagePayload{
825835
UserName:"Bobby",
826836
Labels:map[string]string{
827-
"name":"bobby-template",
828-
"initiator":"rob",
837+
"name":"bobby-template",
838+
"display_name":"Bobby's Template",
839+
"initiator":"rob",
829840
},
830841
},
831842
},
@@ -837,6 +848,7 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
837848
Labels:map[string]string{
838849
"name":"bobby-workspace",
839850
"template_name":"bobby-template",
851+
"template_display_name":"William's Template",
840852
"template_version_name":"bobby-template-version",
841853
"initiator":"joe",
842854
"workspace_owner_username":"mrbobby",
@@ -960,13 +972,15 @@ func TestNotificationTemplatesCanRender(t *testing.T) {
960972
return
961973
}
962974

975+
consthint="run\"DB=ci make update-golden-files\" and commit the changes"
976+
963977
wantBody,err:=os.ReadFile(bodyGoldenFile)
964-
require.NoError(t,err,"open goldenfile, run\"DB=ci make update-golden-files\" and commit the changes")
978+
require.NoError(t,err,fmt.Sprintf("missing goldennotification body file. %s",hint))
965979
wantTitle,err:=os.ReadFile(titleGoldenFile)
966-
require.NoError(t,err,"open goldenfile, run\"DB=ci make update-golden-files\" and commit the changes")
980+
require.NoError(t,err,fmt.Sprintf("missing goldennotification title file. %s",hint))
967981

968-
require.Equal(t,string(wantBody),body,"bodyshould be equal")
969-
require.Equal(t,string(wantTitle),title,"titleshould be equal")
982+
require.Equal(t,string(wantBody),body,fmt.Sprintf("rendered templatebodydoes not match golden file. If this is expected, %s",hint))
983+
require.Equal(t,string(wantTitle),title,fmt.Sprintf("rendered templatetitledoes not match golden file. If this is expected, %s",hint))
970984
})
971985
}
972986
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
Hi Bobby
1+
Hi Bobby,
22

3-
The template **bobby-template** was deleted by **rob**.
3+
The template **bobby-template** was deleted by **rob**.
4+
5+
The template's display name was **Bobby's Template**.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
Hi Bobby,
2-
User account **bobby** has been activated.
2+
3+
User account **bobby** has been activated.
4+
5+
The newly activated account belongs to **william tables** and was activated by **rob**.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Hi Bobby,
22

3-
New user account **bobby** has been created.
3+
New user account **bobby** has been created.
4+
5+
This new user account was created for **William Tables** by **rob**.
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
Hi Bobby,
22

3-
User account **bobby** has been deleted.
3+
User account **bobby** has been deleted.
4+
5+
The deleted account belonged to **william tables** and was deleted by **rob**.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
Hi Bobby,
2-
User account **bobby** has been suspended.
2+
3+
User account **bobby** has been suspended.
4+
5+
The newly suspended account belongs to **william tables** and was suspended by **rob**.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp