From 70f34867f1818a3f4002891b0bdfc89130271faa Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Thu, 3 Oct 2024 18:14:50 +0000 Subject: [PATCH 01/44] feat(notifications): Improve notification format consistency --- ...61_improve_notification_templates.down.sql | 83 +++++++++++++++++++ ...0261_improve_notification_templates.up.sql | 83 +++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 coderd/database/migrations/000261_improve_notification_templates.down.sql create mode 100644 coderd/database/migrations/000261_improve_notification_templates.up.sql diff --git a/coderd/database/migrations/000261_improve_notification_templates.down.sql b/coderd/database/migrations/000261_improve_notification_templates.down.sql new file mode 100644 index 0000000000000..4690ac201338f --- /dev/null +++ b/coderd/database/migrations/000261_improve_notification_templates.down.sql @@ -0,0 +1,83 @@ +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text +WHERE + id = '29a09665-2a4c-403f-9648-54301670e7be'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text +WHERE + id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text +WHERE + id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}}')::text +WHERE + id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, '({{.Labels.template_version_name}}).\n\n', '({{.Labels.template_version_name}}).\n')::text +WHERE + id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}}')::text +WHERE + id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, '\nThe specified reason', 'The specified reason')::text +WHERE + id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text +WHERE + id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, '\nThe specified reason', 'The specified reason')::text +WHERE + id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text +WHERE + id = '0ea69165-ec14-4314-91f1-69566ac3c5a0'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text +WHERE + id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, '\nThe workspace build was initiated by', 'The workspace build was initiated by')::text +WHERE + id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text +WHERE + id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text +WHERE + id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; diff --git a/coderd/database/migrations/000261_improve_notification_templates.up.sql b/coderd/database/migrations/000261_improve_notification_templates.up.sql new file mode 100644 index 0000000000000..d8e8731cb0e08 --- /dev/null +++ b/coderd/database/migrations/000261_improve_notification_templates.up.sql @@ -0,0 +1,83 @@ +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text +WHERE + id = '29a09665-2a4c-403f-9648-54301670e7be'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}},\n')::text +WHERE + id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}},\n')::text +WHERE + id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},\n')::text +WHERE + id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, '({{.Labels.template_version_name}}).\n', '({{.Labels.template_version_name}}).\n\n')::text +WHERE + id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},\n')::text +WHERE + id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'The specified reason', '\nThe specified reason')::text +WHERE + id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text +WHERE + id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'The specified reason', '\nThe specified reason')::text +WHERE + id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text +WHERE + id = '0ea69165-ec14-4314-91f1-69566ac3c5a0'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text +WHERE + id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'The workspace build was initiated by', '\nThe workspace build was initiated by')::text +WHERE + id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}},\n')::text +WHERE + id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}},\n')::text +WHERE + id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; From 7e31a346a5122d7978152698cbc4be5be37074c6 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Sat, 5 Oct 2024 10:07:53 +0000 Subject: [PATCH 02/44] chore(coderd/notifications): regenerate notification testdata from the makefile --- Makefile | 5 +++++ coderd/notifications/notifications_test.go | 1 + 2 files changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 4bf7fb92639b0..b66bcf7396a1b 100644 --- a/Makefile +++ b/Makefile @@ -664,6 +664,7 @@ update-golden-files: \ enterprise/tailnet/testdata/.gen-golden \ tailnet/testdata/.gen-golden \ coderd/.gen-golden \ + coderd/notifications/.gen-golden \ provisioner/terraform/testdata/.gen-golden .PHONY: update-golden-files @@ -695,6 +696,10 @@ coderd/.gen-golden: $(wildcard coderd/testdata/*/*.golden) $(GO_SRC_FILES) $(wil go test ./coderd -run="Test.*Golden$$" -update touch "$@" +coderd/notifications/.gen-golden: $(wildcard coderd/notifications/testdata/*/*.golden) $(GO_SRC_FILES) $(wildcard coderd/notifications/*_test.go) + go test ./coderd/notifications -run="Test.*Golden$$" -update + touch "$@" + provisioner/terraform/testdata/.gen-golden: $(wildcard provisioner/terraform/testdata/*/*.golden) $(GO_SRC_FILES) $(wildcard provisioner/terraform/*_test.go) go test ./provisioner/terraform -run="Test.*Golden$$" -update touch "$@" diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index e52610c9c5823..e963575256492 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -685,6 +685,7 @@ func enumerateAllTemplates(t *testing.T) ([]string, error) { } func TestNotificationTemplatesCanRender(t *testing.T) { +func TestNotificationTemplates_Golden(t *testing.T) { t.Parallel() if !dbtestutil.WillUsePostgres() { From 4b85f2bb1441e4d71d482a10a59630e8c651ac76 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Sat, 5 Oct 2024 12:16:00 +0000 Subject: [PATCH 03/44] chore(coderd/database): renumber migration --- ...61_improve_notification_templates.down.sql | 83 ------------------- ...62_improve_notification_templates.down.sql | 83 +++++++++++++++++++ ...262_improve_notification_templates.up.sql} | 20 ++--- 3 files changed, 93 insertions(+), 93 deletions(-) delete mode 100644 coderd/database/migrations/000261_improve_notification_templates.down.sql create mode 100644 coderd/database/migrations/000262_improve_notification_templates.down.sql rename coderd/database/migrations/{000261_improve_notification_templates.up.sql => 000262_improve_notification_templates.up.sql} (81%) diff --git a/coderd/database/migrations/000261_improve_notification_templates.down.sql b/coderd/database/migrations/000261_improve_notification_templates.down.sql deleted file mode 100644 index 4690ac201338f..0000000000000 --- a/coderd/database/migrations/000261_improve_notification_templates.down.sql +++ /dev/null @@ -1,83 +0,0 @@ -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text -WHERE - id = '29a09665-2a4c-403f-9648-54301670e7be'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text -WHERE - id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text -WHERE - id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}}')::text -WHERE - id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, '({{.Labels.template_version_name}}).\n\n', '({{.Labels.template_version_name}}).\n')::text -WHERE - id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}}')::text -WHERE - id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, '\nThe specified reason', 'The specified reason')::text -WHERE - id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text -WHERE - id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, '\nThe specified reason', 'The specified reason')::text -WHERE - id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text -WHERE - id = '0ea69165-ec14-4314-91f1-69566ac3c5a0'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text -WHERE - id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, '\nThe workspace build was initiated by', 'The workspace build was initiated by')::text -WHERE - id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text -WHERE - id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text -WHERE - id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; diff --git a/coderd/database/migrations/000262_improve_notification_templates.down.sql b/coderd/database/migrations/000262_improve_notification_templates.down.sql new file mode 100644 index 0000000000000..0686d5334e36d --- /dev/null +++ b/coderd/database/migrations/000262_improve_notification_templates.down.sql @@ -0,0 +1,83 @@ +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text +WHERE + id = '29a09665-2a4c-403f-9648-54301670e7be'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', E'Hi {{.UserName}},')::text +WHERE + id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', E'Hi {{.UserName}},')::text +WHERE + id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', E'Hi {{.UserName}}')::text +WHERE + id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'({{.Labels.template_version_name}}).\n\n', E'({{.Labels.template_version_name}}).\n')::text +WHERE + id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', E'Hi {{.UserName}}')::text +WHERE + id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'\nThe specified reason', E'The specified reason')::text +WHERE + id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},', E'Hi {{.UserName}}')::text +WHERE + id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'\nThe specified reason', E'The specified reason')::text +WHERE + id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},', E'Hi {{.UserName}}')::text +WHERE + id = '0ea69165-ec14-4314-91f1-69566ac3c5a0'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},', E'Hi {{.UserName}}')::text +WHERE + id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'\nThe workspace build was initiated by', E'The workspace build was initiated by')::text +WHERE + id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text +WHERE + id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; + +UPDATE notification_templates +SET + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text +WHERE + id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; diff --git a/coderd/database/migrations/000261_improve_notification_templates.up.sql b/coderd/database/migrations/000262_improve_notification_templates.up.sql similarity index 81% rename from coderd/database/migrations/000261_improve_notification_templates.up.sql rename to coderd/database/migrations/000262_improve_notification_templates.up.sql index d8e8731cb0e08..d55ad2a6a537f 100644 --- a/coderd/database/migrations/000261_improve_notification_templates.up.sql +++ b/coderd/database/migrations/000262_improve_notification_templates.up.sql @@ -6,37 +6,37 @@ WHERE UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}},\n')::text + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text WHERE id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}},\n')::text + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text WHERE id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},\n')::text + body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', E'Hi {{.UserName}},\n')::text WHERE id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, '({{.Labels.template_version_name}}).\n', '({{.Labels.template_version_name}}).\n\n')::text + body_template = REPLACE(body_template::text, E'({{.Labels.template_version_name}}).\n', E'({{.Labels.template_version_name}}).\n\n')::text WHERE id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},\n')::text + body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', E'Hi {{.UserName}},\n')::text WHERE id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'The specified reason', '\nThe specified reason')::text + body_template = REPLACE(body_template::text, 'The specified reason', E'\nThe specified reason')::text WHERE id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; @@ -48,7 +48,7 @@ WHERE UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'The specified reason', '\nThe specified reason')::text + body_template = REPLACE(body_template::text, 'The specified reason', E'\nThe specified reason')::text WHERE id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; @@ -66,18 +66,18 @@ WHERE UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'The workspace build was initiated by', '\nThe workspace build was initiated by')::text + body_template = REPLACE(body_template::text, 'The workspace build was initiated by', E'\nThe workspace build was initiated by')::text WHERE id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}},\n')::text + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text WHERE id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}},\n')::text + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text WHERE id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; From e8ad3acd86846d99e0d1c191a758b046896e7395 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Sat, 5 Oct 2024 12:17:11 +0000 Subject: [PATCH 04/44] chore(coderd/notifications): regenerate testdata --- .../rendered-templates/TemplateTemplateDeleted-body.md.golden | 2 +- .../TemplateUserAccountActivated-body.md.golden | 1 + .../TemplateUserAccountSuspended-body.md.golden | 1 + .../TemplateWorkspaceAutoUpdated-body.md.golden | 4 +++- .../TemplateWorkspaceAutobuildFailed-body.md.golden | 4 +++- .../TemplateWorkspaceDeleted-body.md.golden | 3 ++- .../TemplateWorkspaceDormant-body.md.golden | 2 +- .../TemplateWorkspaceManualBuildFailed-body.md.golden | 1 + .../TemplateWorkspaceMarkedForDeletion-body.md.golden | 2 +- .../TemplateYourAccountActivated-body.md.golden | 1 + .../TemplateYourAccountSuspended-body.md.golden | 1 + 11 files changed, 16 insertions(+), 6 deletions(-) diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden index be3a61e695652..0af8a75131535 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden @@ -1,3 +1,3 @@ -Hi Bobby +Hi Bobby, The template **bobby-template** was deleted by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden index 2665a781492ea..a45de605b47f4 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden @@ -1,2 +1,3 @@ Hi Bobby, + User account **bobby** has been activated. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden index 70a43f2960ec0..def07959b59ff 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden @@ -1,2 +1,3 @@ Hi Bobby, + User account **bobby** has been suspended. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden index 79248150987c2..a2a16a7e9d179 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden @@ -1,3 +1,5 @@ -Hi Bobby +Hi Bobby, + Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0). + Reason for update: **template now includes catnip** \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden index 731f71f22ae88..cddf2149d0d46 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden @@ -1,3 +1,5 @@ -Hi Bobby +Hi Bobby, + Automatic build of your workspace **bobby-workspace** failed. + The specified reason was "**autostart**". \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden index 06aec5692465f..a5c71fb3e0170 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden @@ -1,4 +1,5 @@ -Hi Bobby +Hi Bobby, Your workspace **bobby-workspace** was deleted. + The specified reason was "**autodeleted due to dormancy (autobuild)**". \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden index aa10f4864cf24..35bfe8d2c19b6 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden @@ -1,4 +1,4 @@ -Hi Bobby +Hi Bobby, Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity. Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity. diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden index 45f8733dd2931..3989c1ee841fa 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden @@ -1,4 +1,5 @@ Hi Bobby, A manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**). + The workspace build was initiated by **joe**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden index 3d9fe99accd94..21defa7c1d500 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden @@ -1,4 +1,4 @@ -Hi Bobby +Hi Bobby, Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy. To prevent deletion, use your workspace with the link below. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden index 160fdc66e8990..36ea5a0d02139 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden @@ -1,2 +1,3 @@ Hi Bobby, + Your account **bobby** has been activated. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden index ce30139213bb0..5c138f639ef69 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden @@ -1,2 +1,3 @@ Hi Bobby, + Your account **bobby** has been suspended. \ No newline at end of file From 2a4d740fde9c3ff1e9ce4948c96fda4112d901f0 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Sat, 5 Oct 2024 12:33:34 +0000 Subject: [PATCH 05/44] fix(coderd/notifications): remove duplicate function signature --- coderd/notifications/notifications_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index ce3468b254a1c..62b94abde9a3b 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -684,7 +684,6 @@ func enumerateAllTemplates(t *testing.T) ([]string, error) { return out, nil } -func TestNotificationTemplatesCanRender(t *testing.T) { func TestNotificationTemplates_Golden(t *testing.T) { t.Parallel() From e741c434f10018f578d367bcd87f13864031a4a7 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Sat, 5 Oct 2024 12:57:28 +0000 Subject: [PATCH 06/44] chore: remove redundant escaping in migration --- ...62_improve_notification_templates.down.sql | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/coderd/database/migrations/000262_improve_notification_templates.down.sql b/coderd/database/migrations/000262_improve_notification_templates.down.sql index 0686d5334e36d..e4296aed2eee6 100644 --- a/coderd/database/migrations/000262_improve_notification_templates.down.sql +++ b/coderd/database/migrations/000262_improve_notification_templates.down.sql @@ -6,19 +6,19 @@ WHERE UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', E'Hi {{.UserName}},')::text + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text WHERE id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', E'Hi {{.UserName}},')::text + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text WHERE id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', E'Hi {{.UserName}}')::text + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}}')::text WHERE id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; @@ -30,43 +30,43 @@ WHERE UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', E'Hi {{.UserName}}')::text + body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}}')::text WHERE id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'\nThe specified reason', E'The specified reason')::text + body_template = REPLACE(body_template::text, E'\nThe specified reason', 'The specified reason')::text WHERE id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},', E'Hi {{.UserName}}')::text + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text WHERE id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'\nThe specified reason', E'The specified reason')::text + body_template = REPLACE(body_template::text, E'\nThe specified reason', 'The specified reason')::text WHERE id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},', E'Hi {{.UserName}}')::text + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text WHERE id = '0ea69165-ec14-4314-91f1-69566ac3c5a0'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},', E'Hi {{.UserName}}')::text + body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text WHERE id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'\nThe workspace build was initiated by', E'The workspace build was initiated by')::text + body_template = REPLACE(body_template::text, E'\nThe workspace build was initiated by', 'The workspace build was initiated by')::text WHERE id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; From adffe60de5c2464620705999266635c4c6b3a866 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Sat, 5 Oct 2024 16:24:21 +0000 Subject: [PATCH 07/44] chore(coderd/notifications): improve failed test feedback --- coderd/notifications/notifications_test.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 62b94abde9a3b..d22a7b02d1839 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -960,13 +960,15 @@ func TestNotificationTemplates_Golden(t *testing.T) { return } + hint := "run \"DB=ci make update-golden-files\" and commit the changes" + wantBody, err := os.ReadFile(bodyGoldenFile) - require.NoError(t, err, "open golden file, run \"DB=ci make update-golden-files\" and commit the changes") + require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) wantTitle, err := os.ReadFile(titleGoldenFile) - require.NoError(t, err, "open golden file, run \"DB=ci make update-golden-files\" and commit the changes") + require.NoError(t, err, fmt.Sprintf("missing golden notification title file. %s", hint)) - require.Equal(t, string(wantBody), body, "body should be equal") - require.Equal(t, string(wantTitle), title, "title should be equal") + require.Equal(t, string(wantBody), body, "rendered template body does not match golden file. If this is expected, %s", hint) + require.Equal(t, string(wantTitle), title, "rendered template title does not match golden file. If this is expected, %s", hint) }) } } From 41ed54af123fcd57b51da0e9c11bf9de4c73daf0 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Mon, 7 Oct 2024 07:35:32 +0000 Subject: [PATCH 08/44] feat(coderd/database): add new information to the account activated notification body template --- .../000262_improve_notification_templates.down.sql | 2 +- .../migrations/000262_improve_notification_templates.up.sql | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/coderd/database/migrations/000262_improve_notification_templates.down.sql b/coderd/database/migrations/000262_improve_notification_templates.down.sql index e4296aed2eee6..5a8f317ec7fe7 100644 --- a/coderd/database/migrations/000262_improve_notification_templates.down.sql +++ b/coderd/database/migrations/000262_improve_notification_templates.down.sql @@ -6,7 +6,7 @@ WHERE UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text +body_template = E'Hi {{.UserName}},\nUser account **{{.Labels.activated_account_name}}** has been activated.' WHERE id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; diff --git a/coderd/database/migrations/000262_improve_notification_templates.up.sql b/coderd/database/migrations/000262_improve_notification_templates.up.sql index d55ad2a6a537f..5f5b39800db46 100644 --- a/coderd/database/migrations/000262_improve_notification_templates.up.sql +++ b/coderd/database/migrations/000262_improve_notification_templates.up.sql @@ -6,9 +6,11 @@ WHERE UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text +body_template = E'Hi {{.UserName}},\n\n' + 'User account **{{.Labels.activated_account_name}}** has been activated. ' + 'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.' WHERE - id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; + id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; UPDATE notification_templates SET From fe94f0d172309fa3de1aca2f41b41bfeb0300000 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Tue, 8 Oct 2024 10:12:17 +0000 Subject: [PATCH 09/44] chore(coderd/database): rework migration for legibility --- ...62_improve_notification_templates.down.sql | 64 +++++++------- ...0262_improve_notification_templates.up.sql | 84 +++++++++++-------- coderd/notifications/notifications_test.go | 23 +++-- .../TemplateTemplateDeleted-body.md.golden | 6 +- ...emplateUserAccountActivated-body.md.golden | 4 +- .../TemplateUserAccountCreated-body.md.golden | 4 +- .../TemplateUserAccountDeleted-body.md.golden | 4 +- ...emplateUserAccountSuspended-body.md.golden | 4 +- ...emplateWorkspaceAutoUpdated-body.md.golden | 2 +- ...ateWorkspaceAutobuildFailed-body.md.golden | 2 +- .../TemplateWorkspaceDormant-body.md.golden | 4 +- ...eWorkspaceMarkedForDeletion-body.md.golden | 4 +- ...emplateYourAccountActivated-body.md.golden | 2 +- ...emplateYourAccountSuspended-body.md.golden | 2 +- 14 files changed, 122 insertions(+), 87 deletions(-) diff --git a/coderd/database/migrations/000262_improve_notification_templates.down.sql b/coderd/database/migrations/000262_improve_notification_templates.down.sql index 5a8f317ec7fe7..d7aeaaf54a487 100644 --- a/coderd/database/migrations/000262_improve_notification_templates.down.sql +++ b/coderd/database/migrations/000262_improve_notification_templates.down.sql @@ -1,83 +1,83 @@ UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text + body_template = E'Hi {{.UserName}},\nUser account **{{.Labels.suspended_account_name}}** has been suspended.' WHERE - id = '29a09665-2a4c-403f-9648-54301670e7be'; + id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; UPDATE notification_templates SET -body_template = E'Hi {{.UserName}},\nUser account **{{.Labels.activated_account_name}}** has been activated.' + body_template = E'Hi {{.UserName}},\nYour account **{{.Labels.suspended_account_name}}** has been suspended.' WHERE - id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; + id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text + body_template = E'Hi {{.UserName}},\nUser account **{{.Labels.activated_account_name}}** has been activated.' WHERE - id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; + id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}}')::text + body_template = E'Hi {{.UserName}},\nYour account **{{.Labels.activated_account_name}}** has been activated.' WHERE - id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'({{.Labels.template_version_name}}).\n\n', E'({{.Labels.template_version_name}}).\n')::text + body_template = E'Hi {{.UserName}},\n\New user account **{{.Labels.created_account_name}}** has been created.' WHERE - id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + id = '4e19c0ac-94e1-4532-9515-d1801aa283b2'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}}')::text + body_template = E'Hi {{.UserName}},\n\nUser account **{{.Labels.deleted_account_name}}** has been deleted.' WHERE - id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; + id = 'f44d9314-ad03-4bc8-95d0-5cad491da6b6'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'\nThe specified reason', 'The specified reason')::text + body_template = E'Hi {{.UserName}}\n\n' || + E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.' WHERE - id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; + id = '29a09665-2a4c-403f-9648-54301670e7be'; + +UPDATE notification_templates +SET body_template = E'Hi {{.UserName}}\n' || + E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).\n' || + E'Reason for update: **{{.Labels.template_version_message}}**' +WHERE id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text + body_template = E'Hi {{.UserName}}\n\nYour workspace **{{.Labels.name}}** was deleted.\nThe specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".' WHERE - id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; + id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'\nThe specified reason', 'The specified reason')::text + body_template = E'Hi {{.UserName}}\n\nYour workspace **{{.Labels.name}}** was deleted.\nThe specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".' WHERE id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text + body_template = E'Hi {{.UserName}}\n\n' || + E'Your workspace **{{.Labels.name}}** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of {{.Labels.reason}}.\n' || + E'Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after {{.Labels.timeTilDormant}} of inactivity.\n' || + E'To prevent deletion, use your workspace with the link below.' WHERE id = '0ea69165-ec14-4314-91f1-69566ac3c5a0'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', 'Hi {{.UserName}}')::text + body_template = E'Hi {{.UserName}}\n\n' || + 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' || + E'To prevent deletion, use your workspace with the link below.' WHERE id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'\nThe workspace build was initiated by', 'The workspace build was initiated by')::text + 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}}**.' WHERE id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text -WHERE - id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, E'Hi {{.UserName}},\n', 'Hi {{.UserName}},')::text -WHERE - id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; diff --git a/coderd/database/migrations/000262_improve_notification_templates.up.sql b/coderd/database/migrations/000262_improve_notification_templates.up.sql index 5f5b39800db46..a5cb7ee60d1b2 100644 --- a/coderd/database/migrations/000262_improve_notification_templates.up.sql +++ b/coderd/database/migrations/000262_improve_notification_templates.up.sql @@ -1,85 +1,101 @@ UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text + body_template = E'Hi {{.UserName}},\n\n' || + E'User account **{{.Labels.suspended_account_name}}** has been suspended.\n\n' || + E'The newly suspended account belongs to **{{.Labels.suspended_account_user_name}}** and was suspended by **{{.Labels.account_suspender_user_name}}**.' WHERE - id = '29a09665-2a4c-403f-9648-54301670e7be'; + id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; UPDATE notification_templates SET -body_template = E'Hi {{.UserName}},\n\n' - 'User account **{{.Labels.activated_account_name}}** has been activated. ' - 'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.' + body_template = E'Hi {{.UserName}},\n\n' || + E'Your account **{{.Labels.suspended_account_name}}** has been suspended by **{{.Labels.account_suspender_user_name}}**' WHERE - id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; + id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text + body_template = E'Hi {{.UserName}},\n\n' || + E'User account **{{.Labels.activated_account_name}}** has been activated.\n\n' || + E'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.' WHERE - id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; + id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', E'Hi {{.UserName}},\n')::text + body_template = E'Hi {{.UserName}},\n\n' || + E'Your account **{{.Labels.activated_account_name}}** has been activated by **{{.Labels.account_activator_user_name}}**.' WHERE - id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, E'({{.Labels.template_version_name}}).\n', E'({{.Labels.template_version_name}}).\n\n')::text + body_template = E'Hi {{.UserName}},\n\n' || + E'New user account **{{.Labels.created_account_name}}** has been created.\n\n' || + E'This new user account was created for **{{.Labels.created_account_user_name}}** by **{{.Labels.account_creator}}**' WHERE - id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + id = '4e19c0ac-94e1-4532-9515-d1801aa283b2'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', E'Hi {{.UserName}},\n')::text + body_template = E'Hi {{.UserName}},\n\n' || + E'User account **{{.Labels.deleted_account_name}}** has been deleted.\n\n' || + E'The deleted account belonged to **{{.Labels.deleted_account_user_name}}** and was deleted by **{{.Labels.account_deleter_user_name}}**.' WHERE - id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; + id = 'f44d9314-ad03-4bc8-95d0-5cad491da6b6'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'The specified reason', E'\nThe specified reason')::text + body_template = E'Hi {{.UserName}}\n\n' || + E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.\n\n' || + E'The templates display name was **{{.Labels.display_name}}**.' WHERE - id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; + id = '29a09665-2a4c-403f-9648-54301670e7be'; + +UPDATE notification_templates +SET body_template = E'Hi {{.UserName}}\n\n' || + 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'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text + body_template = E'Hi {{.UserName}}\n\n' || + E'Automatic build of your workspace **{{.Labels.name}}** failed.\n\n' || + E'The specified reason was "**{{.Labels.reason}}**".' WHERE - id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; + id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'The specified reason', E'\nThe specified reason')::text + body_template = E'Hi {{.UserName}},\n\n' || + E'Your workspace **{{.Labels.name}}** was deleted.\n\n' || + E'The specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".' WHERE id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text + body_template = E'Hi {{.UserName}}\n\n,' || -- add comma + E'Your workspace **{{.Labels.name}}** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of {{.Labels.reason}}.\n' || + E'Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after {{.Labels.timeTilDormant}} of inactivity.\n' || + E'To prevent deletion, use your workspace with the link below.' WHERE id = '0ea69165-ec14-4314-91f1-69566ac3c5a0'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}}', 'Hi {{.UserName}},')::text + body_template = E'Hi {{.UserName}}\n\n,' || -- add comma + 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' || + E'To prevent deletion, use your workspace with the link below.' WHERE id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42'; UPDATE notification_templates SET - body_template = REPLACE(body_template::text, 'The workspace build was initiated by', E'\nThe workspace build was initiated by')::text + body_template = E'Hi {{.UserName}},\n\n' || + E'A manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\n\n' || + E'The workspace build was initiated by **{{.Labels.initiator}}**.' WHERE id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text -WHERE - id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; - -UPDATE notification_templates -SET - body_template = REPLACE(body_template::text, 'Hi {{.UserName}},', E'Hi {{.UserName}},\n')::text -WHERE - id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index d22a7b02d1839..65953775523c9 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -774,7 +774,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { payload: types.MessagePayload{ UserName: "Bobby", Labels: map[string]string{ - "deleted_account_name": "bobby", + "deleted_account_name": "bobby", + "deleted_account_user_name": "william tables", + "account_deleter_user_name": "rob", }, }, }, @@ -784,7 +786,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { payload: types.MessagePayload{ UserName: "Bobby", Labels: map[string]string{ - "suspended_account_name": "bobby", + "suspended_account_name": "bobby", + "suspended_account_user_name": "william tables", + "account_suspender_user_name": "rob", }, }, }, @@ -794,7 +798,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { payload: types.MessagePayload{ UserName: "Bobby", Labels: map[string]string{ - "activated_account_name": "bobby", + "activated_account_name": "bobby", + "activated_account_user_name": "william tables", + "account_activator_user_name": "rob", }, }, }, @@ -804,7 +810,8 @@ func TestNotificationTemplates_Golden(t *testing.T) { payload: types.MessagePayload{ UserName: "Bobby", Labels: map[string]string{ - "suspended_account_name": "bobby", + "suspended_account_name": "bobby", + "account_suspender_user_name": "rob", }, }, }, @@ -814,7 +821,8 @@ func TestNotificationTemplates_Golden(t *testing.T) { payload: types.MessagePayload{ UserName: "Bobby", Labels: map[string]string{ - "activated_account_name": "bobby", + "activated_account_name": "bobby", + "account_activator_user_name": "rob", }, }, }, @@ -824,8 +832,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { payload: types.MessagePayload{ UserName: "Bobby", Labels: map[string]string{ - "name": "bobby-template", - "initiator": "rob", + "name": "bobby-template", + "display_name": "Bobby's Template", + "initiator": "rob", }, }, }, diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden index 0af8a75131535..5d3ca5c7f94b9 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden @@ -1,3 +1,5 @@ -Hi Bobby, +Hi Bobby -The template **bobby-template** was deleted by **rob**. \ No newline at end of file +The template **bobby-template** was deleted by **rob**. + +The templates display name was **Bobby's Template**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden index a45de605b47f4..5a773a51dc181 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden @@ -1,3 +1,5 @@ Hi Bobby, -User account **bobby** has been activated. \ No newline at end of file +User account **bobby** has been activated. + +The newly activated account belongs to **william tables** and was activated by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden index e5a5be89c11e0..c44c7a9cfca16 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden @@ -1,3 +1,5 @@ Hi Bobby, -New user account **bobby** has been created. \ No newline at end of file +New user account **bobby** has been created. + +This new user account was created for **** by **** \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden index bd1066c25fb50..4ca8bedd0ca52 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden @@ -1,3 +1,5 @@ Hi Bobby, -User account **bobby** has been deleted. \ No newline at end of file +User account **bobby** has been deleted. + +The deleted account belonged to **william tables** and was deleted by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden index def07959b59ff..ecf276504ebc9 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden @@ -1,3 +1,5 @@ Hi Bobby, -User account **bobby** has been suspended. \ No newline at end of file +User account **bobby** has been suspended. + +The newly suspended account belongs to **william tables** and was suspended by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden index a2a16a7e9d179..8a87a0c61aeff 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden @@ -1,4 +1,4 @@ -Hi Bobby, +Hi Bobby Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0). diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden index cddf2149d0d46..4a700546e1442 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden @@ -1,4 +1,4 @@ -Hi Bobby, +Hi Bobby Automatic build of your workspace **bobby-workspace** failed. diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden index 35bfe8d2c19b6..a766d6090cd4f 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden @@ -1,5 +1,5 @@ -Hi Bobby, +Hi Bobby -Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity. +,Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity. Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity. To prevent deletion, use your workspace with the link below. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden index 21defa7c1d500..4d797ba93709b 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden @@ -1,4 +1,4 @@ -Hi Bobby, +Hi Bobby -Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy. +,Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy. To prevent deletion, use your workspace with the link below. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden index 36ea5a0d02139..a3a8710de4673 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden @@ -1,3 +1,3 @@ Hi Bobby, -Your account **bobby** has been activated. \ No newline at end of file +Your account **bobby** has been activated by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden index 5c138f639ef69..615e24ca30f1a 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden @@ -1,3 +1,3 @@ Hi Bobby, -Your account **bobby** has been suspended. \ No newline at end of file +Your account **bobby** has been suspended by **rob** \ No newline at end of file From 98e7501840a51913eb6b56d55329f14eac5865a1 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Tue, 8 Oct 2024 10:13:56 +0000 Subject: [PATCH 10/44] feat(coderd): send newly required information to notification templates --- coderd/templates.go | 5 ++- coderd/templates_test.go | 5 ++- coderd/userauth.go | 5 ++- coderd/users.go | 89 +++++++++++++++++++++++++++++----------- coderd/users_test.go | 3 ++ 5 files changed, 79 insertions(+), 28 deletions(-) diff --git a/coderd/templates.go b/coderd/templates.go index dc32841b72aad..01c2a056bb813 100644 --- a/coderd/templates.go +++ b/coderd/templates.go @@ -137,8 +137,9 @@ func (api *API) notifyTemplateDeleted(ctx context.Context, template database.Tem if _, err := api.NotificationsEnqueuer.Enqueue(ctx, receiverID, notifications.TemplateTemplateDeleted, map[string]string{ - "name": template.Name, - "initiator": initiator.Username, + "name": template.Name, + "display_name": template.DisplayName, + "initiator": initiator.Username, }, "api-templates-delete", // Associate this notification with all the related entities. template.ID, template.OrganizationID, diff --git a/coderd/templates_test.go b/coderd/templates_test.go index ca8d9c4cf88f2..4273169d4ca82 100644 --- a/coderd/templates_test.go +++ b/coderd/templates_test.go @@ -1419,7 +1419,9 @@ func TestTemplateNotifications(t *testing.T) { // Setup template version = coderdtest.CreateTemplateVersion(t, client, initiator.OrganizationID, nil) _ = coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID) - template = coderdtest.CreateTemplate(t, client, initiator.OrganizationID, version.ID) + template = coderdtest.CreateTemplate(t, client, initiator.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) { + ctr.DisplayName = "Bobby's Template" + }) ) // Setup users with different roles @@ -1455,6 +1457,7 @@ func TestTemplateNotifications(t *testing.T) { require.Contains(t, n.Targets, template.ID) require.Contains(t, n.Targets, template.OrganizationID) require.Equal(t, n.Labels["name"], template.Name) + require.Equal(t, n.Labels["display_name"], template.DisplayName) require.Equal(t, n.Labels["initiator"], coderdtest.FirstUserParams.Username) } }) diff --git a/coderd/userauth.go b/coderd/userauth.go index a1e1252797de3..0ff3dfa8f97cc 100644 --- a/coderd/userauth.go +++ b/coderd/userauth.go @@ -1481,14 +1481,15 @@ func (api *API) oauthLogin(r *http.Request, params *oauthLoginParams) ([]*http.C Username: params.Username, OrganizationIDs: orgIDs, }, - LoginType: params.LoginType, + LoginType: params.LoginType, + accountCreatorName: "oauth", }) if err != nil { return xerrors.Errorf("create user: %w", err) } } - // Activate dormant user on sigin + // Activate dormant user on sign-in if user.Status == database.UserStatusDormant { //nolint:gocritic // System needs to update status of the user account (dormant -> active). user, err = tx.UpdateUserStatus(dbauthz.AsSystemRestricted(ctx), database.UpdateUserStatusParams{ diff --git a/coderd/users.go b/coderd/users.go index 48bc3ee15e4c5..2356bf2211a61 100644 --- a/coderd/users.go +++ b/coderd/users.go @@ -194,7 +194,8 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) { Password: createUser.Password, OrganizationIDs: []uuid.UUID{defaultOrg.ID}, }, - LoginType: database.LoginTypePassword, + LoginType: database.LoginTypePassword, + accountCreatorName: "coder", }) if err != nil { httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ @@ -479,10 +480,22 @@ func (api *API) postUser(rw http.ResponseWriter, r *http.Request) { return } + apiKey := httpmw.APIKey(r) + + accountCreator, err := api.Database.GetUserByID(ctx, apiKey.UserID) + if err != nil { + httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ + Message: "Unable to determine the details of the actor creating the account.", + }) + return + } + user, err := api.CreateUser(ctx, api.Database, CreateUserRequest{ CreateUserRequestWithOrgs: req, LoginType: loginType, + accountCreatorName: accountCreator.Name, }) + if dbauthz.IsNotAuthorizedError(err) { httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{ Message: "You are not authorized to create users.", @@ -576,11 +589,24 @@ func (api *API) deleteUser(rw http.ResponseWriter, r *http.Request) { return } + apiKey := httpmw.APIKey(r) + + accountDeleter, err := api.Database.GetUserByID(ctx, apiKey.UserID) + if err != nil { + httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ + Message: "Unable to determine the details of the actor deleting the account.", + }) + return + } + for _, u := range userAdmins { if _, err := api.NotificationsEnqueuer.Enqueue(ctx, u.ID, notifications.TemplateUserAccountDeleted, map[string]string{ - "deleted_account_name": user.Username, - }, "api-users-delete", + "deleted_account_name": user.Username, + "deleted_account_user_name": user.Name, + "account_deleter_user_name": accountDeleter.Name, + }, + "api-users-delete", user.ID, ); err != nil { api.Logger.Warn(ctx, "unable to notify about deleted user", slog.F("deleted_user", user.Username), slog.Error(err)) @@ -844,6 +870,14 @@ func (api *API) putUserStatus(status database.UserStatus) func(rw http.ResponseW } } + actingUser, err := api.Database.GetUserByID(ctx, apiKey.UserID) + if err != nil { + httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ + Message: "Unable to determine the details of the actor creating the account.", + }) + return + } + targetUser, err := api.Database.UpdateUserStatus(ctx, database.UpdateUserStatusParams{ ID: user.ID, Status: status, @@ -858,7 +892,7 @@ func (api *API) putUserStatus(status database.UserStatus) func(rw http.ResponseW } aReq.New = targetUser - err = api.notifyUserStatusChanged(ctx, user, status) + err = api.notifyUserStatusChanged(ctx, actingUser.Name, user, status) if err != nil { api.Logger.Warn(ctx, "unable to notify about changed user's status", slog.F("affected_user", user.Username), slog.Error(err)) } @@ -871,24 +905,33 @@ func (api *API) putUserStatus(status database.UserStatus) func(rw http.ResponseW }) return } + httpapi.Write(ctx, rw, http.StatusOK, db2sdk.User(targetUser, organizations)) } } -func (api *API) notifyUserStatusChanged(ctx context.Context, user database.User, status database.UserStatus) error { - var key string +func (api *API) notifyUserStatusChanged(ctx context.Context, actingUserName string, targetUser database.User, status database.UserStatus) error { + var labels map[string]string var adminTemplateID, personalTemplateID uuid.UUID switch status { case database.UserStatusSuspended: - key = "suspended_account_name" + labels = map[string]string{ + "suspended_account_name": targetUser.Username, + "suspended_account_user_name": targetUser.Name, + "account_suspender_user_name": actingUserName, + } adminTemplateID = notifications.TemplateUserAccountSuspended personalTemplateID = notifications.TemplateYourAccountSuspended case database.UserStatusActive: - key = "activated_account_name" + labels = map[string]string{ + "activated_account_name": targetUser.Username, + "activated_account_user_name": targetUser.Name, + "account_activator_user_name": actingUserName, + } adminTemplateID = notifications.TemplateUserAccountActivated personalTemplateID = notifications.TemplateYourAccountActivated default: - api.Logger.Error(ctx, "user status is not supported", slog.F("username", user.Username), slog.F("user_status", string(status))) + api.Logger.Error(ctx, "user status is not supported", slog.F("username", targetUser.Username), slog.F("user_status", string(status))) return xerrors.Errorf("unable to notify admins as the user's status is unsupported") } @@ -900,21 +943,17 @@ func (api *API) notifyUserStatusChanged(ctx context.Context, user database.User, // Send notifications to user admins and affected user for _, u := range userAdmins { if _, err := api.NotificationsEnqueuer.Enqueue(ctx, u.ID, adminTemplateID, - map[string]string{ - key: user.Username, - }, "api-put-user-status", - user.ID, + labels, "api-put-user-status", + targetUser.ID, ); err != nil { - api.Logger.Warn(ctx, "unable to notify about changed user's status", slog.F("affected_user", user.Username), slog.Error(err)) + api.Logger.Warn(ctx, "unable to notify about changed user's status", slog.F("affected_user", targetUser.Username), slog.Error(err)) } } - if _, err := api.NotificationsEnqueuer.Enqueue(ctx, user.ID, personalTemplateID, - map[string]string{ - key: user.Username, - }, "api-put-user-status", - user.ID, + if _, err := api.NotificationsEnqueuer.Enqueue(ctx, targetUser.ID, personalTemplateID, + labels, "api-put-user-status", + targetUser.ID, ); err != nil { - api.Logger.Warn(ctx, "unable to notify user about status change of their account", slog.F("affected_user", user.Username), slog.Error(err)) + api.Logger.Warn(ctx, "unable to notify user about status change of their account", slog.F("affected_user", targetUser.Username), slog.Error(err)) } return nil } @@ -1280,8 +1319,9 @@ func (api *API) organizationByUserAndName(rw http.ResponseWriter, r *http.Reques type CreateUserRequest struct { codersdk.CreateUserRequestWithOrgs - LoginType database.LoginType - SkipNotifications bool + LoginType database.LoginType + SkipNotifications bool + accountCreatorName string } func (api *API) CreateUser(ctx context.Context, store database.Store, req CreateUserRequest) (database.User, error) { @@ -1365,13 +1405,16 @@ func (api *API) CreateUser(ctx context.Context, store database.Store, req Create for _, u := range userAdmins { if _, err := api.NotificationsEnqueuer.Enqueue(ctx, u.ID, notifications.TemplateUserAccountCreated, map[string]string{ - "created_account_name": user.Username, + "created_account_name": user.Username, + "created_account_user_name": user.Name, + "account_creator": req.accountCreatorName, }, "api-users-create", user.ID, ); err != nil { api.Logger.Warn(ctx, "unable to notify about created user", slog.F("created_user", user.Username), slog.Error(err)) } } + return user, err } diff --git a/coderd/users_test.go b/coderd/users_test.go index 1ab052d4aa470..3aa7aa397d360 100644 --- a/coderd/users_test.go +++ b/coderd/users_test.go @@ -513,6 +513,9 @@ func TestNotifyDeletedUser(t *testing.T) { require.Equal(t, firstUser.UserID, notifyEnq.Sent[1].UserID) require.Contains(t, notifyEnq.Sent[1].Targets, user.ID) require.Equal(t, user.Username, notifyEnq.Sent[1].Labels["deleted_account_name"]) + require.Equal(t, user.Name, notifyEnq.Sent[1].Labels["deleted_account_user_name"]) + // Not sure where to get the following just yet + // require.Equal(t, , notifyEnq.Sent[1].Labels["account_deleter_user_name"]) }) t.Run("UserAdminNotified", func(t *testing.T) { From d8e00c28cd73d7feef10a2846ab29bc10f688750 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Tue, 8 Oct 2024 13:51:39 +0000 Subject: [PATCH 11/44] feat(coderd/notifications): provide additional context to workspace notifications --- ...0262_improve_notification_templates.up.sql | 45 +++++++++++++++---- coderd/notifications/notifications_test.go | 1 + .../TemplateTemplateDeleted-body.md.golden | 4 +- ...emplateWorkspaceAutoUpdated-body.md.golden | 2 +- ...ateWorkspaceAutobuildFailed-body.md.golden | 2 +- ...eWorkspaceManualBuildFailed-body.md.golden | 2 +- .../provisionerdserver/provisionerdserver.go | 1 + .../provisionerdserver_test.go | 1 + 8 files changed, 44 insertions(+), 14 deletions(-) diff --git a/coderd/database/migrations/000262_improve_notification_templates.up.sql b/coderd/database/migrations/000262_improve_notification_templates.up.sql index a5cb7ee60d1b2..0c58ee85d9aa6 100644 --- a/coderd/database/migrations/000262_improve_notification_templates.up.sql +++ b/coderd/database/migrations/000262_improve_notification_templates.up.sql @@ -1,80 +1,103 @@ +-- https://github.com/coder/coder/issues/14893 + +-- UserAccountSuspended UPDATE notification_templates SET - body_template = E'Hi {{.UserName}},\n\n' || + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n E'User account **{{.Labels.suspended_account_name}}** has been suspended.\n\n' || + -- Mention the real name of the user who suspended the account: E'The newly suspended account belongs to **{{.Labels.suspended_account_user_name}}** and was suspended by **{{.Labels.account_suspender_user_name}}**.' WHERE id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; +-- YourAccountSuspended UPDATE notification_templates SET - body_template = E'Hi {{.UserName}},\n\n' || + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n + -- Mention who suspended the account: E'Your account **{{.Labels.suspended_account_name}}** has been suspended by **{{.Labels.account_suspender_user_name}}**' WHERE id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; +-- UserAccountActivated UPDATE notification_templates SET - body_template = E'Hi {{.UserName}},\n\n' || + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n E'User account **{{.Labels.activated_account_name}}** has been activated.\n\n' || + -- Mention the real name of the user who activated the account: E'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.' WHERE id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; +-- YourAccountActivated UPDATE notification_templates SET - body_template = E'Hi {{.UserName}},\n\n' || + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n + -- Mention who activated the account: E'Your account **{{.Labels.activated_account_name}}** has been activated by **{{.Labels.account_activator_user_name}}**.' WHERE id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; +-- UserAccountCreated UPDATE notification_templates SET body_template = E'Hi {{.UserName}},\n\n' || E'New user account **{{.Labels.created_account_name}}** has been created.\n\n' || + -- Mention the real name of the user who created the account: E'This new user account was created for **{{.Labels.created_account_user_name}}** by **{{.Labels.account_creator}}**' WHERE id = '4e19c0ac-94e1-4532-9515-d1801aa283b2'; +-- UserAccountDeleted UPDATE notification_templates SET body_template = E'Hi {{.UserName}},\n\n' || E'User account **{{.Labels.deleted_account_name}}** has been deleted.\n\n' || + -- Mention the real name of the user who deleted the account: E'The deleted account belonged to **{{.Labels.deleted_account_user_name}}** and was deleted by **{{.Labels.account_deleter_user_name}}**.' WHERE id = 'f44d9314-ad03-4bc8-95d0-5cad491da6b6'; +-- TemplateDeleted UPDATE notification_templates SET - body_template = E'Hi {{.UserName}}\n\n' || + body_template = E'Hi {{.UserName}}i,\n\n' || -- Add a comma E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.\n\n' || - E'The templates display name was **{{.Labels.display_name}}**.' + -- Mention template display name: + E'The template''s display name was **{{.Labels.display_name}}**.' WHERE id = '29a09665-2a4c-403f-9648-54301670e7be'; +-- WorkspaceAutoUpdated UPDATE notification_templates -SET body_template = E'Hi {{.UserName}}\n\n' || +SET body_template = E'Hi {{.UserName}},\n\n' || -- Add a comma and a \n + -- Add a \n: 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'; +-- WorkspaceAutoBuildFailed UPDATE notification_templates SET - body_template = E'Hi {{.UserName}}\n\n' || + body_template = E'Hi {{.UserName}},\n\n' || -- Add a comma + -- Add a \n after: E'Automatic build of your workspace **{{.Labels.name}}** failed.\n\n' || E'The specified reason was "**{{.Labels.reason}}**".' WHERE id = '381df2a9-c0c0-4749-420f-80a9280c66f9'; +-- WorkspaceDeleted UPDATE notification_templates SET - body_template = E'Hi {{.UserName}},\n\n' || + body_template = E'Hi {{.UserName}},\n\n' || -- Add a comma + -- Add a \n after: E'Your workspace **{{.Labels.name}}** was deleted.\n\n' || E'The specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".' WHERE id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; +-- WorkspaceDormant UPDATE notification_templates SET body_template = E'Hi {{.UserName}}\n\n,' || -- add comma @@ -84,6 +107,7 @@ SET WHERE id = '0ea69165-ec14-4314-91f1-69566ac3c5a0'; +-- WorkspaceMarkedForDeletion UPDATE notification_templates SET body_template = E'Hi {{.UserName}}\n\n,' || -- add comma @@ -92,10 +116,13 @@ SET WHERE id = '51ce2fdf-c9ca-4be1-8d70-628674f9bc42'; +-- WorkspaceManualBuildFailed UPDATE notification_templates SET body_template = E'Hi {{.UserName}},\n\n' || E'A manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\n\n' || + -- Mention template display name: + E'The template''s display name was **{{.Labels.template_display_name}}**.' || E'The workspace build was initiated by **{{.Labels.initiator}}**.' WHERE id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 65953775523c9..3086f84a16109 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -846,6 +846,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { Labels: map[string]string{ "name": "bobby-workspace", "template_name": "bobby-template", + "template_display_name": "William's Template", "template_version_name": "bobby-template-version", "initiator": "joe", "workspace_owner_username": "mrbobby", diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden index 5d3ca5c7f94b9..27a300e5ac1be 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden @@ -1,5 +1,5 @@ -Hi Bobby +Hi Bobbyi, The template **bobby-template** was deleted by **rob**. -The templates display name was **Bobby's Template**. \ No newline at end of file +The template's display name was **Bobby's Template**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden index 8a87a0c61aeff..a2a16a7e9d179 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden @@ -1,4 +1,4 @@ -Hi Bobby +Hi Bobby, Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0). diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden index 4a700546e1442..cddf2149d0d46 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden @@ -1,4 +1,4 @@ -Hi Bobby +Hi Bobby, Automatic build of your workspace **bobby-workspace** failed. diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden index 3989c1ee841fa..da9a44aa3529f 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden @@ -2,4 +2,4 @@ Hi Bobby, A manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**). -The workspace build was initiated by **joe**. \ No newline at end of file +The template's display name was **William's Template**.The workspace build was initiated by **joe**. \ No newline at end of file diff --git a/coderd/provisionerdserver/provisionerdserver.go b/coderd/provisionerdserver/provisionerdserver.go index 2db5bbd1062b1..0fc89b239a8d4 100644 --- a/coderd/provisionerdserver/provisionerdserver.go +++ b/coderd/provisionerdserver/provisionerdserver.go @@ -1128,6 +1128,7 @@ func (s *server) notifyWorkspaceManualBuildFailed(ctx context.Context, workspace map[string]string{ "name": workspace.Name, "template_name": template.Name, + "template_display_name": template.DisplayName, "template_version_name": templateVersion.Name, "initiator": build.InitiatorByUsername, "workspace_owner_username": workspaceOwner.Username, diff --git a/coderd/provisionerdserver/provisionerdserver_test.go b/coderd/provisionerdserver/provisionerdserver_test.go index d429ae1a1bcb1..1fe60f5897004 100644 --- a/coderd/provisionerdserver/provisionerdserver_test.go +++ b/coderd/provisionerdserver/provisionerdserver_test.go @@ -1860,6 +1860,7 @@ func TestNotifications(t *testing.T) { assert.Contains(t, notifEnq.Sent[0].Targets, user.ID) assert.Equal(t, workspace.Name, notifEnq.Sent[0].Labels["name"]) assert.Equal(t, template.Name, notifEnq.Sent[0].Labels["template_name"]) + assert.Equal(t, template.DisplayName, notifEnq.Sent[0].Labels["template_display_name"]) assert.Equal(t, version.Name, notifEnq.Sent[0].Labels["template_version_name"]) assert.Equal(t, user.Username, notifEnq.Sent[0].Labels["initiator"]) assert.Equal(t, user.Username, notifEnq.Sent[0].Labels["workspace_owner_username"]) From d6a339f07658d1f31bd83f251ddd6b0a9ad41fc2 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Tue, 8 Oct 2024 14:36:40 +0000 Subject: [PATCH 12/44] fix(coderd/notifications): add a missing call to fmt.Sprintf --- coderd/notifications/notifications_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 3086f84a16109..4973936194769 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -977,8 +977,8 @@ func TestNotificationTemplates_Golden(t *testing.T) { wantTitle, err := os.ReadFile(titleGoldenFile) require.NoError(t, err, fmt.Sprintf("missing golden notification title file. %s", hint)) - require.Equal(t, string(wantBody), body, "rendered template body does not match golden file. If this is expected, %s", hint) - require.Equal(t, string(wantTitle), title, "rendered template title does not match golden file. If this is expected, %s", hint) + require.Equal(t, string(wantBody), body, fmt.Sprintf("rendered template body does not match golden file. If this is expected, %s", hint)) + require.Equal(t, string(wantTitle), title, fmt.Sprintf("rendered template title does not match golden file. If this is expected, %s", hint)) }) } } From 920ad312b193593f614240fe817a43ad0f7c0333 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Wed, 9 Oct 2024 06:20:30 +0000 Subject: [PATCH 13/44] fix(coderd/notifications): fix oversights in template migration --- .../000262_improve_notification_templates.up.sql | 8 ++++---- coderd/notifications/notifications_test.go | 4 +++- .../TemplateTemplateDeleted-body.md.golden | 2 +- .../TemplateUserAccountCreated-body.md.golden | 2 +- .../TemplateWorkspaceDormant-body.md.golden | 4 ++-- .../TemplateWorkspaceManualBuildFailed-body.md.golden | 2 +- .../TemplateWorkspaceMarkedForDeletion-body.md.golden | 4 ++-- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/coderd/database/migrations/000262_improve_notification_templates.up.sql b/coderd/database/migrations/000262_improve_notification_templates.up.sql index 0c58ee85d9aa6..13571cc618dfc 100644 --- a/coderd/database/migrations/000262_improve_notification_templates.up.sql +++ b/coderd/database/migrations/000262_improve_notification_templates.up.sql @@ -61,7 +61,7 @@ WHERE -- TemplateDeleted UPDATE notification_templates SET - body_template = E'Hi {{.UserName}}i,\n\n' || -- Add a comma + body_template = E'Hi {{.UserName}},\n\n' || -- Add a comma E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.\n\n' || -- Mention template display name: E'The template''s display name was **{{.Labels.display_name}}**.' @@ -100,7 +100,7 @@ WHERE -- WorkspaceDormant UPDATE notification_templates SET - body_template = E'Hi {{.UserName}}\n\n,' || -- add comma + body_template = E'Hi {{.UserName}},\n\n' || -- add comma E'Your workspace **{{.Labels.name}}** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of {{.Labels.reason}}.\n' || E'Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after {{.Labels.timeTilDormant}} of inactivity.\n' || E'To prevent deletion, use your workspace with the link below.' @@ -110,7 +110,7 @@ WHERE -- WorkspaceMarkedForDeletion UPDATE notification_templates SET - body_template = E'Hi {{.UserName}}\n\n,' || -- add comma + body_template = E'Hi {{.UserName}},\n\n' || -- add comma 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' || E'To prevent deletion, use your workspace with the link below.' WHERE @@ -122,7 +122,7 @@ SET body_template = E'Hi {{.UserName}},\n\n' || E'A manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\n\n' || -- Mention template display name: - E'The template''s display name was **{{.Labels.template_display_name}}**.' || + E'The template''s display name was **{{.Labels.template_display_name}}**. ' || E'The workspace build was initiated by **{{.Labels.initiator}}**.' WHERE id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 4973936194769..dcf207c36cace 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -764,7 +764,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { payload: types.MessagePayload{ UserName: "Bobby", Labels: map[string]string{ - "created_account_name": "bobby", + "created_account_name": "bobby", + "created_account_user_name": "William Tables", + "account_creator": "rob", }, }, }, diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden index 27a300e5ac1be..ade9c87ff791a 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden @@ -1,4 +1,4 @@ -Hi Bobbyi, +Hi Bobby, The template **bobby-template** was deleted by **rob**. diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden index c44c7a9cfca16..880d92a8bed2b 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden @@ -2,4 +2,4 @@ Hi Bobby, New user account **bobby** has been created. -This new user account was created for **** by **** \ No newline at end of file +This new user account was created for **William Tables** by **rob** \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden index a766d6090cd4f..35bfe8d2c19b6 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden @@ -1,5 +1,5 @@ -Hi Bobby +Hi Bobby, -,Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity. +Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity. Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity. To prevent deletion, use your workspace with the link below. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden index da9a44aa3529f..e1091b2888830 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden @@ -2,4 +2,4 @@ Hi Bobby, A manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**). -The template's display name was **William's Template**.The workspace build was initiated by **joe**. \ No newline at end of file +The template's display name was **William's Template**. The workspace build was initiated by **joe**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden index 4d797ba93709b..21defa7c1d500 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden @@ -1,4 +1,4 @@ -Hi Bobby +Hi Bobby, -,Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy. +Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy. To prevent deletion, use your workspace with the link below. \ No newline at end of file From 9e938e50414193eb7e7456975222e61296fe2492 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Wed, 9 Oct 2024 06:42:34 +0000 Subject: [PATCH 14/44] chore(coderd/provisionerdserver): set the displayname in TestNotifications --- coderd/provisionerdserver/provisionerdserver_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderd/provisionerdserver/provisionerdserver_test.go b/coderd/provisionerdserver/provisionerdserver_test.go index 1fe60f5897004..32ae2efa648a0 100644 --- a/coderd/provisionerdserver/provisionerdserver_test.go +++ b/coderd/provisionerdserver/provisionerdserver_test.go @@ -1820,7 +1820,7 @@ func TestNotifications(t *testing.T) { _ = dbgen.OrganizationMember(t, db, database.OrganizationMember{UserID: user.ID, OrganizationID: pd.OrganizationID}) template := dbgen.Template(t, db, database.Template{ - Name: "template", Provisioner: database.ProvisionerTypeEcho, OrganizationID: pd.OrganizationID, + Name: "template", DisplayName: "William's Template", Provisioner: database.ProvisionerTypeEcho, OrganizationID: pd.OrganizationID, }) workspace := dbgen.Workspace(t, db, database.Workspace{ TemplateID: template.ID, OwnerID: user.ID, OrganizationID: pd.OrganizationID, From 59e57ac26c4fd537dd9dbbee250d01ee5ff4e521 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Wed, 9 Oct 2024 07:58:36 +0000 Subject: [PATCH 15/44] chore(coderd): add more robust testing assertions to TestNotifyDeletedUser --- coderd/users_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/coderd/users_test.go b/coderd/users_test.go index 3aa7aa397d360..7406df75bf1db 100644 --- a/coderd/users_test.go +++ b/coderd/users_test.go @@ -489,13 +489,16 @@ func TestNotifyDeletedUser(t *testing.T) { adminClient := coderdtest.New(t, &coderdtest.Options{ NotificationsEnqueuer: notifyEnq, }) - firstUser := coderdtest.CreateFirstUser(t, adminClient) + firstUserResponse := coderdtest.CreateFirstUser(t, adminClient) ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) defer cancel() + firstUser, err := adminClient.User(ctx, firstUserResponse.UserID.String()) + require.NoError(t, err) + user, err := adminClient.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{ - OrganizationIDs: []uuid.UUID{firstUser.OrganizationID}, + OrganizationIDs: []uuid.UUID{firstUserResponse.OrganizationID}, Email: "another@user.org", Username: "someone-else", Password: "SomeSecurePassword!", @@ -510,12 +513,11 @@ func TestNotifyDeletedUser(t *testing.T) { require.Len(t, notifyEnq.Sent, 2) // notifyEnq.Sent[0] is create account event require.Equal(t, notifications.TemplateUserAccountDeleted, notifyEnq.Sent[1].TemplateID) - require.Equal(t, firstUser.UserID, notifyEnq.Sent[1].UserID) + require.Equal(t, firstUser.ID, notifyEnq.Sent[1].UserID) require.Contains(t, notifyEnq.Sent[1].Targets, user.ID) require.Equal(t, user.Username, notifyEnq.Sent[1].Labels["deleted_account_name"]) require.Equal(t, user.Name, notifyEnq.Sent[1].Labels["deleted_account_user_name"]) - // Not sure where to get the following just yet - // require.Equal(t, , notifyEnq.Sent[1].Labels["account_deleter_user_name"]) + require.Equal(t, firstUser.Name, notifyEnq.Sent[1].Labels["account_deleter_user_name"]) }) t.Run("UserAdminNotified", func(t *testing.T) { From c907238e38e7223e72660d60dc024608da2a0ed6 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Wed, 9 Oct 2024 16:00:59 +0000 Subject: [PATCH 16/44] chore(coderd/notifications): fix migration indentation --- ...62_improve_notification_templates.down.sql | 17 ++++++------- ...0262_improve_notification_templates.up.sql | 24 +++++++++---------- coderd/notifications/notifications_test.go | 2 +- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/coderd/database/migrations/000262_improve_notification_templates.down.sql b/coderd/database/migrations/000262_improve_notification_templates.down.sql index d7aeaaf54a487..62a2799e52caa 100644 --- a/coderd/database/migrations/000262_improve_notification_templates.down.sql +++ b/coderd/database/migrations/000262_improve_notification_templates.down.sql @@ -14,7 +14,7 @@ UPDATE notification_templates SET body_template = E'Hi {{.UserName}},\nUser account **{{.Labels.activated_account_name}}** has been activated.' WHERE - id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; + id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; UPDATE notification_templates SET @@ -24,13 +24,13 @@ WHERE UPDATE notification_templates SET - body_template = E'Hi {{.UserName}},\n\New user account **{{.Labels.created_account_name}}** has been created.' + body_template = E'Hi {{.UserName}},\n\New user account **{{.Labels.created_account_name}}** has been created.' WHERE id = '4e19c0ac-94e1-4532-9515-d1801aa283b2'; UPDATE notification_templates SET - body_template = E'Hi {{.UserName}},\n\nUser account **{{.Labels.deleted_account_name}}** has been deleted.' + body_template = E'Hi {{.UserName}},\n\nUser account **{{.Labels.deleted_account_name}}** has been deleted.' WHERE id = 'f44d9314-ad03-4bc8-95d0-5cad491da6b6'; @@ -43,9 +43,10 @@ WHERE UPDATE notification_templates SET body_template = E'Hi {{.UserName}}\n' || - E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).\n' || - E'Reason for update: **{{.Labels.template_version_message}}**' -WHERE id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; + E'Your workspace **{{.Labels.name}}** has been updated automatically to the latest template version ({{.Labels.template_version_name}}).\n' || + E'Reason for update: **{{.Labels.template_version_message}}**' +WHERE + id = 'c34a0c09-0704-4cac-bd1c-0c0146811c2b'; UPDATE notification_templates SET @@ -55,7 +56,7 @@ WHERE UPDATE notification_templates SET - body_template = E'Hi {{.UserName}}\n\nYour workspace **{{.Labels.name}}** was deleted.\nThe specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".' + body_template = E'Hi {{.UserName}}\n\nYour workspace **{{.Labels.name}}** was deleted.\nThe specified reason was "**{{.Labels.reason}}{{ if .Labels.initiator }} ({{ .Labels.initiator }}){{end}}**".' WHERE id = 'f517da0b-cdc9-410f-ab89-a86107c420ed'; @@ -78,6 +79,6 @@ WHERE UPDATE notification_templates SET - 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}}**.' + 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}}**.' WHERE id = '2faeee0f-26cb-4e96-821c-85ccb9f71513'; diff --git a/coderd/database/migrations/000262_improve_notification_templates.up.sql b/coderd/database/migrations/000262_improve_notification_templates.up.sql index 13571cc618dfc..12dab392e2b20 100644 --- a/coderd/database/migrations/000262_improve_notification_templates.up.sql +++ b/coderd/database/migrations/000262_improve_notification_templates.up.sql @@ -4,9 +4,9 @@ UPDATE notification_templates SET body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n - E'User account **{{.Labels.suspended_account_name}}** has been suspended.\n\n' || + E'User account **{{.Labels.suspended_account_name}}** has been suspended.\n\n' || -- Mention the real name of the user who suspended the account: - E'The newly suspended account belongs to **{{.Labels.suspended_account_user_name}}** and was suspended by **{{.Labels.account_suspender_user_name}}**.' + E'The newly suspended account belongs to **{{.Labels.suspended_account_user_name}}** and was suspended by **{{.Labels.account_suspender_user_name}}**.' WHERE id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; @@ -15,7 +15,7 @@ UPDATE notification_templates SET body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n -- Mention who suspended the account: - E'Your account **{{.Labels.suspended_account_name}}** has been suspended by **{{.Labels.account_suspender_user_name}}**' + E'Your account **{{.Labels.suspended_account_name}}** has been suspended by **{{.Labels.account_suspender_user_name}}**.' WHERE id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; @@ -23,11 +23,11 @@ WHERE UPDATE notification_templates SET body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n - E'User account **{{.Labels.activated_account_name}}** has been activated.\n\n' || + E'User account **{{.Labels.activated_account_name}}** has been activated.\n\n' || -- Mention the real name of the user who activated the account: - E'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.' + E'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.' WHERE - id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; + id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; -- YourAccountActivated UPDATE notification_templates @@ -41,17 +41,17 @@ WHERE -- UserAccountCreated UPDATE notification_templates SET - body_template = E'Hi {{.UserName}},\n\n' || + body_template = E'Hi {{.UserName}},\n\n' || E'New user account **{{.Labels.created_account_name}}** has been created.\n\n' || -- Mention the real name of the user who created the account: - E'This new user account was created for **{{.Labels.created_account_user_name}}** by **{{.Labels.account_creator}}**' + E'This new user account was created for **{{.Labels.created_account_user_name}}** by **{{.Labels.account_creator}}**.' WHERE id = '4e19c0ac-94e1-4532-9515-d1801aa283b2'; -- UserAccountDeleted UPDATE notification_templates SET - body_template = E'Hi {{.UserName}},\n\n' || + body_template = E'Hi {{.UserName}},\n\n' || E'User account **{{.Labels.deleted_account_name}}** has been deleted.\n\n' || -- Mention the real name of the user who deleted the account: E'The deleted account belonged to **{{.Labels.deleted_account_user_name}}** and was deleted by **{{.Labels.account_deleter_user_name}}**.' @@ -72,8 +72,8 @@ WHERE UPDATE notification_templates SET body_template = E'Hi {{.UserName}},\n\n' || -- Add a comma and a \n -- Add a \n: - 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}}**' + 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'; @@ -119,7 +119,7 @@ WHERE -- WorkspaceManualBuildFailed UPDATE notification_templates SET - body_template = E'Hi {{.UserName}},\n\n' || + body_template = E'Hi {{.UserName}},\n\n' || E'A manual build of the workspace **{{.Labels.name}}** using the template **{{.Labels.template_name}}** failed (version: **{{.Labels.template_version_name}}**).\n\n' || -- Mention template display name: E'The template''s display name was **{{.Labels.template_display_name}}**. ' || diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index dcf207c36cace..28bd8b5190c71 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -972,7 +972,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { return } - hint := "run \"DB=ci make update-golden-files\" and commit the changes" + const hint = "run \"DB=ci make update-golden-files\" and commit the changes" wantBody, err := os.ReadFile(bodyGoldenFile) require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) From 2493556d73282381c4196c5ab6c04aeb28a1da88 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Wed, 9 Oct 2024 16:03:43 +0000 Subject: [PATCH 17/44] chore(coderd/notifications): regenerate golden files --- .../TemplateUserAccountCreated-body.md.golden | 2 +- .../TemplateWorkspaceAutoUpdated-body.md.golden | 2 +- .../TemplateYourAccountSuspended-body.md.golden | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden index 880d92a8bed2b..88a46735f0483 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden @@ -2,4 +2,4 @@ Hi Bobby, New user account **bobby** has been created. -This new user account was created for **William Tables** by **rob** \ No newline at end of file +This new user account was created for **William Tables** by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden index a2a16a7e9d179..d9f4e27cb4c6e 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden @@ -2,4 +2,4 @@ Hi Bobby, Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0). -Reason for update: **template now includes catnip** \ No newline at end of file +Reason for update: **template now includes catnip**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden index 615e24ca30f1a..86fc40401774b 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden @@ -1,3 +1,3 @@ Hi Bobby, -Your account **bobby** has been suspended by **rob** \ No newline at end of file +Your account **bobby** has been suspended by **rob**. \ No newline at end of file From eccef1cae3435a4b24e1c75c823a10f8c0525649 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Wed, 9 Oct 2024 20:02:01 +0000 Subject: [PATCH 18/44] chore(coderd/notifications): expand golden file testing for notifications --- coderd/notifications/notifications_test.go | 126 ++++++++++++------ .../TemplateTemplateDeleted-body.md.golden | 5 - .../TemplateTemplateDeleted-title.md.golden | 1 - .../TemplateTemplateDeleted.json.golden | 23 ++++ ...emplateUserAccountActivated-body.md.golden | 5 - ...mplateUserAccountActivated-title.md.golden | 1 - .../TemplateUserAccountActivated.json.golden | 23 ++++ .../TemplateUserAccountCreated-body.md.golden | 5 - ...TemplateUserAccountCreated-title.md.golden | 1 - .../TemplateUserAccountCreated.json.golden | 23 ++++ .../TemplateUserAccountDeleted-body.md.golden | 5 - ...TemplateUserAccountDeleted-title.md.golden | 1 - ...emplateUserAccountSuspended-body.md.golden | 5 - ...mplateUserAccountSuspended-title.md.golden | 1 - .../TemplateUserAccountSuspended.json.golden | 23 ++++ ...serRequestedOneTimePasscode-body.md.golden | 7 - ...erRequestedOneTimePasscode-title.md.golden | 1 - ...teUserRequestedOneTimePasscode.json.golden | 16 +++ ...emplateWorkspaceAutoUpdated-body.md.golden | 5 - ...mplateWorkspaceAutoUpdated-title.md.golden | 1 - .../TemplateWorkspaceAutoUpdated.json.golden | 23 ++++ ...ateWorkspaceAutobuildFailed-body.md.golden | 5 - ...teWorkspaceAutobuildFailed-title.md.golden | 1 - ...mplateWorkspaceAutobuildFailed.json.golden | 22 +++ ...WorkspaceBuildsFailedReport-body.md.golden | 17 --- ...orkspaceBuildsFailedReport-title.md.golden | 1 - ...ateWorkspaceBuildsFailedReport.json.golden | 60 +++++++++ .../TemplateWorkspaceDeleted-body.md.golden | 5 - .../TemplateWorkspaceDeleted-title.md.golden | 1 - .../TemplateWorkspaceDormant-body.md.golden | 5 - .../TemplateWorkspaceDormant-title.md.golden | 1 - .../TemplateWorkspaceDormant.json.golden | 25 ++++ ...eWorkspaceManualBuildFailed-body.md.golden | 5 - ...WorkspaceManualBuildFailed-title.md.golden | 1 - ...lateWorkspaceManualBuildFailed.json.golden | 27 ++++ ...eWorkspaceMarkedForDeletion-body.md.golden | 4 - ...WorkspaceMarkedForDeletion-title.md.golden | 1 - ...lateWorkspaceMarkedForDeletion.json.golden | 24 ++++ ...emplateYourAccountActivated-body.md.golden | 3 - ...mplateYourAccountActivated-title.md.golden | 1 - .../TemplateYourAccountActivated.json.golden | 22 +++ ...emplateYourAccountSuspended-body.md.golden | 3 - ...mplateYourAccountSuspended-title.md.golden | 1 - .../TemplateYourAccountSuspended.json.golden | 17 +++ 44 files changed, 415 insertions(+), 138 deletions(-) delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-title.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-title.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-title.md.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 28bd8b5190c71..e45972f987947 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -42,7 +42,6 @@ import ( "github.com/coder/coder/v2/coderd/database/dbtestutil" "github.com/coder/coder/v2/coderd/notifications" "github.com/coder/coder/v2/coderd/notifications/dispatch" - "github.com/coder/coder/v2/coderd/notifications/render" "github.com/coder/coder/v2/coderd/notifications/types" "github.com/coder/coder/v2/coderd/rbac" "github.com/coder/coder/v2/coderd/util/syncmap" @@ -938,49 +937,63 @@ func TestNotificationTemplates_Golden(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() - _, _, sql := dbtestutil.NewDBWithSQLDB(t) + ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong)) - var ( - titleTmpl string - bodyTmpl string + adminClient, _, api := coderdtest.NewWithAPI(t, nil) + db := api.Database + firstUserResponse := coderdtest.CreateFirstUser(t, adminClient) + user, err := adminClient.User(ctx, firstUserResponse.UserID.String()) + require.NoError(t, err) + + manager, err := notifications.NewManager( + defaultNotificationsConfig(database.NotificationMethodSmtp), + db, + defaultHelpers(), + createMetrics(), + api.Logger.Named("manager"), ) - err := sql. - QueryRow("SELECT title_template, body_template FROM notification_templates WHERE id = $1 LIMIT 1", tc.id). - Scan(&titleTmpl, &bodyTmpl) - require.NoError(t, err, "failed to query body template for template:", tc.id) - - title, err := render.GoTemplate(titleTmpl, tc.payload, defaultHelpers()) - require.NotContainsf(t, title, render.NoValue, "template %q is missing a label value", tc.name) - require.NoError(t, err, "failed to render notification title template") - require.NotEmpty(t, title, "title should not be empty") - - body, err := render.GoTemplate(bodyTmpl, tc.payload, defaultHelpers()) - require.NoError(t, err, "failed to render notification body template") - require.NotEmpty(t, body, "body should not be empty") - - partialName := strings.Split(t.Name(), "/")[1] - bodyGoldenFile := filepath.Join("testdata", "rendered-templates", partialName+"-body.md.golden") - titleGoldenFile := filepath.Join("testdata", "rendered-templates", partialName+"-title.md.golden") - - if *updateGoldenFiles { - err = os.MkdirAll(filepath.Dir(bodyGoldenFile), 0o755) - require.NoError(t, err, "want no error creating golden file directory") - err = os.WriteFile(bodyGoldenFile, []byte(body), 0o600) - require.NoError(t, err, "want no error writing body golden file") - err = os.WriteFile(titleGoldenFile, []byte(title), 0o600) - require.NoError(t, err, "want no error writing title golden file") - return - } + require.NoError(t, err) + + manager.WithHandlers(map[database.NotificationMethod]notifications.Handler{ + database.NotificationMethodSmtp: &goldenFileHandler{ + t: t, + updateGoldenFiles: *updateGoldenFiles, + }, + }) - const hint = "run \"DB=ci make update-golden-files\" and commit the changes" + manager.Run(ctx) - wantBody, err := os.ReadFile(bodyGoldenFile) - require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) - wantTitle, err := os.ReadFile(titleGoldenFile) - require.NoError(t, err, fmt.Sprintf("missing golden notification title file. %s", hint)) + enqueuer, err := notifications.NewStoreEnqueuer( + defaultNotificationsConfig(database.NotificationMethodSmtp), + db, + defaultHelpers(), + api.Logger.Named("manager"), + quartz.NewReal(), + ) + require.NoError(t, err) + + _, err = enqueuer.EnqueueWithData( + ctx, + user.ID, + tc.id, + tc.payload.Labels, + tc.payload.Data, + user.Username, + user.ID, + ) + require.NoError(t, err) + + err = manager.Stop(ctx) + require.NoError(t, err) + // title, err := render.GoTemplate(titleTmpl, tc.payload, defaultHelpers()) + // require.NotContainsf(t, title, render.NoValue, "template %q is missing a label value", tc.name) + // require.NoError(t, err, "failed to render notification title template") + // require.NotEmpty(t, title, "title should not be empty") + + // body, err := render.GoTemplate(bodyTmpl, tc.payload, defaultHelpers()) + // require.NoError(t, err, "failed to render notification body template") + // require.NotEmpty(t, body, "body should not be empty") - require.Equal(t, string(wantBody), body, fmt.Sprintf("rendered template body does not match golden file. If this is expected, %s", hint)) - require.Equal(t, string(wantTitle), title, fmt.Sprintf("rendered template title does not match golden file. If this is expected, %s", hint)) }) } } @@ -1285,6 +1298,41 @@ func (f *fakeHandler) Dispatcher(payload types.MessagePayload, _, _ string) (dis }, nil } +type goldenFileHandler struct { + t *testing.T + updateGoldenFiles bool +} + +func (f *goldenFileHandler) Dispatcher(payload types.MessagePayload, title, body string) (dispatch.DeliveryFunc, error) { + return func(_ context.Context, _ uuid.UUID) (retryable bool, err error) { + partialName := strings.Split(f.t.Name(), "/")[1] + goldenFile := filepath.Join("testdata", "rendered-templates", partialName+".json.golden") + + payload.Labels["_body"] = body + payload.Labels["_title"] = title + + payloadJSON, err := json.MarshalIndent(payload, "", " ") + require.NoError(f.t, err, "want no error marshaling payload to JSON") + + if *updateGoldenFiles { + err = os.MkdirAll(filepath.Dir(partialName), 0o755) + require.NoError(f.t, err, "want no error creating golden file directory") + err = os.WriteFile(goldenFile, payloadJSON, 0o600) + require.NoError(f.t, err, "want no error writing body golden file") + return + } + + const hint = "run \"DB=ci make update-golden-files\" and commit the changes" + + wantBody, err := os.ReadFile(goldenFile) + require.NoError(f.t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) + + require.Equal(f.t, string(wantBody), body, fmt.Sprintf("rendered template body does not match golden file. If this is expected, %s", hint)) + + return false, nil + }, nil +} + // noopStoreSyncer pretends to perform store syncs, but does not; leading to messages being stuck in "leased" state. type noopStoreSyncer struct { *acquireSignalingInterceptor diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden deleted file mode 100644 index ade9c87ff791a..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-body.md.golden +++ /dev/null @@ -1,5 +0,0 @@ -Hi Bobby, - -The template **bobby-template** was deleted by **rob**. - -The template's display name was **Bobby's Template**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-title.md.golden deleted file mode 100644 index c3f3db7645422..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Template "bobby-template" deleted \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden new file mode 100644 index 0000000000000..103e0897da62f --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden @@ -0,0 +1,23 @@ +{ + "_version": "1.1", + "notification_name": "Template Deleted", + "notification_template_id": "29a09665-2a4c-403f-9648-54301670e7be", + "user_id": "bb698abb-1d96-4e09-bcc6-aaa8ef756320", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "View templates", + "url": "http://test.com/templates" + } + ], + "labels": { + "_body": "Hi Test User,\n\nThe template **bobby-template** was deleted by **rob**.\n\nThe template's display name was **Bobby's Template**.", + "_title": "Template \"bobby-template\" deleted", + "display_name": "Bobby's Template", + "initiator": "rob", + "name": "bobby-template" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden deleted file mode 100644 index 5a773a51dc181..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-body.md.golden +++ /dev/null @@ -1,5 +0,0 @@ -Hi Bobby, - -User account **bobby** has been activated. - -The newly activated account belongs to **william tables** and was activated by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-title.md.golden deleted file mode 100644 index ebf8e9da36934..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -User account "bobby" activated \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden new file mode 100644 index 0000000000000..3ceda2526a348 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden @@ -0,0 +1,23 @@ +{ + "_version": "1.1", + "notification_name": "User account activated", + "notification_template_id": "9f5af851-8408-4e73-a7a1-c6502ba46689", + "user_id": "5c97ed8d-11ec-4e50-a9a0-bc6edeefddcd", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "View accounts", + "url": "http://test.com/deployment/users?filter=status%3Aactive" + } + ], + "labels": { + "_body": "Hi Test User,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **william tables** and was activated by **rob**.", + "_title": "User account \"bobby\" activated", + "account_activator_user_name": "rob", + "activated_account_name": "bobby", + "activated_account_user_name": "william tables" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden deleted file mode 100644 index 88a46735f0483..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-body.md.golden +++ /dev/null @@ -1,5 +0,0 @@ -Hi Bobby, - -New user account **bobby** has been created. - -This new user account was created for **William Tables** by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-title.md.golden deleted file mode 100644 index bfcdf6826f772..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -User account "bobby" created \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden new file mode 100644 index 0000000000000..03f3d456ec232 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden @@ -0,0 +1,23 @@ +{ + "_version": "1.1", + "notification_name": "User account created", + "notification_template_id": "4e19c0ac-94e1-4532-9515-d1801aa283b2", + "user_id": "3f16ed84-73d9-4209-bce7-5a7eced0437b", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "View accounts", + "url": "http://test.com/deployment/users?filter=status%3Aactive" + } + ], + "labels": { + "_body": "Hi Test User,\n\nNew user account **bobby** has been created.\n\nThis new user account was created for **William Tables** by **rob**.", + "_title": "User account \"bobby\" created", + "account_creator": "rob", + "created_account_name": "bobby", + "created_account_user_name": "William Tables" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden deleted file mode 100644 index 4ca8bedd0ca52..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-body.md.golden +++ /dev/null @@ -1,5 +0,0 @@ -Hi Bobby, - -User account **bobby** has been deleted. - -The deleted account belonged to **william tables** and was deleted by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-title.md.golden deleted file mode 100644 index 199d4ddd66d12..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -User account "bobby" deleted \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden deleted file mode 100644 index ecf276504ebc9..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-body.md.golden +++ /dev/null @@ -1,5 +0,0 @@ -Hi Bobby, - -User account **bobby** has been suspended. - -The newly suspended account belongs to **william tables** and was suspended by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-title.md.golden deleted file mode 100644 index f2be8e201f0af..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -User account "bobby" suspended \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden new file mode 100644 index 0000000000000..f0feefbd722c4 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden @@ -0,0 +1,23 @@ +{ + "_version": "1.1", + "notification_name": "User account suspended", + "notification_template_id": "b02ddd82-4733-4d02-a2d7-c36f3598997d", + "user_id": "4a89cdf1-b8b0-46a0-8c32-2656520b8b8c", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "View suspended accounts", + "url": "http://test.com/deployment/users?filter=status%3Asuspended" + } + ], + "labels": { + "_body": "Hi Test User,\n\nUser account **bobby** has been suspended.\n\nThe newly suspended account belongs to **william tables** and was suspended by **rob**.", + "_title": "User account \"bobby\" suspended", + "account_suspender_user_name": "rob", + "suspended_account_name": "bobby", + "suspended_account_user_name": "william tables" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode-body.md.golden deleted file mode 100644 index 6288af33f867e..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode-body.md.golden +++ /dev/null @@ -1,7 +0,0 @@ -Hi Bobby, - -A request to reset the password for your Coder account has been made. Your one-time passcode is: - -**fad9020b-6562-4cdb-87f1-0486f1bea415** - -If you did not request to reset your password, you can ignore this message. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode-title.md.golden deleted file mode 100644 index ecf7383911053..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Your One-Time Passcode for Coder. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden new file mode 100644 index 0000000000000..db47af6a59c8e --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden @@ -0,0 +1,16 @@ +{ + "_version": "1.1", + "notification_name": "One-Time Passcode", + "notification_template_id": "62f86a30-2330-4b61-a26d-311ff3b608cf", + "user_id": "a218d7ba-85a6-462e-a954-a3ac6609b211", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [], + "labels": { + "_body": "Hi Test User,\n\nA request to reset the password for your Coder account has been made. Your one-time passcode is:\n\n**fad9020b-6562-4cdb-87f1-0486f1bea415**\n\nIf you did not request to reset your password, you can ignore this message.", + "_title": "Your One-Time Passcode for Coder.", + "one_time_passcode": "fad9020b-6562-4cdb-87f1-0486f1bea415" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden deleted file mode 100644 index d9f4e27cb4c6e..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-body.md.golden +++ /dev/null @@ -1,5 +0,0 @@ -Hi Bobby, - -Your workspace **bobby-workspace** has been updated automatically to the latest template version (1.0). - -Reason for update: **template now includes catnip**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-title.md.golden deleted file mode 100644 index fb62dcd0d3692..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Workspace "bobby-workspace" updated automatically \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden new file mode 100644 index 0000000000000..fd00250688761 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden @@ -0,0 +1,23 @@ +{ + "_version": "1.1", + "notification_name": "Workspace Updated Automatically", + "notification_template_id": "c34a0c09-0704-4cac-bd1c-0c0146811c2b", + "user_id": "83aa673b-336d-4a4f-b53a-c6f922147496", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "View workspace", + "url": "http://test.com/@testuser/bobby-workspace" + } + ], + "labels": { + "_body": "Hi Test User,\n\nYour workspace **bobby-workspace** has been updated automatically to the latest template version (1.0).\n\nReason for update: **template now includes catnip**.", + "_title": "Workspace \"bobby-workspace\" updated automatically", + "name": "bobby-workspace", + "template_version_message": "template now includes catnip", + "template_version_name": "1.0" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden deleted file mode 100644 index cddf2149d0d46..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-body.md.golden +++ /dev/null @@ -1,5 +0,0 @@ -Hi Bobby, - -Automatic build of your workspace **bobby-workspace** failed. - -The specified reason was "**autostart**". \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-title.md.golden deleted file mode 100644 index 9cf98bc9e546a..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Workspace "bobby-workspace" autobuild failed \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden new file mode 100644 index 0000000000000..83804bc2b6f6a --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden @@ -0,0 +1,22 @@ +{ + "_version": "1.1", + "notification_name": "Workspace Autobuild Failed", + "notification_template_id": "381df2a9-c0c0-4749-420f-80a9280c66f9", + "user_id": "bde72088-2e02-45a9-a2bf-6e26242b6964", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "View workspace", + "url": "http://test.com/@testuser/bobby-workspace" + } + ], + "labels": { + "_body": "Hi Test User,\n\nAutomatic build of your workspace **bobby-workspace** failed.\n\nThe specified reason was \"**autostart**\".", + "_title": "Workspace \"bobby-workspace\" autobuild failed", + "name": "bobby-workspace", + "reason": "autostart" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport-body.md.golden deleted file mode 100644 index e896a0a8c9e51..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport-body.md.golden +++ /dev/null @@ -1,17 +0,0 @@ -Hi Bobby, - -Template **Bobby First Template** has failed to build 4/55 times over the last week. - -**Report:** - -**bobby-template-version-1** failed 3 times: - -* [mtojek / workspace-1 / #1234](http://test.com/@mtojek/workspace-1/builds/1234) -* [johndoe / my-workspace-3 / #5678](http://test.com/@johndoe/my-workspace-3/builds/5678) -* [jack / workwork / #774](http://test.com/@jack/workwork/builds/774) - -**bobby-template-version-2** failed 1 time: - -* [ben / cool-workspace / #8888](http://test.com/@ben/cool-workspace/builds/8888) - -We recommend reviewing these issues to ensure future builds are successful. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport-title.md.golden deleted file mode 100644 index f03f8fca96c7c..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Workspace builds failed for template "Bobby First Template" \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden new file mode 100644 index 0000000000000..782715bbaf689 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden @@ -0,0 +1,60 @@ +{ + "_version": "1.1", + "notification_name": "Report: Workspace Builds Failed For Template", + "notification_template_id": "34a20db2-e9cc-4a93-b0e4-8569699d7a00", + "user_id": "0a8fde87-3865-41ce-8e97-47911648d42d", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "View workspaces", + "url": "http://test.com/workspaces?filter=template%3Abobby-first-template" + } + ], + "labels": { + "_body": "Hi Test User,\n\nTemplate **Bobby First Template** has failed to build 4/55 times over the last week.\n\n**Report:**\n\n**bobby-template-version-1** failed 3 times:\n\n* [mtojek / workspace-1 / #1234](http://test.com/@mtojek/workspace-1/builds/1234)\n* [johndoe / my-workspace-3 / #5678](http://test.com/@johndoe/my-workspace-3/builds/5678)\n* [jack / workwork / #774](http://test.com/@jack/workwork/builds/774)\n\n**bobby-template-version-2** failed 1 time:\n\n* [ben / cool-workspace / #8888](http://test.com/@ben/cool-workspace/builds/8888)\n\nWe recommend reviewing these issues to ensure future builds are successful.", + "_title": "Workspace builds failed for template \"Bobby First Template\"", + "template_display_name": "Bobby First Template", + "template_name": "bobby-first-template" + }, + "data": { + "failed_builds": 4, + "report_frequency": "week", + "template_versions": [ + { + "failed_builds": [ + { + "build_number": 1234, + "workspace_name": "workspace-1", + "workspace_owner_username": "mtojek" + }, + { + "build_number": 5678, + "workspace_name": "my-workspace-3", + "workspace_owner_username": "johndoe" + }, + { + "build_number": 774, + "workspace_name": "workwork", + "workspace_owner_username": "jack" + } + ], + "failed_count": 3, + "template_version_name": "bobby-template-version-1" + }, + { + "failed_builds": [ + { + "build_number": 8888, + "workspace_name": "cool-workspace", + "workspace_owner_username": "ben" + } + ], + "failed_count": 1, + "template_version_name": "bobby-template-version-2" + } + ], + "total_builds": 55 + } +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden deleted file mode 100644 index a5c71fb3e0170..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-body.md.golden +++ /dev/null @@ -1,5 +0,0 @@ -Hi Bobby, - -Your workspace **bobby-workspace** was deleted. - -The specified reason was "**autodeleted due to dormancy (autobuild)**". \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-title.md.golden deleted file mode 100644 index 6806624053eb9..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Workspace "bobby-workspace" deleted \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden deleted file mode 100644 index 35bfe8d2c19b6..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-body.md.golden +++ /dev/null @@ -1,5 +0,0 @@ -Hi Bobby, - -Your workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity. -Dormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity. -To prevent deletion, use your workspace with the link below. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-title.md.golden deleted file mode 100644 index ce34a2a029ab4..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Workspace "bobby-workspace" marked as dormant \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden new file mode 100644 index 0000000000000..f153b28968fa0 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden @@ -0,0 +1,25 @@ +{ + "_version": "1.1", + "notification_name": "Workspace Marked as Dormant", + "notification_template_id": "0ea69165-ec14-4314-91f1-69566ac3c5a0", + "user_id": "4bf300d5-b3c6-4673-9bed-cd4a2cfe6a75", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "View workspace", + "url": "http://test.com/@testuser/bobby-workspace" + } + ], + "labels": { + "_body": "Hi Test User,\n\nYour workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity.\nDormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity.\nTo prevent deletion, use your workspace with the link below.", + "_title": "Workspace \"bobby-workspace\" marked as dormant", + "dormancyHours": "24", + "initiator": "autobuild", + "name": "bobby-workspace", + "reason": "breached the template's threshold for inactivity", + "timeTilDormant": "24 hours" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden deleted file mode 100644 index e1091b2888830..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-body.md.golden +++ /dev/null @@ -1,5 +0,0 @@ -Hi Bobby, - -A manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**). - -The template's display name was **William's Template**. The workspace build was initiated by **joe**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-title.md.golden deleted file mode 100644 index e786626b74672..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Workspace "bobby-workspace" manual build failed \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden new file mode 100644 index 0000000000000..9831f45cc3bdf --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden @@ -0,0 +1,27 @@ +{ + "_version": "1.1", + "notification_name": "Workspace Manual Build Failed", + "notification_template_id": "2faeee0f-26cb-4e96-821c-85ccb9f71513", + "user_id": "d1baee94-c5cf-4daf-a00d-2c3ac8041d38", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "View build", + "url": "http://test.com/@mrbobby/bobby-workspace/builds/3" + } + ], + "labels": { + "_body": "Hi Test User,\n\nA manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).\n\nThe template's display name was **William's Template**. The workspace build was initiated by **joe**.", + "_title": "Workspace \"bobby-workspace\" manual build failed", + "initiator": "joe", + "name": "bobby-workspace", + "template_display_name": "William's Template", + "template_name": "bobby-template", + "template_version_name": "bobby-template-version", + "workspace_build_number": "3", + "workspace_owner_username": "mrbobby" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden deleted file mode 100644 index 21defa7c1d500..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-body.md.golden +++ /dev/null @@ -1,4 +0,0 @@ -Hi Bobby, - -Your workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy. -To prevent deletion, use your workspace with the link below. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-title.md.golden deleted file mode 100644 index 1b561a73678de..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Workspace "bobby-workspace" marked for deletion \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden new file mode 100644 index 0000000000000..b797545afa528 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden @@ -0,0 +1,24 @@ +{ + "_version": "1.1", + "notification_name": "Workspace Marked for Deletion", + "notification_template_id": "51ce2fdf-c9ca-4be1-8d70-628674f9bc42", + "user_id": "6b57b167-ac12-4948-a3d3-f1d1002e1ad0", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "View workspace", + "url": "http://test.com/@testuser/bobby-workspace" + } + ], + "labels": { + "_body": "Hi Test User,\n\nYour workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy.\nTo prevent deletion, use your workspace with the link below.", + "_title": "Workspace \"bobby-workspace\" marked for deletion", + "dormancyHours": "24", + "name": "bobby-workspace", + "reason": "template updated to new dormancy policy", + "timeTilDormant": "24 hours" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden deleted file mode 100644 index a3a8710de4673..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-body.md.golden +++ /dev/null @@ -1,3 +0,0 @@ -Hi Bobby, - -Your account **bobby** has been activated by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-title.md.golden deleted file mode 100644 index 90be1ef2dd63c..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Your account "bobby" has been activated \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden new file mode 100644 index 0000000000000..0b62afdf335ee --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden @@ -0,0 +1,22 @@ +{ + "_version": "1.1", + "notification_name": "Your account has been activated", + "notification_template_id": "1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4", + "user_id": "f6266a4d-bc5f-4789-98f4-838f63f577d1", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [ + { + "label": "Open Coder", + "url": "http://test.com" + } + ], + "labels": { + "_body": "Hi Test User,\n\nYour account **bobby** has been activated by **rob**.", + "_title": "Your account \"bobby\" has been activated", + "account_activator_user_name": "rob", + "activated_account_name": "bobby" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden deleted file mode 100644 index 86fc40401774b..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-body.md.golden +++ /dev/null @@ -1,3 +0,0 @@ -Hi Bobby, - -Your account **bobby** has been suspended by **rob**. \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-title.md.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-title.md.golden deleted file mode 100644 index 3a4cb57c8aac0..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended-title.md.golden +++ /dev/null @@ -1 +0,0 @@ -Your account "bobby" has been suspended \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden new file mode 100644 index 0000000000000..02974a4e9650c --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden @@ -0,0 +1,17 @@ +{ + "_version": "1.1", + "notification_name": "Your account has been suspended", + "notification_template_id": "6a2f0609-9b69-4d36-a989-9f5925b6cbff", + "user_id": "efa9b662-1c70-45b9-b1c5-830ba6f05222", + "user_email": "testuser@coder.com", + "user_name": "Test User", + "user_username": "testuser", + "actions": [], + "labels": { + "_body": "Hi Test User,\n\nYour account **bobby** has been suspended by **rob**.", + "_title": "Your account \"bobby\" has been suspended", + "account_suspender_user_name": "rob", + "suspended_account_name": "bobby" + }, + "data": null +} \ No newline at end of file From 0036006c7eddc8b1b535fd68ed266939f684a5dd Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Wed, 9 Oct 2024 21:16:45 +0000 Subject: [PATCH 19/44] chore(coderd/notifications): ensure that notification golden files are static --- coderd/notifications/notifications_test.go | 84 +++++++++++++++---- .../TemplateTemplateDeleted.json.golden | 10 +-- .../TemplateUserAccountActivated.json.golden | 10 +-- .../TemplateUserAccountCreated.json.golden | 10 +-- .../TemplateUserAccountDeleted.json.golden | 23 +++++ .../TemplateUserAccountSuspended.json.golden | 10 +-- ...teUserRequestedOneTimePasscode.json.golden | 10 +-- .../TemplateWorkspaceAutoUpdated.json.golden | 12 +-- ...mplateWorkspaceAutobuildFailed.json.golden | 12 +-- ...ateWorkspaceBuildsFailedReport.json.golden | 10 +-- .../TemplateWorkspaceDeleted.json.golden | 27 ++++++ .../TemplateWorkspaceDormant.json.golden | 12 +-- ...lateWorkspaceManualBuildFailed.json.golden | 10 +-- ...lateWorkspaceMarkedForDeletion.json.golden | 12 +-- .../TemplateYourAccountActivated.json.golden | 10 +-- .../TemplateYourAccountSuspended.json.golden | 10 +-- 16 files changed, 185 insertions(+), 87 deletions(-) create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted.json.golden create mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted.json.golden diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index e45972f987947..97937dd53ebee 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -699,7 +699,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateWorkspaceDeleted", id: notifications.TemplateWorkspaceDeleted, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "name": "bobby-workspace", "reason": "autodeleted due to dormancy", @@ -711,7 +713,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateWorkspaceAutobuildFailed", id: notifications.TemplateWorkspaceAutobuildFailed, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "name": "bobby-workspace", "reason": "autostart", @@ -722,7 +726,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateWorkspaceDormant", id: notifications.TemplateWorkspaceDormant, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "name": "bobby-workspace", "reason": "breached the template's threshold for inactivity", @@ -736,7 +742,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateWorkspaceAutoUpdated", id: notifications.TemplateWorkspaceAutoUpdated, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "name": "bobby-workspace", "template_version_name": "1.0", @@ -748,7 +756,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateWorkspaceMarkedForDeletion", id: notifications.TemplateWorkspaceMarkedForDeletion, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "name": "bobby-workspace", "reason": "template updated to new dormancy policy", @@ -761,7 +771,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateUserAccountCreated", id: notifications.TemplateUserAccountCreated, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "created_account_name": "bobby", "created_account_user_name": "William Tables", @@ -773,7 +785,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateUserAccountDeleted", id: notifications.TemplateUserAccountDeleted, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "deleted_account_name": "bobby", "deleted_account_user_name": "william tables", @@ -785,7 +799,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateUserAccountSuspended", id: notifications.TemplateUserAccountSuspended, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "suspended_account_name": "bobby", "suspended_account_user_name": "william tables", @@ -797,7 +813,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateUserAccountActivated", id: notifications.TemplateUserAccountActivated, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "activated_account_name": "bobby", "activated_account_user_name": "william tables", @@ -809,7 +827,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateYourAccountSuspended", id: notifications.TemplateYourAccountSuspended, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "suspended_account_name": "bobby", "account_suspender_user_name": "rob", @@ -820,7 +840,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateYourAccountActivated", id: notifications.TemplateYourAccountActivated, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "activated_account_name": "bobby", "account_activator_user_name": "rob", @@ -831,7 +853,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateTemplateDeleted", id: notifications.TemplateTemplateDeleted, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "name": "bobby-template", "display_name": "Bobby's Template", @@ -843,7 +867,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateWorkspaceManualBuildFailed", id: notifications.TemplateWorkspaceManualBuildFailed, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "name": "bobby-workspace", "template_name": "bobby-template", @@ -859,7 +885,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateWorkspaceBuildsFailedReport", id: notifications.TemplateWorkspaceBuildsFailedReport, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "template_name": "bobby-first-template", "template_display_name": "Bobby First Template", @@ -910,7 +938,9 @@ func TestNotificationTemplates_Golden(t *testing.T) { name: "TemplateUserRequestedOneTimePasscode", id: notifications.TemplateUserRequestedOneTimePasscode, payload: types.MessagePayload{ - UserName: "Bobby", + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", Labels: map[string]string{ "one_time_passcode": "fad9020b-6562-4cdb-87f1-0486f1bea415", }, @@ -941,9 +971,19 @@ func TestNotificationTemplates_Golden(t *testing.T) { adminClient, _, api := coderdtest.NewWithAPI(t, nil) db := api.Database - firstUserResponse := coderdtest.CreateFirstUser(t, adminClient) - user, err := adminClient.User(ctx, firstUserResponse.UserID.String()) - require.NoError(t, err) + firstUser := coderdtest.CreateFirstUser(t, adminClient) + + _, user := coderdtest.CreateAnotherUserMutators( + t, + adminClient, + firstUser.OrganizationID, + []rbac.RoleIdentifier{rbac.RoleUserAdmin()}, + func(r *codersdk.CreateUserRequestWithOrgs) { + r.Username = tc.payload.UserUsername + r.Email = tc.payload.UserEmail + r.Name = tc.payload.UserName + }, + ) manager, err := notifications.NewManager( defaultNotificationsConfig(database.NotificationMethodSmtp), @@ -1308,6 +1348,14 @@ func (f *goldenFileHandler) Dispatcher(payload types.MessagePayload, title, body partialName := strings.Split(f.t.Name(), "/")[1] goldenFile := filepath.Join("testdata", "rendered-templates", partialName+".json.golden") + // UserIDs change on every test run. We need to set it to a known value to compare golden files. + payload.UserID = "00000000-0000-0000-0000-000000000000" + + // The following is done by the stmp handler during dispatch. + // By doing it here we get an accurate golden representation of + // what would have been sent. We don't need to maintain parity + // with how the SMTP handler does it. We just need an accurate + // representation of the payload, and the rendered body and title. payload.Labels["_body"] = body payload.Labels["_title"] = title diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden index 103e0897da62f..968a900bfd02e 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden @@ -2,10 +2,10 @@ "_version": "1.1", "notification_name": "Template Deleted", "notification_template_id": "29a09665-2a4c-403f-9648-54301670e7be", - "user_id": "bb698abb-1d96-4e09-bcc6-aaa8ef756320", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", "actions": [ { "label": "View templates", @@ -13,7 +13,7 @@ } ], "labels": { - "_body": "Hi Test User,\n\nThe template **bobby-template** was deleted by **rob**.\n\nThe template's display name was **Bobby's Template**.", + "_body": "Hi Bobby,\n\nThe template **bobby-template** was deleted by **rob**.\n\nThe template's display name was **Bobby's Template**.", "_title": "Template \"bobby-template\" deleted", "display_name": "Bobby's Template", "initiator": "rob", diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden index 3ceda2526a348..9222bdd2642c3 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden @@ -2,10 +2,10 @@ "_version": "1.1", "notification_name": "User account activated", "notification_template_id": "9f5af851-8408-4e73-a7a1-c6502ba46689", - "user_id": "5c97ed8d-11ec-4e50-a9a0-bc6edeefddcd", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", "actions": [ { "label": "View accounts", @@ -13,7 +13,7 @@ } ], "labels": { - "_body": "Hi Test User,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **william tables** and was activated by **rob**.", + "_body": "Hi Bobby,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **william tables** and was activated by **rob**.", "_title": "User account \"bobby\" activated", "account_activator_user_name": "rob", "activated_account_name": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden index 03f3d456ec232..7106119134807 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden @@ -2,10 +2,10 @@ "_version": "1.1", "notification_name": "User account created", "notification_template_id": "4e19c0ac-94e1-4532-9515-d1801aa283b2", - "user_id": "3f16ed84-73d9-4209-bce7-5a7eced0437b", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", "actions": [ { "label": "View accounts", @@ -13,7 +13,7 @@ } ], "labels": { - "_body": "Hi Test User,\n\nNew user account **bobby** has been created.\n\nThis new user account was created for **William Tables** by **rob**.", + "_body": "Hi Bobby,\n\nNew user account **bobby** has been created.\n\nThis new user account was created for **William Tables** by **rob**.", "_title": "User account \"bobby\" created", "account_creator": "rob", "created_account_name": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted.json.golden new file mode 100644 index 0000000000000..d787634b04f35 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted.json.golden @@ -0,0 +1,23 @@ +{ + "_version": "1.1", + "notification_name": "User account deleted", + "notification_template_id": "f44d9314-ad03-4bc8-95d0-5cad491da6b6", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View accounts", + "url": "http://test.com/deployment/users?filter=status%3Aactive" + } + ], + "labels": { + "_body": "Hi Bobby,\n\nUser account **bobby** has been deleted.\n\nThe deleted account belonged to **william tables** and was deleted by **rob**.", + "_title": "User account \"bobby\" deleted", + "account_deleter_user_name": "rob", + "deleted_account_name": "bobby", + "deleted_account_user_name": "william tables" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden index f0feefbd722c4..d63845c3cadd0 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden @@ -2,10 +2,10 @@ "_version": "1.1", "notification_name": "User account suspended", "notification_template_id": "b02ddd82-4733-4d02-a2d7-c36f3598997d", - "user_id": "4a89cdf1-b8b0-46a0-8c32-2656520b8b8c", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", "actions": [ { "label": "View suspended accounts", @@ -13,7 +13,7 @@ } ], "labels": { - "_body": "Hi Test User,\n\nUser account **bobby** has been suspended.\n\nThe newly suspended account belongs to **william tables** and was suspended by **rob**.", + "_body": "Hi Bobby,\n\nUser account **bobby** has been suspended.\n\nThe newly suspended account belongs to **william tables** and was suspended by **rob**.", "_title": "User account \"bobby\" suspended", "account_suspender_user_name": "rob", "suspended_account_name": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden index db47af6a59c8e..208e599679f26 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden @@ -2,13 +2,13 @@ "_version": "1.1", "notification_name": "One-Time Passcode", "notification_template_id": "62f86a30-2330-4b61-a26d-311ff3b608cf", - "user_id": "a218d7ba-85a6-462e-a954-a3ac6609b211", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", "actions": [], "labels": { - "_body": "Hi Test User,\n\nA request to reset the password for your Coder account has been made. Your one-time passcode is:\n\n**fad9020b-6562-4cdb-87f1-0486f1bea415**\n\nIf you did not request to reset your password, you can ignore this message.", + "_body": "Hi Bobby,\n\nA request to reset the password for your Coder account has been made. Your one-time passcode is:\n\n**fad9020b-6562-4cdb-87f1-0486f1bea415**\n\nIf you did not request to reset your password, you can ignore this message.", "_title": "Your One-Time Passcode for Coder.", "one_time_passcode": "fad9020b-6562-4cdb-87f1-0486f1bea415" }, diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden index fd00250688761..d86a5ffda7e83 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden @@ -2,18 +2,18 @@ "_version": "1.1", "notification_name": "Workspace Updated Automatically", "notification_template_id": "c34a0c09-0704-4cac-bd1c-0c0146811c2b", - "user_id": "83aa673b-336d-4a4f-b53a-c6f922147496", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "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/@testuser/bobby-workspace" + "url": "http://test.com/@bobby/bobby-workspace" } ], "labels": { - "_body": "Hi Test User,\n\nYour workspace **bobby-workspace** has been updated automatically to the latest template version (1.0).\n\nReason for update: **template now includes catnip**.", + "_body": "Hi Bobby,\n\nYour workspace **bobby-workspace** has been updated automatically to the latest template version (1.0).\n\nReason for update: **template now includes catnip**.", "_title": "Workspace \"bobby-workspace\" updated automatically", "name": "bobby-workspace", "template_version_message": "template now includes catnip", diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden index 83804bc2b6f6a..3b33753608a3b 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden @@ -2,18 +2,18 @@ "_version": "1.1", "notification_name": "Workspace Autobuild Failed", "notification_template_id": "381df2a9-c0c0-4749-420f-80a9280c66f9", - "user_id": "bde72088-2e02-45a9-a2bf-6e26242b6964", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "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/@testuser/bobby-workspace" + "url": "http://test.com/@bobby/bobby-workspace" } ], "labels": { - "_body": "Hi Test User,\n\nAutomatic build of your workspace **bobby-workspace** failed.\n\nThe specified reason was \"**autostart**\".", + "_body": "Hi Bobby,\n\nAutomatic build of your workspace **bobby-workspace** failed.\n\nThe specified reason was \"**autostart**\".", "_title": "Workspace \"bobby-workspace\" autobuild failed", "name": "bobby-workspace", "reason": "autostart" diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden index 782715bbaf689..5a11822d85289 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden @@ -2,10 +2,10 @@ "_version": "1.1", "notification_name": "Report: Workspace Builds Failed For Template", "notification_template_id": "34a20db2-e9cc-4a93-b0e4-8569699d7a00", - "user_id": "0a8fde87-3865-41ce-8e97-47911648d42d", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", "actions": [ { "label": "View workspaces", @@ -13,7 +13,7 @@ } ], "labels": { - "_body": "Hi Test User,\n\nTemplate **Bobby First Template** has failed to build 4/55 times over the last week.\n\n**Report:**\n\n**bobby-template-version-1** failed 3 times:\n\n* [mtojek / workspace-1 / #1234](http://test.com/@mtojek/workspace-1/builds/1234)\n* [johndoe / my-workspace-3 / #5678](http://test.com/@johndoe/my-workspace-3/builds/5678)\n* [jack / workwork / #774](http://test.com/@jack/workwork/builds/774)\n\n**bobby-template-version-2** failed 1 time:\n\n* [ben / cool-workspace / #8888](http://test.com/@ben/cool-workspace/builds/8888)\n\nWe recommend reviewing these issues to ensure future builds are successful.", + "_body": "Hi Bobby,\n\nTemplate **Bobby First Template** has failed to build 4/55 times over the last week.\n\n**Report:**\n\n**bobby-template-version-1** failed 3 times:\n\n* [mtojek / workspace-1 / #1234](http://test.com/@mtojek/workspace-1/builds/1234)\n* [johndoe / my-workspace-3 / #5678](http://test.com/@johndoe/my-workspace-3/builds/5678)\n* [jack / workwork / #774](http://test.com/@jack/workwork/builds/774)\n\n**bobby-template-version-2** failed 1 time:\n\n* [ben / cool-workspace / #8888](http://test.com/@ben/cool-workspace/builds/8888)\n\nWe recommend reviewing these issues to ensure future builds are successful.", "_title": "Workspace builds failed for template \"Bobby First Template\"", "template_display_name": "Bobby First Template", "template_name": "bobby-first-template" diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted.json.golden new file mode 100644 index 0000000000000..86cb7d43b59ff --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted.json.golden @@ -0,0 +1,27 @@ +{ + "_version": "1.1", + "notification_name": "Workspace Deleted", + "notification_template_id": "f517da0b-cdc9-410f-ab89-a86107c420ed", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View workspaces", + "url": "http://test.com/workspaces" + }, + { + "label": "View templates", + "url": "http://test.com/templates" + } + ], + "labels": { + "_body": "Hi Bobby,\n\nYour workspace **bobby-workspace** was deleted.\n\nThe specified reason was \"**autodeleted due to dormancy (autobuild)**\".", + "_title": "Workspace \"bobby-workspace\" deleted", + "initiator": "autobuild", + "name": "bobby-workspace", + "reason": "autodeleted due to dormancy" + }, + "data": null +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden index f153b28968fa0..e884ae6a124a8 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden @@ -2,18 +2,18 @@ "_version": "1.1", "notification_name": "Workspace Marked as Dormant", "notification_template_id": "0ea69165-ec14-4314-91f1-69566ac3c5a0", - "user_id": "4bf300d5-b3c6-4673-9bed-cd4a2cfe6a75", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "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/@testuser/bobby-workspace" + "url": "http://test.com/@bobby/bobby-workspace" } ], "labels": { - "_body": "Hi Test User,\n\nYour workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity.\nDormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity.\nTo prevent deletion, use your workspace with the link below.", + "_body": "Hi Bobby,\n\nYour workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity.\nDormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity.\nTo prevent deletion, use your workspace with the link below.", "_title": "Workspace \"bobby-workspace\" marked as dormant", "dormancyHours": "24", "initiator": "autobuild", diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden index 9831f45cc3bdf..3c981afce264e 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden @@ -2,10 +2,10 @@ "_version": "1.1", "notification_name": "Workspace Manual Build Failed", "notification_template_id": "2faeee0f-26cb-4e96-821c-85ccb9f71513", - "user_id": "d1baee94-c5cf-4daf-a00d-2c3ac8041d38", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", "actions": [ { "label": "View build", @@ -13,7 +13,7 @@ } ], "labels": { - "_body": "Hi Test User,\n\nA manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).\n\nThe template's display name was **William's Template**. The workspace build was initiated by **joe**.", + "_body": "Hi Bobby,\n\nA manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).\n\nThe template's display name was **William's Template**. The workspace build was initiated by **joe**.", "_title": "Workspace \"bobby-workspace\" manual build failed", "initiator": "joe", "name": "bobby-workspace", diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden index b797545afa528..9c0ec9b80c76b 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden @@ -2,18 +2,18 @@ "_version": "1.1", "notification_name": "Workspace Marked for Deletion", "notification_template_id": "51ce2fdf-c9ca-4be1-8d70-628674f9bc42", - "user_id": "6b57b167-ac12-4948-a3d3-f1d1002e1ad0", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "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/@testuser/bobby-workspace" + "url": "http://test.com/@bobby/bobby-workspace" } ], "labels": { - "_body": "Hi Test User,\n\nYour workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy.\nTo prevent deletion, use your workspace with the link below.", + "_body": "Hi Bobby,\n\nYour workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy.\nTo prevent deletion, use your workspace with the link below.", "_title": "Workspace \"bobby-workspace\" marked for deletion", "dormancyHours": "24", "name": "bobby-workspace", diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden index 0b62afdf335ee..10a6b1bc9781a 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden @@ -2,10 +2,10 @@ "_version": "1.1", "notification_name": "Your account has been activated", "notification_template_id": "1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4", - "user_id": "f6266a4d-bc5f-4789-98f4-838f63f577d1", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", "actions": [ { "label": "Open Coder", @@ -13,7 +13,7 @@ } ], "labels": { - "_body": "Hi Test User,\n\nYour account **bobby** has been activated by **rob**.", + "_body": "Hi Bobby,\n\nYour account **bobby** has been activated by **rob**.", "_title": "Your account \"bobby\" has been activated", "account_activator_user_name": "rob", "activated_account_name": "bobby" diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden index 02974a4e9650c..ccbb2de751bd5 100644 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden +++ b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden @@ -2,13 +2,13 @@ "_version": "1.1", "notification_name": "Your account has been suspended", "notification_template_id": "6a2f0609-9b69-4d36-a989-9f5925b6cbff", - "user_id": "efa9b662-1c70-45b9-b1c5-830ba6f05222", - "user_email": "testuser@coder.com", - "user_name": "Test User", - "user_username": "testuser", + "user_id": "00000000-0000-0000-0000-000000000000", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", "actions": [], "labels": { - "_body": "Hi Test User,\n\nYour account **bobby** has been suspended by **rob**.", + "_body": "Hi Bobby,\n\nYour account **bobby** has been suspended by **rob**.", "_title": "Your account \"bobby\" has been suspended", "account_suspender_user_name": "rob", "suspended_account_name": "bobby" From e9eebf322f789126816b5ee83e1d4932cf188287 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Wed, 9 Oct 2024 21:32:40 +0000 Subject: [PATCH 20/44] chore(coderd/notifications): remove defunct test assertions --- coderd/notifications/notifications_test.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 97937dd53ebee..8698c90405b29 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -1025,14 +1025,6 @@ func TestNotificationTemplates_Golden(t *testing.T) { err = manager.Stop(ctx) require.NoError(t, err) - // title, err := render.GoTemplate(titleTmpl, tc.payload, defaultHelpers()) - // require.NotContainsf(t, title, render.NoValue, "template %q is missing a label value", tc.name) - // require.NoError(t, err, "failed to render notification title template") - // require.NotEmpty(t, title, "title should not be empty") - - // body, err := render.GoTemplate(bodyTmpl, tc.payload, defaultHelpers()) - // require.NoError(t, err, "failed to render notification body template") - // require.NotEmpty(t, body, "body should not be empty") }) } From 78f278724b0e13ab93a47cd7b817155a01cf1f8e Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Wed, 9 Oct 2024 21:41:31 +0000 Subject: [PATCH 21/44] chore(coderd/notifications): lint notifications_test --- coderd/notifications/notifications_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 8698c90405b29..972d52081cf54 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -967,6 +967,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() + // nolint:gocritic // Unit test. ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong)) adminClient, _, api := coderdtest.NewWithAPI(t, nil) @@ -1025,7 +1026,6 @@ func TestNotificationTemplates_Golden(t *testing.T) { err = manager.Stop(ctx) require.NoError(t, err) - }) } } @@ -1359,7 +1359,7 @@ func (f *goldenFileHandler) Dispatcher(payload types.MessagePayload, title, body require.NoError(f.t, err, "want no error creating golden file directory") err = os.WriteFile(goldenFile, payloadJSON, 0o600) require.NoError(f.t, err, "want no error writing body golden file") - return + return false, nil } const hint = "run \"DB=ci make update-golden-files\" and commit the changes" From 02535bba2e850086a8112c0908356b80fdc3db61 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Thu, 10 Oct 2024 10:44:34 +0000 Subject: [PATCH 22/44] feat(coderd/notifications): demonstrate the concept of smtp golden files --- coderd/notifications/dispatch/smtp_test.go | 130 ++++++++++++++++++ .../TemplateWorkspaceDeleted.golden.html | 66 +++++++++ coderd/notifications/notifications_test.go | 13 +- 3 files changed, 203 insertions(+), 6 deletions(-) create mode 100644 coderd/notifications/dispatch/testdata/rendered-templates/TemplateWorkspaceDeleted.golden.html diff --git a/coderd/notifications/dispatch/smtp_test.go b/coderd/notifications/dispatch/smtp_test.go index eb12f05ad46c7..3b0ecc05a3abd 100644 --- a/coderd/notifications/dispatch/smtp_test.go +++ b/coderd/notifications/dispatch/smtp_test.go @@ -7,6 +7,9 @@ import ( "fmt" "log" "net" + "os" + "path/filepath" + "strings" "sync" "testing" @@ -523,6 +526,133 @@ func TestSMTP(t *testing.T) { } } +func TestSMTPGolden(t *testing.T) { + t.Parallel() + + const ( + username = "bob" + password = "🤫" + + hello = "localhost" + from = "system@coder.com" + ) + + tcs := []struct { + name string + cfg codersdk.NotificationsEmailConfig + payload types.MessagePayload + // TODO: should this be part of the payload: + subject string + body string + }{ + { + name: "TemplateWorkspaceDeleted", + cfg: codersdk.NotificationsEmailConfig{ + Hello: hello, + From: from, + + Auth: codersdk.NotificationsEmailAuthConfig{ + Username: username, + Password: password, + }, + }, + payload: types.MessagePayload{ + UserName: "Bobby", + UserEmail: "bobby@coder.com", + UserUsername: "bobby", + Labels: map[string]string{ + "name": "bobby-workspace", + "reason": "autodeleted due to dormancy", + "initiator": "autobuild", + }, + }, + subject: "Workspace bobby-workspace has been deleted", + body: "Workspace bobby-workspace has been deleted due to dormancy by autobuild.", + }, + } + for _, tc := range tcs { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + ctx := testutil.Context(t, testutil.WaitShort) + + backend := NewBackend(Config{ + AuthMechanisms: []string{sasl.Login}, + + AcceptedIdentity: tc.cfg.Auth.Identity.String(), + AcceptedUsername: username, + AcceptedPassword: password, + }) + + // Create a mock SMTP server which conditionally listens for plain or TLS connections. + srv, listen, err := createMockSMTPServer(backend, false) + require.NoError(t, err) + t.Cleanup(func() { + // We expect that the server has already been closed in the test + assert.ErrorIs(t, srv.Shutdown(ctx), smtp.ErrServerClosed) + }) + + var hp serpent.HostPort + require.NoError(t, hp.Set(listen.Addr().String())) + tc.cfg.Smarthost = hp + + // Start mock SMTP server in the background. + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + assert.NoError(t, srv.Serve(listen)) + }() + + // Wait for the server to become pingable. + require.Eventually(t, func() bool { + cl, err := pingClient(listen, false, tc.cfg.TLS.StartTLS.Value()) + if err != nil { + t.Logf("smtp not yet dialable: %s", err) + return false + } + + if err = cl.Noop(); err != nil { + t.Logf("smtp not yet noopable: %s", err) + return false + } + + if err = cl.Close(); err != nil { + t.Logf("smtp didn't close properly: %s", err) + return false + } + + return true + }, testutil.WaitShort, testutil.IntervalFast) + + logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true, IgnoredErrorIs: []error{}}).Leveled(slog.LevelDebug) + helpers := map[string]any{ + "base_url": func() string { return "http://test.com" }, + "current_year": func() string { return "2024" }, + } + handler := dispatch.NewSMTPHandler(tc.cfg, helpers, logger.Named("smtp")) + dispatchFn, err := handler.Dispatcher(tc.payload, tc.subject, tc.body) + require.NoError(t, err) + msgID := uuid.New() + retryable, err := dispatchFn(ctx, msgID) + require.NoError(t, err) + require.False(t, retryable) + + msg := backend.LastMessage() + + // msgJSON, err := json.MarshalIndent(msg, "", " ") + // require.NoError(t, err, "want no error marshaling payload to JSON") + + partialName := strings.Split(t.Name(), "/")[1] + goldenFile := filepath.Join("testdata", "rendered-templates", partialName+".golden.html") + // TODO: add flag to update golden files + err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) + require.NoError(t, err, "want no error creating golden file directory") + err = os.WriteFile(goldenFile, []byte(msg.Contents), 0o600) + require.NoError(t, err, "want no error writing body golden file") + }) + } +} + func pingClient(listen net.Listener, useTLS bool, startTLS bool) (*smtp.Client, error) { tlsCfg := &tls.Config{ // nolint:gosec // It's a test. diff --git a/coderd/notifications/dispatch/testdata/rendered-templates/TemplateWorkspaceDeleted.golden.html b/coderd/notifications/dispatch/testdata/rendered-templates/TemplateWorkspaceDeleted.golden.html new file mode 100644 index 0000000000000..8e5e065539039 --- /dev/null +++ b/coderd/notifications/dispatch/testdata/rendered-templates/TemplateWorkspaceDeleted.golden.html @@ -0,0 +1,66 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Workspace bobby-workspace has been deleted +Message-Id: 74472365-4868-463c-8325-1a0c99d12ac0@blush-whale-48 +Date: Thu, 10 Oct 2024 10:42:15 +0000 +Content-Type: multipart/alternative; boundary=32122c97f1062aa05b08887844a8756eb74e6b2de42c5bdcab2584aed1fb +MIME-Version: 1.0 + +--32122c97f1062aa05b08887844a8756eb74e6b2de42c5bdcab2584aed1fb +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Workspace bobby-workspace has been deleted due to dormancy by autobuild. + + +--32122c97f1062aa05b08887844a8756eb74e6b2de42c5bdcab2584aed1fb +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Workspace bobby-workspace has been deleted +

+
+

Workspace bobby-workspace has been deleted due to dormancy by au= +tobuild.

+
+
+ =20 +
+ +
+ + + +--32122c97f1062aa05b08887844a8756eb74e6b2de42c5bdcab2584aed1fb-- diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 972d52081cf54..33797e6f920a2 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -995,9 +995,12 @@ func TestNotificationTemplates_Golden(t *testing.T) { ) require.NoError(t, err) + partialName := strings.Split(t.Name(), "/")[1] + goldenFile := filepath.Join("testdata", "rendered-templates", partialName+".json.golden") manager.WithHandlers(map[database.NotificationMethod]notifications.Handler{ database.NotificationMethodSmtp: &goldenFileHandler{ t: t, + goldenFileName: goldenFile, updateGoldenFiles: *updateGoldenFiles, }, }) @@ -1332,14 +1335,12 @@ func (f *fakeHandler) Dispatcher(payload types.MessagePayload, _, _ string) (dis type goldenFileHandler struct { t *testing.T + goldenFileName string updateGoldenFiles bool } func (f *goldenFileHandler) Dispatcher(payload types.MessagePayload, title, body string) (dispatch.DeliveryFunc, error) { return func(_ context.Context, _ uuid.UUID) (retryable bool, err error) { - partialName := strings.Split(f.t.Name(), "/")[1] - goldenFile := filepath.Join("testdata", "rendered-templates", partialName+".json.golden") - // UserIDs change on every test run. We need to set it to a known value to compare golden files. payload.UserID = "00000000-0000-0000-0000-000000000000" @@ -1355,16 +1356,16 @@ func (f *goldenFileHandler) Dispatcher(payload types.MessagePayload, title, body require.NoError(f.t, err, "want no error marshaling payload to JSON") if *updateGoldenFiles { - err = os.MkdirAll(filepath.Dir(partialName), 0o755) + err = os.MkdirAll(filepath.Dir(f.goldenFileName), 0o755) require.NoError(f.t, err, "want no error creating golden file directory") - err = os.WriteFile(goldenFile, payloadJSON, 0o600) + err = os.WriteFile(f.goldenFileName, payloadJSON, 0o600) require.NoError(f.t, err, "want no error writing body golden file") return false, nil } const hint = "run \"DB=ci make update-golden-files\" and commit the changes" - wantBody, err := os.ReadFile(goldenFile) + wantBody, err := os.ReadFile(f.goldenFileName) require.NoError(f.t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) require.Equal(f.t, string(wantBody), body, fmt.Sprintf("rendered template body does not match golden file. If this is expected, %s", hint)) From 7e013d886419f88e9e61c225a55b7c60a98d22a0 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Thu, 10 Oct 2024 13:03:05 +0000 Subject: [PATCH 23/44] chore(coderd/notifications): move mock smtp server into its own package --- .../dispatch/{ => mock_smtp}/fixtures/ca.conf | 0 .../notifications/dispatch/{ => mock_smtp}/fixtures/ca.crt | 0 .../notifications/dispatch/{ => mock_smtp}/fixtures/ca.key | 0 .../notifications/dispatch/{ => mock_smtp}/fixtures/ca.srl | 0 .../dispatch/{ => mock_smtp}/fixtures/generate.sh | 0 .../dispatch/{ => mock_smtp}/fixtures/password.txt | 0 .../dispatch/{ => mock_smtp}/fixtures/server.conf | 0 .../dispatch/{ => mock_smtp}/fixtures/server.crt | 0 .../dispatch/{ => mock_smtp}/fixtures/server.csr | 0 .../dispatch/{ => mock_smtp}/fixtures/server.key | 0 .../dispatch/{ => mock_smtp}/fixtures/v3_ext.conf | 0 .../dispatch/{ => mock_smtp}/smtp_util_test.go | 4 ++-- coderd/notifications/dispatch/smtp_test.go | 7 ++++--- 13 files changed, 6 insertions(+), 5 deletions(-) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/ca.conf (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/ca.crt (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/ca.key (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/ca.srl (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/generate.sh (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/password.txt (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/server.conf (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/server.crt (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/server.csr (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/server.key (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/fixtures/v3_ext.conf (100%) rename coderd/notifications/dispatch/{ => mock_smtp}/smtp_util_test.go (98%) diff --git a/coderd/notifications/dispatch/fixtures/ca.conf b/coderd/notifications/dispatch/mock_smtp/fixtures/ca.conf similarity index 100% rename from coderd/notifications/dispatch/fixtures/ca.conf rename to coderd/notifications/dispatch/mock_smtp/fixtures/ca.conf diff --git a/coderd/notifications/dispatch/fixtures/ca.crt b/coderd/notifications/dispatch/mock_smtp/fixtures/ca.crt similarity index 100% rename from coderd/notifications/dispatch/fixtures/ca.crt rename to coderd/notifications/dispatch/mock_smtp/fixtures/ca.crt diff --git a/coderd/notifications/dispatch/fixtures/ca.key b/coderd/notifications/dispatch/mock_smtp/fixtures/ca.key similarity index 100% rename from coderd/notifications/dispatch/fixtures/ca.key rename to coderd/notifications/dispatch/mock_smtp/fixtures/ca.key diff --git a/coderd/notifications/dispatch/fixtures/ca.srl b/coderd/notifications/dispatch/mock_smtp/fixtures/ca.srl similarity index 100% rename from coderd/notifications/dispatch/fixtures/ca.srl rename to coderd/notifications/dispatch/mock_smtp/fixtures/ca.srl diff --git a/coderd/notifications/dispatch/fixtures/generate.sh b/coderd/notifications/dispatch/mock_smtp/fixtures/generate.sh similarity index 100% rename from coderd/notifications/dispatch/fixtures/generate.sh rename to coderd/notifications/dispatch/mock_smtp/fixtures/generate.sh diff --git a/coderd/notifications/dispatch/fixtures/password.txt b/coderd/notifications/dispatch/mock_smtp/fixtures/password.txt similarity index 100% rename from coderd/notifications/dispatch/fixtures/password.txt rename to coderd/notifications/dispatch/mock_smtp/fixtures/password.txt diff --git a/coderd/notifications/dispatch/fixtures/server.conf b/coderd/notifications/dispatch/mock_smtp/fixtures/server.conf similarity index 100% rename from coderd/notifications/dispatch/fixtures/server.conf rename to coderd/notifications/dispatch/mock_smtp/fixtures/server.conf diff --git a/coderd/notifications/dispatch/fixtures/server.crt b/coderd/notifications/dispatch/mock_smtp/fixtures/server.crt similarity index 100% rename from coderd/notifications/dispatch/fixtures/server.crt rename to coderd/notifications/dispatch/mock_smtp/fixtures/server.crt diff --git a/coderd/notifications/dispatch/fixtures/server.csr b/coderd/notifications/dispatch/mock_smtp/fixtures/server.csr similarity index 100% rename from coderd/notifications/dispatch/fixtures/server.csr rename to coderd/notifications/dispatch/mock_smtp/fixtures/server.csr diff --git a/coderd/notifications/dispatch/fixtures/server.key b/coderd/notifications/dispatch/mock_smtp/fixtures/server.key similarity index 100% rename from coderd/notifications/dispatch/fixtures/server.key rename to coderd/notifications/dispatch/mock_smtp/fixtures/server.key diff --git a/coderd/notifications/dispatch/fixtures/v3_ext.conf b/coderd/notifications/dispatch/mock_smtp/fixtures/v3_ext.conf similarity index 100% rename from coderd/notifications/dispatch/fixtures/v3_ext.conf rename to coderd/notifications/dispatch/mock_smtp/fixtures/v3_ext.conf diff --git a/coderd/notifications/dispatch/smtp_util_test.go b/coderd/notifications/dispatch/mock_smtp/smtp_util_test.go similarity index 98% rename from coderd/notifications/dispatch/smtp_util_test.go rename to coderd/notifications/dispatch/mock_smtp/smtp_util_test.go index 44cb8725c5d8c..85251b4cecbd1 100644 --- a/coderd/notifications/dispatch/smtp_util_test.go +++ b/coderd/notifications/dispatch/mock_smtp/smtp_util_test.go @@ -1,4 +1,4 @@ -package dispatch_test +package mock_smtp import ( "crypto/tls" @@ -162,7 +162,7 @@ func (*Session) Reset() {} func (*Session) Logout() error { return nil } // nolint:revive // Yes, useTLS is a control flag. -func createMockSMTPServer(be *Backend, useTLS bool) (*smtp.Server, net.Listener, error) { +func CreateMockSMTPServer(be *Backend, useTLS bool) (*smtp.Server, net.Listener, error) { // nolint:gosec tlsCfg := &tls.Config{ GetCertificate: readCert, diff --git a/coderd/notifications/dispatch/smtp_test.go b/coderd/notifications/dispatch/smtp_test.go index 3b0ecc05a3abd..f569ed42d0ea8 100644 --- a/coderd/notifications/dispatch/smtp_test.go +++ b/coderd/notifications/dispatch/smtp_test.go @@ -25,6 +25,7 @@ import ( "github.com/coder/serpent" "github.com/coder/coder/v2/coderd/notifications/dispatch" + "github.com/coder/coder/v2/coderd/notifications/dispatch/mock_smtp" "github.com/coder/coder/v2/coderd/notifications/types" "github.com/coder/coder/v2/codersdk" "github.com/coder/coder/v2/testutil" @@ -420,7 +421,7 @@ func TestSMTP(t *testing.T) { tc.cfg.ForceTLS = serpent.Bool(tc.useTLS) - backend := NewBackend(Config{ + backend := mock_smtp.NewBackend(Config{ AuthMechanisms: tc.authMechs, AcceptedIdentity: tc.cfg.Auth.Identity.String(), @@ -431,7 +432,7 @@ func TestSMTP(t *testing.T) { }) // Create a mock SMTP server which conditionally listens for plain or TLS connections. - srv, listen, err := createMockSMTPServer(backend, tc.useTLS) + srv, listen, err := mock_smtp.CreateMockSMTPServer(backend, tc.useTLS) require.NoError(t, err) t.Cleanup(func() { // We expect that the server has already been closed in the test @@ -546,7 +547,7 @@ func TestSMTPGolden(t *testing.T) { body string }{ { - name: "TemplateWorkspaceDeleted", + name: "_body", cfg: codersdk.NotificationsEmailConfig{ Hello: hello, From: from, From a3b240db43986b2e422787818ab1461e85d313b2 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 07:11:08 +0000 Subject: [PATCH 24/44] chore(coderd/notifications): new golden files for smtp and wehbook --- .../{smtp_util_test.go => server.go} | 16 + coderd/notifications/dispatch/smtp_test.go | 28 +- coderd/notifications/notifications_test.go | 303 ++++++++++++++---- .../TemplateTemplateDeleted.json.golden | 23 -- .../TemplateUserAccountActivated.json.golden | 23 -- .../TemplateUserAccountCreated.json.golden | 23 -- .../TemplateUserAccountDeleted.json.golden | 23 -- .../TemplateUserAccountSuspended.json.golden | 23 -- ...teUserRequestedOneTimePasscode.json.golden | 16 - .../TemplateWorkspaceAutoUpdated.json.golden | 23 -- ...mplateWorkspaceAutobuildFailed.json.golden | 22 -- ...ateWorkspaceBuildsFailedReport.json.golden | 60 ---- .../TemplateWorkspaceDeleted.json.golden | 27 -- .../TemplateWorkspaceDormant.json.golden | 25 -- ...lateWorkspaceManualBuildFailed.json.golden | 27 -- ...lateWorkspaceMarkedForDeletion.json.golden | 24 -- .../TemplateYourAccountActivated.json.golden | 22 -- .../TemplateYourAccountSuspended.json.golden | 17 - .../smtp/TemplateTemplateDeleted.golden.html | 83 +++++ .../TemplateUserAccountActivated.golden.html | 84 +++++ .../TemplateUserAccountCreated.golden.html | 83 +++++ .../TemplateUserAccountDeleted.golden.html | 83 +++++ .../TemplateUserAccountSuspended.golden.html | 85 +++++ ...teUserRequestedOneTimePasscode.golden.html | 80 +++++ .../TemplateWorkspaceAutoUpdated.golden.html | 83 +++++ ...mplateWorkspaceAutobuildFailed.golden.html | 82 +++++ ...ateWorkspaceBuildsFailedReport.golden.html | 126 ++++++++ .../smtp/TemplateWorkspaceDeleted.golden.html | 90 ++++++ .../smtp/TemplateWorkspaceDormant.golden.html | 90 ++++++ ...lateWorkspaceManualBuildFailed.golden.html | 86 +++++ ...lateWorkspaceMarkedForDeletion.golden.html | 84 +++++ .../TemplateYourAccountActivated.golden.html | 78 +++++ .../TemplateYourAccountSuspended.golden.html | 70 ++++ .../TemplateTemplateDeleted.golden.json | 29 ++ .../TemplateUserAccountActivated.golden.json | 29 ++ .../TemplateUserAccountCreated.golden.json | 29 ++ .../TemplateUserAccountDeleted.golden.json | 29 ++ .../TemplateUserAccountSuspended.golden.json | 29 ++ ...teUserRequestedOneTimePasscode.golden.json | 22 ++ .../TemplateWorkspaceAutoUpdated.golden.json | 29 ++ ...ateWorkspaceBuildsFailedReport.golden.json | 66 ++++ .../TemplateWorkspaceDormant.golden.json | 31 ++ ...lateWorkspaceMarkedForDeletion.golden.json | 30 ++ .../TemplateYourAccountActivated.golden.json | 28 ++ .../TemplateYourAccountSuspended.golden.json | 23 ++ 45 files changed, 1925 insertions(+), 461 deletions(-) rename coderd/notifications/dispatch/mock_smtp/{smtp_util_test.go => server.go} (92%) delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden delete mode 100644 coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.golden.html create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.golden.json create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.golden.json diff --git a/coderd/notifications/dispatch/mock_smtp/smtp_util_test.go b/coderd/notifications/dispatch/mock_smtp/server.go similarity index 92% rename from coderd/notifications/dispatch/mock_smtp/smtp_util_test.go rename to coderd/notifications/dispatch/mock_smtp/server.go index 85251b4cecbd1..1290be1bece49 100644 --- a/coderd/notifications/dispatch/mock_smtp/smtp_util_test.go +++ b/coderd/notifications/dispatch/mock_smtp/server.go @@ -203,3 +203,19 @@ func readCert(_ *tls.ClientHelloInfo) (*tls.Certificate, error) { return &crt, nil } + +func PingClient(listen net.Listener, useTLS bool, startTLS bool) (*smtp.Client, error) { + tlsCfg := &tls.Config{ + // nolint:gosec // It's a test. + InsecureSkipVerify: true, + } + + switch { + case useTLS: + return smtp.DialTLS(listen.Addr().String(), tlsCfg) + case startTLS: + return smtp.DialStartTLS(listen.Addr().String(), tlsCfg) + default: + return smtp.Dial(listen.Addr().String()) + } +} diff --git a/coderd/notifications/dispatch/smtp_test.go b/coderd/notifications/dispatch/smtp_test.go index f569ed42d0ea8..05dc0b80a2a7f 100644 --- a/coderd/notifications/dispatch/smtp_test.go +++ b/coderd/notifications/dispatch/smtp_test.go @@ -2,11 +2,9 @@ package dispatch_test import ( "bytes" - "crypto/tls" _ "embed" "fmt" "log" - "net" "os" "path/filepath" "strings" @@ -421,7 +419,7 @@ func TestSMTP(t *testing.T) { tc.cfg.ForceTLS = serpent.Bool(tc.useTLS) - backend := mock_smtp.NewBackend(Config{ + backend := mock_smtp.NewBackend(mock_smtp.Config{ AuthMechanisms: tc.authMechs, AcceptedIdentity: tc.cfg.Auth.Identity.String(), @@ -464,7 +462,7 @@ func TestSMTP(t *testing.T) { // Wait for the server to become pingable. require.Eventually(t, func() bool { - cl, err := pingClient(listen, tc.useTLS, tc.cfg.TLS.StartTLS.Value()) + cl, err := mock_smtp.PingClient(listen, tc.useTLS, tc.cfg.TLS.StartTLS.Value()) if err != nil { t.Logf("smtp not yet dialable: %s", err) return false @@ -576,7 +574,7 @@ func TestSMTPGolden(t *testing.T) { t.Parallel() ctx := testutil.Context(t, testutil.WaitShort) - backend := NewBackend(Config{ + backend := mock_smtp.NewBackend(mock_smtp.Config{ AuthMechanisms: []string{sasl.Login}, AcceptedIdentity: tc.cfg.Auth.Identity.String(), @@ -585,7 +583,7 @@ func TestSMTPGolden(t *testing.T) { }) // Create a mock SMTP server which conditionally listens for plain or TLS connections. - srv, listen, err := createMockSMTPServer(backend, false) + srv, listen, err := mock_smtp.CreateMockSMTPServer(backend, false) require.NoError(t, err) t.Cleanup(func() { // We expect that the server has already been closed in the test @@ -606,7 +604,7 @@ func TestSMTPGolden(t *testing.T) { // Wait for the server to become pingable. require.Eventually(t, func() bool { - cl, err := pingClient(listen, false, tc.cfg.TLS.StartTLS.Value()) + cl, err := mock_smtp.PingClient(listen, false, tc.cfg.TLS.StartTLS.Value()) if err != nil { t.Logf("smtp not yet dialable: %s", err) return false @@ -653,19 +651,3 @@ func TestSMTPGolden(t *testing.T) { }) } } - -func pingClient(listen net.Listener, useTLS bool, startTLS bool) (*smtp.Client, error) { - tlsCfg := &tls.Config{ - // nolint:gosec // It's a test. - InsecureSkipVerify: true, - } - - switch { - case useTLS: - return smtp.DialTLS(listen.Addr().String(), tlsCfg) - case startTLS: - return smtp.DialStartTLS(listen.Addr().String(), tlsCfg) - default: - return smtp.Dial(listen.Addr().String()) - } -} diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 33797e6f920a2..fdcec9c107d78 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -10,6 +10,7 @@ import ( "go/ast" "go/parser" "go/token" + "io" "net/http" "net/http/httptest" "net/url" @@ -25,6 +26,10 @@ import ( "golang.org/x/xerrors" + "cdr.dev/slog" + + "github.com/emersion/go-sasl" + "github.com/coder/quartz" "github.com/google/uuid" @@ -42,6 +47,7 @@ import ( "github.com/coder/coder/v2/coderd/database/dbtestutil" "github.com/coder/coder/v2/coderd/notifications" "github.com/coder/coder/v2/coderd/notifications/dispatch" + "github.com/coder/coder/v2/coderd/notifications/dispatch/mock_smtp" "github.com/coder/coder/v2/coderd/notifications/types" "github.com/coder/coder/v2/coderd/rbac" "github.com/coder/coder/v2/coderd/util/syncmap" @@ -690,6 +696,15 @@ func TestNotificationTemplates_Golden(t *testing.T) { t.Skip("This test requires postgres; it relies on the notification templates added by migrations in the database") } + const ( + username = "bob" + password = "🤫" + + hello = "localhost" + + from = "system@coder.com" + ) + tests := []struct { name string id uuid.UUID @@ -948,6 +963,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { }, } + // We must have a test case for every notification_template. This is enforced below: allTemplates, err := enumerateAllTemplates(t) require.NoError(t, err) for _, name := range allTemplates { @@ -967,68 +983,235 @@ func TestNotificationTemplates_Golden(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() - // nolint:gocritic // Unit test. - ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong)) - - adminClient, _, api := coderdtest.NewWithAPI(t, nil) - db := api.Database - firstUser := coderdtest.CreateFirstUser(t, adminClient) - - _, user := coderdtest.CreateAnotherUserMutators( - t, - adminClient, - firstUser.OrganizationID, - []rbac.RoleIdentifier{rbac.RoleUserAdmin()}, - func(r *codersdk.CreateUserRequestWithOrgs) { - r.Username = tc.payload.UserUsername - r.Email = tc.payload.UserEmail - r.Name = tc.payload.UserName - }, - ) - - manager, err := notifications.NewManager( - defaultNotificationsConfig(database.NotificationMethodSmtp), - db, - defaultHelpers(), - createMetrics(), - api.Logger.Named("manager"), - ) - require.NoError(t, err) - - partialName := strings.Split(t.Name(), "/")[1] - goldenFile := filepath.Join("testdata", "rendered-templates", partialName+".json.golden") - manager.WithHandlers(map[database.NotificationMethod]notifications.Handler{ - database.NotificationMethodSmtp: &goldenFileHandler{ - t: t, - goldenFileName: goldenFile, - updateGoldenFiles: *updateGoldenFiles, - }, + t.Run("smtp", func(t *testing.T) { + t.Parallel() + // nolint:gocritic // Unit test. + ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong)) + + // Spin up the DB + db, logger, user := func() (*database.Store, *slog.Logger, *codersdk.User) { + adminClient, _, api := coderdtest.NewWithAPI(t, nil) + db := api.Database + firstUser := coderdtest.CreateFirstUser(t, adminClient) + + _, user := coderdtest.CreateAnotherUserMutators( + t, + adminClient, + firstUser.OrganizationID, + []rbac.RoleIdentifier{rbac.RoleUserAdmin()}, + func(r *codersdk.CreateUserRequestWithOrgs) { + r.Username = tc.payload.UserUsername + r.Email = tc.payload.UserEmail + r.Name = tc.payload.UserName + }, + ) + return &db, &api.Logger, &user + }() + + // smtp config shared between client and server + smtpConfig := codersdk.NotificationsEmailConfig{ + Hello: hello, + From: from, + + Auth: codersdk.NotificationsEmailAuthConfig{ + Username: username, + Password: password, + }, + } + + // Spin up the mock SMTP server + backend := mock_smtp.NewBackend(mock_smtp.Config{ + AuthMechanisms: []string{sasl.Login}, + + AcceptedIdentity: smtpConfig.Auth.Identity.String(), + AcceptedUsername: username, + AcceptedPassword: password, + }) + + // Create a mock SMTP server which conditionally listens for plain or TLS connections. + srv, listen, err := mock_smtp.CreateMockSMTPServer(backend, false) + require.NoError(t, err) + t.Cleanup(func() { + err := srv.Shutdown(ctx) + require.NoError(t, err) + }) + + var hp serpent.HostPort + require.NoError(t, hp.Set(listen.Addr().String())) + smtpConfig.Smarthost = hp + + // Start mock SMTP server in the background. + var wg sync.WaitGroup + wg.Add(1) + go func() { + defer wg.Done() + assert.NoError(t, srv.Serve(listen)) + }() + + // Wait for the server to become pingable. + require.Eventually(t, func() bool { + cl, err := mock_smtp.PingClient(listen, false, smtpConfig.TLS.StartTLS.Value()) + if err != nil { + t.Logf("smtp not yet dialable: %s", err) + return false + } + + if err = cl.Noop(); err != nil { + t.Logf("smtp not yet noopable: %s", err) + return false + } + + if err = cl.Close(); err != nil { + t.Logf("smtp didn't close properly: %s", err) + return false + } + + return true + }, testutil.WaitShort, testutil.IntervalFast) + + smtpCfg := defaultNotificationsConfig(database.NotificationMethodSmtp) + smtpCfg.SMTP = smtpConfig + + smtpManager, err := notifications.NewManager( + smtpCfg, + *db, + defaultHelpers(), + createMetrics(), + logger.Named("manager"), + ) + require.NoError(t, err) + + smtpManager.Run(ctx) + time.Sleep(time.Second) + + notificationCfg := defaultNotificationsConfig(database.NotificationMethodSmtp) + + smtpEnqueuer, err := notifications.NewStoreEnqueuer( + notificationCfg, + *db, + defaultHelpers(), + logger.Named("enqueuer"), + quartz.NewReal(), + ) + require.NoError(t, err) + + _, err = smtpEnqueuer.EnqueueWithData( + ctx, + user.ID, + tc.id, + tc.payload.Labels, + tc.payload.Data, + user.Username, + user.ID, + ) + require.NoError(t, err) + + // Wait for the message to be fetched + time.Sleep(notificationCfg.FetchInterval.Value()) + + err = smtpManager.Stop(ctx) + require.NoError(t, err) + + msg := backend.LastMessage() + require.NotNil(t, msg, "want a message to be sent") + + partialName := strings.Split(t.Name(), "/")[1] + goldenFile := filepath.Join("testdata", "rendered-templates", "smtp", partialName+".golden.html") + // TODO: add flag to update golden files + err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) + require.NoError(t, err, "want no error creating golden file directory") + err = os.WriteFile(goldenFile, []byte(msg.Contents), 0o600) + require.NoError(t, err, "want no error writing body golden file") }) - manager.Run(ctx) - - enqueuer, err := notifications.NewStoreEnqueuer( - defaultNotificationsConfig(database.NotificationMethodSmtp), - db, - defaultHelpers(), - api.Logger.Named("manager"), - quartz.NewReal(), - ) - require.NoError(t, err) - - _, err = enqueuer.EnqueueWithData( - ctx, - user.ID, - tc.id, - tc.payload.Labels, - tc.payload.Data, - user.Username, - user.ID, - ) - require.NoError(t, err) - - err = manager.Stop(ctx) - require.NoError(t, err) + t.Run("webhook", func(t *testing.T) { + t.Parallel() + // nolint:gocritic // Unit test. + ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong)) + + // Spin up the DB + db, logger, user := func() (*database.Store, *slog.Logger, *codersdk.User) { + adminClient, _, api := coderdtest.NewWithAPI(t, nil) + db := api.Database + firstUser := coderdtest.CreateFirstUser(t, adminClient) + + _, user := coderdtest.CreateAnotherUserMutators( + t, + adminClient, + firstUser.OrganizationID, + []rbac.RoleIdentifier{rbac.RoleUserAdmin()}, + func(r *codersdk.CreateUserRequestWithOrgs) { + r.Username = tc.payload.UserUsername + r.Email = tc.payload.UserEmail + r.Name = tc.payload.UserName + }, + ) + return &db, &api.Logger, &user + }() + + // Spin up the mock webhook server + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + body, err := io.ReadAll(r.Body) + require.NoError(t, err) + var prettyJSON bytes.Buffer + err = json.Indent(&prettyJSON, body, "", " ") + require.NoError(t, err) + + partialName := strings.Split(t.Name(), "/")[1] + goldenFile := filepath.Join("testdata", "rendered-templates", "webhook", partialName+".golden.json") + // TODO: add flag to update golden files + err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) + require.NoError(t, err, "want no error creating golden file directory") + err = os.WriteFile(goldenFile, prettyJSON.Bytes(), 0o600) + require.NoError(t, err, "want no error writing body golden file") + + w.WriteHeader(http.StatusOK) + })) + t.Cleanup(server.Close) + + endpoint, err := url.Parse(server.URL) + require.NoError(t, err) + + webhookCfg := defaultNotificationsConfig(database.NotificationMethodWebhook) + + webhookCfg.Webhook = codersdk.NotificationsWebhookConfig{ + Endpoint: *serpent.URLOf(endpoint), + } + + webhookManager, err := notifications.NewManager( + webhookCfg, + *db, + defaultHelpers(), + createMetrics(), + logger.Named("manager"), + ) + require.NoError(t, err) + + webhookManager.Run(ctx) + + httpEnqueuer, err := notifications.NewStoreEnqueuer( + defaultNotificationsConfig(database.NotificationMethodWebhook), + *db, + defaultHelpers(), + logger.Named("enqueuer"), + quartz.NewReal(), + ) + require.NoError(t, err) + + _, err = httpEnqueuer.EnqueueWithData( + ctx, + user.ID, + tc.id, + tc.payload.Labels, + tc.payload.Data, + user.Username, + user.ID, + ) + require.NoError(t, err) + + err = webhookManager.Stop(ctx) + require.NoError(t, err) + }) }) } } diff --git a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden deleted file mode 100644 index 968a900bfd02e..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateTemplateDeleted.json.golden +++ /dev/null @@ -1,23 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "Template Deleted", - "notification_template_id": "29a09665-2a4c-403f-9648-54301670e7be", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View templates", - "url": "http://test.com/templates" - } - ], - "labels": { - "_body": "Hi Bobby,\n\nThe template **bobby-template** was deleted by **rob**.\n\nThe template's display name was **Bobby's Template**.", - "_title": "Template \"bobby-template\" deleted", - "display_name": "Bobby's Template", - "initiator": "rob", - "name": "bobby-template" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden deleted file mode 100644 index 9222bdd2642c3..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountActivated.json.golden +++ /dev/null @@ -1,23 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "User account activated", - "notification_template_id": "9f5af851-8408-4e73-a7a1-c6502ba46689", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View accounts", - "url": "http://test.com/deployment/users?filter=status%3Aactive" - } - ], - "labels": { - "_body": "Hi Bobby,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **william tables** and was activated by **rob**.", - "_title": "User account \"bobby\" activated", - "account_activator_user_name": "rob", - "activated_account_name": "bobby", - "activated_account_user_name": "william tables" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden deleted file mode 100644 index 7106119134807..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountCreated.json.golden +++ /dev/null @@ -1,23 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "User account created", - "notification_template_id": "4e19c0ac-94e1-4532-9515-d1801aa283b2", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View accounts", - "url": "http://test.com/deployment/users?filter=status%3Aactive" - } - ], - "labels": { - "_body": "Hi Bobby,\n\nNew user account **bobby** has been created.\n\nThis new user account was created for **William Tables** by **rob**.", - "_title": "User account \"bobby\" created", - "account_creator": "rob", - "created_account_name": "bobby", - "created_account_user_name": "William Tables" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted.json.golden deleted file mode 100644 index d787634b04f35..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountDeleted.json.golden +++ /dev/null @@ -1,23 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "User account deleted", - "notification_template_id": "f44d9314-ad03-4bc8-95d0-5cad491da6b6", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View accounts", - "url": "http://test.com/deployment/users?filter=status%3Aactive" - } - ], - "labels": { - "_body": "Hi Bobby,\n\nUser account **bobby** has been deleted.\n\nThe deleted account belonged to **william tables** and was deleted by **rob**.", - "_title": "User account \"bobby\" deleted", - "account_deleter_user_name": "rob", - "deleted_account_name": "bobby", - "deleted_account_user_name": "william tables" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden deleted file mode 100644 index d63845c3cadd0..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserAccountSuspended.json.golden +++ /dev/null @@ -1,23 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "User account suspended", - "notification_template_id": "b02ddd82-4733-4d02-a2d7-c36f3598997d", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View suspended accounts", - "url": "http://test.com/deployment/users?filter=status%3Asuspended" - } - ], - "labels": { - "_body": "Hi Bobby,\n\nUser account **bobby** has been suspended.\n\nThe newly suspended account belongs to **william tables** and was suspended by **rob**.", - "_title": "User account \"bobby\" suspended", - "account_suspender_user_name": "rob", - "suspended_account_name": "bobby", - "suspended_account_user_name": "william tables" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden deleted file mode 100644 index 208e599679f26..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateUserRequestedOneTimePasscode.json.golden +++ /dev/null @@ -1,16 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "One-Time Passcode", - "notification_template_id": "62f86a30-2330-4b61-a26d-311ff3b608cf", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [], - "labels": { - "_body": "Hi Bobby,\n\nA request to reset the password for your Coder account has been made. Your one-time passcode is:\n\n**fad9020b-6562-4cdb-87f1-0486f1bea415**\n\nIf you did not request to reset your password, you can ignore this message.", - "_title": "Your One-Time Passcode for Coder.", - "one_time_passcode": "fad9020b-6562-4cdb-87f1-0486f1bea415" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden deleted file mode 100644 index d86a5ffda7e83..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutoUpdated.json.golden +++ /dev/null @@ -1,23 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "Workspace Updated Automatically", - "notification_template_id": "c34a0c09-0704-4cac-bd1c-0c0146811c2b", - "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": { - "_body": "Hi Bobby,\n\nYour workspace **bobby-workspace** has been updated automatically to the latest template version (1.0).\n\nReason for update: **template now includes catnip**.", - "_title": "Workspace \"bobby-workspace\" updated automatically", - "name": "bobby-workspace", - "template_version_message": "template now includes catnip", - "template_version_name": "1.0" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden deleted file mode 100644 index 3b33753608a3b..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceAutobuildFailed.json.golden +++ /dev/null @@ -1,22 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "Workspace Autobuild Failed", - "notification_template_id": "381df2a9-c0c0-4749-420f-80a9280c66f9", - "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": { - "_body": "Hi Bobby,\n\nAutomatic build of your workspace **bobby-workspace** failed.\n\nThe specified reason was \"**autostart**\".", - "_title": "Workspace \"bobby-workspace\" autobuild failed", - "name": "bobby-workspace", - "reason": "autostart" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden deleted file mode 100644 index 5a11822d85289..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceBuildsFailedReport.json.golden +++ /dev/null @@ -1,60 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "Report: Workspace Builds Failed For Template", - "notification_template_id": "34a20db2-e9cc-4a93-b0e4-8569699d7a00", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View workspaces", - "url": "http://test.com/workspaces?filter=template%3Abobby-first-template" - } - ], - "labels": { - "_body": "Hi Bobby,\n\nTemplate **Bobby First Template** has failed to build 4/55 times over the last week.\n\n**Report:**\n\n**bobby-template-version-1** failed 3 times:\n\n* [mtojek / workspace-1 / #1234](http://test.com/@mtojek/workspace-1/builds/1234)\n* [johndoe / my-workspace-3 / #5678](http://test.com/@johndoe/my-workspace-3/builds/5678)\n* [jack / workwork / #774](http://test.com/@jack/workwork/builds/774)\n\n**bobby-template-version-2** failed 1 time:\n\n* [ben / cool-workspace / #8888](http://test.com/@ben/cool-workspace/builds/8888)\n\nWe recommend reviewing these issues to ensure future builds are successful.", - "_title": "Workspace builds failed for template \"Bobby First Template\"", - "template_display_name": "Bobby First Template", - "template_name": "bobby-first-template" - }, - "data": { - "failed_builds": 4, - "report_frequency": "week", - "template_versions": [ - { - "failed_builds": [ - { - "build_number": 1234, - "workspace_name": "workspace-1", - "workspace_owner_username": "mtojek" - }, - { - "build_number": 5678, - "workspace_name": "my-workspace-3", - "workspace_owner_username": "johndoe" - }, - { - "build_number": 774, - "workspace_name": "workwork", - "workspace_owner_username": "jack" - } - ], - "failed_count": 3, - "template_version_name": "bobby-template-version-1" - }, - { - "failed_builds": [ - { - "build_number": 8888, - "workspace_name": "cool-workspace", - "workspace_owner_username": "ben" - } - ], - "failed_count": 1, - "template_version_name": "bobby-template-version-2" - } - ], - "total_builds": 55 - } -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted.json.golden deleted file mode 100644 index 86cb7d43b59ff..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDeleted.json.golden +++ /dev/null @@ -1,27 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "Workspace Deleted", - "notification_template_id": "f517da0b-cdc9-410f-ab89-a86107c420ed", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View workspaces", - "url": "http://test.com/workspaces" - }, - { - "label": "View templates", - "url": "http://test.com/templates" - } - ], - "labels": { - "_body": "Hi Bobby,\n\nYour workspace **bobby-workspace** was deleted.\n\nThe specified reason was \"**autodeleted due to dormancy (autobuild)**\".", - "_title": "Workspace \"bobby-workspace\" deleted", - "initiator": "autobuild", - "name": "bobby-workspace", - "reason": "autodeleted due to dormancy" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden deleted file mode 100644 index e884ae6a124a8..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceDormant.json.golden +++ /dev/null @@ -1,25 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "Workspace Marked as Dormant", - "notification_template_id": "0ea69165-ec14-4314-91f1-69566ac3c5a0", - "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": { - "_body": "Hi Bobby,\n\nYour workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity.\nDormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity.\nTo prevent deletion, use your workspace with the link below.", - "_title": "Workspace \"bobby-workspace\" marked as dormant", - "dormancyHours": "24", - "initiator": "autobuild", - "name": "bobby-workspace", - "reason": "breached the template's threshold for inactivity", - "timeTilDormant": "24 hours" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden deleted file mode 100644 index 3c981afce264e..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceManualBuildFailed.json.golden +++ /dev/null @@ -1,27 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "Workspace Manual Build Failed", - "notification_template_id": "2faeee0f-26cb-4e96-821c-85ccb9f71513", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View build", - "url": "http://test.com/@mrbobby/bobby-workspace/builds/3" - } - ], - "labels": { - "_body": "Hi Bobby,\n\nA manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).\n\nThe template's display name was **William's Template**. The workspace build was initiated by **joe**.", - "_title": "Workspace \"bobby-workspace\" manual build failed", - "initiator": "joe", - "name": "bobby-workspace", - "template_display_name": "William's Template", - "template_name": "bobby-template", - "template_version_name": "bobby-template-version", - "workspace_build_number": "3", - "workspace_owner_username": "mrbobby" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden deleted file mode 100644 index 9c0ec9b80c76b..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateWorkspaceMarkedForDeletion.json.golden +++ /dev/null @@ -1,24 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "Workspace Marked for Deletion", - "notification_template_id": "51ce2fdf-c9ca-4be1-8d70-628674f9bc42", - "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": { - "_body": "Hi Bobby,\n\nYour workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy.\nTo prevent deletion, use your workspace with the link below.", - "_title": "Workspace \"bobby-workspace\" marked for deletion", - "dormancyHours": "24", - "name": "bobby-workspace", - "reason": "template updated to new dormancy policy", - "timeTilDormant": "24 hours" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden deleted file mode 100644 index 10a6b1bc9781a..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountActivated.json.golden +++ /dev/null @@ -1,22 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "Your account has been activated", - "notification_template_id": "1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "Open Coder", - "url": "http://test.com" - } - ], - "labels": { - "_body": "Hi Bobby,\n\nYour account **bobby** has been activated by **rob**.", - "_title": "Your account \"bobby\" has been activated", - "account_activator_user_name": "rob", - "activated_account_name": "bobby" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden deleted file mode 100644 index ccbb2de751bd5..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/TemplateYourAccountSuspended.json.golden +++ /dev/null @@ -1,17 +0,0 @@ -{ - "_version": "1.1", - "notification_name": "Your account has been suspended", - "notification_template_id": "6a2f0609-9b69-4d36-a989-9f5925b6cbff", - "user_id": "00000000-0000-0000-0000-000000000000", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [], - "labels": { - "_body": "Hi Bobby,\n\nYour account **bobby** has been suspended by **rob**.", - "_title": "Your account \"bobby\" has been suspended", - "account_suspender_user_name": "rob", - "suspended_account_name": "bobby" - }, - "data": null -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.golden.html new file mode 100644 index 0000000000000..ab5fd2bd646c9 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.golden.html @@ -0,0 +1,83 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Template "bobby-template" deleted +Message-Id: f7c231e3-3c60-40f9-87e4-e2187c33f61c@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:47 +0000 +Content-Type: multipart/alternative; boundary=c2b474e4ddaacbd4a99ed66399f8163284628d966bbbe1d7e78b3dc7fd9f +MIME-Version: 1.0 + +--c2b474e4ddaacbd4a99ed66399f8163284628d966bbbe1d7e78b3dc7fd9f +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +The template bobby-template was deleted by rob. + +The template's display name was Bobby's Template. + + +View templates: http://test.com/templates + +--c2b474e4ddaacbd4a99ed66399f8163284628d966bbbe1d7e78b3dc7fd9f +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Template "bobby-template" deleted +

+
+

Hi Bobby,

+ +

The template bobby-template was deleted by rob<= +/strong>.

+ +

The template’s display name was Bobby’s Template.

+
+
+ =20 + + View templates + + =20 +
+ +
+ + + +--c2b474e4ddaacbd4a99ed66399f8163284628d966bbbe1d7e78b3dc7fd9f-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.golden.html new file mode 100644 index 0000000000000..8da1d976aba52 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.golden.html @@ -0,0 +1,84 @@ +From: system@coder.com +To: bobby@coder.com +Subject: User account "bobby" activated +Message-Id: f53579e9-e0f6-4e5f-8b5f-ffb143ffbfc2@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:47 +0000 +Content-Type: multipart/alternative; boundary=bdd4f63bddac33f9c64dc637e930cb8b7b7a78aadfa2e26c608ecbcab9d8 +MIME-Version: 1.0 + +--bdd4f63bddac33f9c64dc637e930cb8b7b7a78aadfa2e26c608ecbcab9d8 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +User account bobby has been activated. + +The newly activated account belongs to william tables and was activated by = +rob. + + +View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive + +--bdd4f63bddac33f9c64dc637e930cb8b7b7a78aadfa2e26c608ecbcab9d8 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ User account "bobby" activated +

+
+

Hi Bobby,

+ +

User account bobby has been activated.

+ +

The newly activated account belongs to william tables a= +nd was activated by rob.

+
+
+ =20 + + View accounts + + =20 +
+ +
+ + + +--bdd4f63bddac33f9c64dc637e930cb8b7b7a78aadfa2e26c608ecbcab9d8-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.golden.html new file mode 100644 index 0000000000000..1a7e33cc1a67d --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.golden.html @@ -0,0 +1,83 @@ +From: system@coder.com +To: bobby@coder.com +Subject: User account "bobby" created +Message-Id: de6644cd-9024-4022-bcd2-26e2e16ad7a9@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:47 +0000 +Content-Type: multipart/alternative; boundary=554f2d9c541e7f980805085bf6318568f21a41b0b102c0538e52c1faf36f +MIME-Version: 1.0 + +--554f2d9c541e7f980805085bf6318568f21a41b0b102c0538e52c1faf36f +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +New user account bobby has been created. + +This new user account was created for William Tables by rob. + + +View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive + +--554f2d9c541e7f980805085bf6318568f21a41b0b102c0538e52c1faf36f +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ User account "bobby" created +

+
+

Hi Bobby,

+ +

New user account bobby has been created.

+ +

This new user account was created for William Tables by= + rob.

+
+
+ =20 + + View accounts + + =20 +
+ +
+ + + +--554f2d9c541e7f980805085bf6318568f21a41b0b102c0538e52c1faf36f-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.golden.html new file mode 100644 index 0000000000000..3a452e06f1282 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.golden.html @@ -0,0 +1,83 @@ +From: system@coder.com +To: bobby@coder.com +Subject: User account "bobby" deleted +Message-Id: 4c0b275e-1407-44de-a19c-dace68e6b569@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:48 +0000 +Content-Type: multipart/alternative; boundary=0a4f71d4690a1db88c14d9c076d11c45d7ad9f9a3296c118dc38acf001be +MIME-Version: 1.0 + +--0a4f71d4690a1db88c14d9c076d11c45d7ad9f9a3296c118dc38acf001be +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +User account bobby has been deleted. + +The deleted account belonged to william tables and was deleted by rob. + + +View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive + +--0a4f71d4690a1db88c14d9c076d11c45d7ad9f9a3296c118dc38acf001be +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ User account "bobby" deleted +

+
+

Hi Bobby,

+ +

User account bobby has been deleted.

+ +

The deleted account belonged to william tables and was = +deleted by rob.

+
+
+ =20 + + View accounts + + =20 +
+ +
+ + + +--0a4f71d4690a1db88c14d9c076d11c45d7ad9f9a3296c118dc38acf001be-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.golden.html new file mode 100644 index 0000000000000..02c7390e80b20 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.golden.html @@ -0,0 +1,85 @@ +From: system@coder.com +To: bobby@coder.com +Subject: User account "bobby" suspended +Message-Id: a8116eb1-a491-4ad5-8046-3439a8c7c2bb@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:48 +0000 +Content-Type: multipart/alternative; boundary=f966987bcfd6e14cfb8c13b387636b8bf5598e59aebd7645be43727ff3d3 +MIME-Version: 1.0 + +--f966987bcfd6e14cfb8c13b387636b8bf5598e59aebd7645be43727ff3d3 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +User account bobby has been suspended. + +The newly suspended account belongs to william tables and was suspended by = +rob. + + +View suspended accounts: http://test.com/deployment/users?filter=3Dstatus%3= +Asuspended + +--f966987bcfd6e14cfb8c13b387636b8bf5598e59aebd7645be43727ff3d3 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ User account "bobby" suspended +

+
+

Hi Bobby,

+ +

User account bobby has been suspended.

+ +

The newly suspended account belongs to william tables a= +nd was suspended by rob.

+
+ + +
+ + + +--f966987bcfd6e14cfb8c13b387636b8bf5598e59aebd7645be43727ff3d3-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.golden.html new file mode 100644 index 0000000000000..be3be35085c1a --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.golden.html @@ -0,0 +1,80 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Your One-Time Passcode for Coder. +Message-Id: 88c8e582-31e6-4340-91db-625ee94cff41@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:47 +0000 +Content-Type: multipart/alternative; boundary=8d6dd286d3988e88511d6c79b25669b6652d49c6a6cfe3e3ac22ed7c498e +MIME-Version: 1.0 + +--8d6dd286d3988e88511d6c79b25669b6652d49c6a6cfe3e3ac22ed7c498e +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +A request to reset the password for your Coder account has been made. Your = +one-time passcode is: + +fad9020b-6562-4cdb-87f1-0486f1bea415 + +If you did not request to reset your password, you can ignore this message. + + +--8d6dd286d3988e88511d6c79b25669b6652d49c6a6cfe3e3ac22ed7c498e +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Your One-Time Passcode for Coder. +

+
+

Hi Bobby,

+ +

A request to reset the password for your Coder account has been made. Yo= +ur one-time passcode is:

+ +

fad9020b-6562-4cdb-87f1-0486f1bea415

+ +

If you did not request to reset your password, you can ignore this messa= +ge.

+
+
+ =20 +
+ +
+ + + +--8d6dd286d3988e88511d6c79b25669b6652d49c6a6cfe3e3ac22ed7c498e-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.golden.html new file mode 100644 index 0000000000000..2dc40797c2c83 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.golden.html @@ -0,0 +1,83 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Workspace "bobby-workspace" updated automatically +Message-Id: 020bbf88-d7c2-4288-a793-77c71ad280ab@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:46 +0000 +Content-Type: multipart/alternative; boundary=a1bf50e5d03b4b474dcc7ff5ca29c57d75c87b5a5818af1ea4c70c74b929 +MIME-Version: 1.0 + +--a1bf50e5d03b4b474dcc7ff5ca29c57d75c87b5a5818af1ea4c70c74b929 +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). + +Reason for update: template now includes catnip. + + +View workspace: http://test.com/@bobby/bobby-workspace + +--a1bf50e5d03b4b474dcc7ff5ca29c57d75c87b5a5818af1ea4c70c74b929 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Workspace "bobby-workspace" updated automatically +

+
+

Hi Bobby,

+ +

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

+ +

Reason for update: template now includes catnip.

+
+
+ =20 + + View workspace + + =20 +
+ +
+ + + +--a1bf50e5d03b4b474dcc7ff5ca29c57d75c87b5a5818af1ea4c70c74b929-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.golden.html new file mode 100644 index 0000000000000..5720d51170674 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.golden.html @@ -0,0 +1,82 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Workspace "bobby-workspace" autobuild failed +Message-Id: 85797188-c342-42d4-baf8-82fa28ae0e5e@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:46 +0000 +Content-Type: multipart/alternative; boundary=22e99bbaa4b5e4842cfbfa98ce86e72701d3f527d851608b4264914714de +MIME-Version: 1.0 + +--22e99bbaa4b5e4842cfbfa98ce86e72701d3f527d851608b4264914714de +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +Automatic build of your workspace bobby-workspace failed. + +The specified reason was "autostart". + + +View workspace: http://test.com/@bobby/bobby-workspace + +--22e99bbaa4b5e4842cfbfa98ce86e72701d3f527d851608b4264914714de +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Workspace "bobby-workspace" autobuild failed +

+
+

Hi Bobby,

+ +

Automatic build of your workspace bobby-workspace faile= +d.

+ +

The specified reason was “autostart”.

+
+
+ =20 + + View workspace + + =20 +
+ +
+ + + +--22e99bbaa4b5e4842cfbfa98ce86e72701d3f527d851608b4264914714de-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.golden.html new file mode 100644 index 0000000000000..62ae6b7624e15 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.golden.html @@ -0,0 +1,126 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Workspace builds failed for template "Bobby First Template" +Message-Id: 016fdea9-c110-4400-b4ee-01226ba4cca6@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:49 +0000 +Content-Type: multipart/alternative; boundary=efa4000d6a58234bb16aadeb7154404af355eee48b6c092305731104fb86 +MIME-Version: 1.0 + +--efa4000d6a58234bb16aadeb7154404af355eee48b6c092305731104fb86 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +Template Bobby First Template has failed to build 4/55 times over the last = +week. + +Report: + +bobby-template-version-1 failed 3 times: + +mtojek / workspace-1 / #1234 (http://test.com/@mtojek/workspace-1/builds/12= +34) +johndoe / my-workspace-3 / #5678 (http://test.com/@johndoe/my-workspace-3/b= +uilds/5678) +jack / workwork / #774 (http://test.com/@jack/workwork/builds/774) + +bobby-template-version-2 failed 1 time: + +ben / cool-workspace / #8888 (http://test.com/@ben/cool-workspace/builds/88= +88) + +We recommend reviewing these issues to ensure future builds are successful. + + +View workspaces: http://test.com/workspaces?filter=3Dtemplate%3Abobby-first= +-template + +--efa4000d6a58234bb16aadeb7154404af355eee48b6c092305731104fb86 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Workspace "bobby-workspace" deleted +

+
+

Hi Bobby,

+ +

Your workspace bobby-workspace was deleted.

+ +

The specified reason was “autodeleted due to dormancy (aut= +obuild)”.

+
+ + +
+ + + +--a2ac3693060ec5a6eec4291417263bc512450a8a12175f14357e39c5897d-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.golden.html new file mode 100644 index 0000000000000..05c691e8a15fc --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.golden.html @@ -0,0 +1,90 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Workspace "bobby-workspace" marked as dormant +Message-Id: 21006a6f-db94-410d-a12b-8b1d7e1c14b6@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:48 +0000 +Content-Type: multipart/alternative; boundary=10a16dabe06abad8dc2a402a4845e82da5077f4357086d29682759903ab4 +MIME-Version: 1.0 + +--10a16dabe06abad8dc2a402a4845e82da5077f4357086d29682759903ab4 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +Your workspace bobby-workspace has been marked as dormant (https://coder.co= +m/docs/templates/schedule#dormancy-threshold-enterprise) because of breache= +d the template's threshold for inactivity. +Dormant workspaces are automatically deleted (https://coder.com/docs/templa= +tes/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivit= +y. +To prevent deletion, use your workspace with the link below. + + +View workspace: http://test.com/@bobby/bobby-workspace + +--10a16dabe06abad8dc2a402a4845e82da5077f4357086d29682759903ab4 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Workspace "bobby-workspace" marked as dormant +

+
+

Hi Bobby,

+ +

Your workspace bobby-workspace has been marked as dormant because of breached the template’s t= +hreshold for inactivity.
+Dormant workspaces are automatically deleted after 24 hour= +s of inactivity.
+To prevent deletion, use your workspace with the link below.

+
+
+ =20 + + View workspace + + =20 +
+ +
+ + + +--10a16dabe06abad8dc2a402a4845e82da5077f4357086d29682759903ab4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.golden.html new file mode 100644 index 0000000000000..eff610da2db63 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.golden.html @@ -0,0 +1,86 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Workspace "bobby-workspace" manual build failed +Message-Id: b2076a0a-b9d9-4c46-950c-194a3838e68f@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:46 +0000 +Content-Type: multipart/alternative; boundary=ac32d74ecad98ce821f696bf87be1764d39d76dc61eee7ee421e2009b3b7 +MIME-Version: 1.0 + +--ac32d74ecad98ce821f696bf87be1764d39d76dc61eee7ee421e2009b3b7 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +A manual build of the workspace bobby-workspace using the template bobby-te= +mplate failed (version: bobby-template-version). + +The template's display name was William's Template. The workspace build was= + initiated by joe. + + +View build: http://test.com/@mrbobby/bobby-workspace/builds/3 + +--ac32d74ecad98ce821f696bf87be1764d39d76dc61eee7ee421e2009b3b7 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Workspace "bobby-workspace" manual build failed +

+
+

Hi Bobby,

+ +

A manual build of the workspace bobby-workspace using t= +he template bobby-template failed (version: bobby-= +template-version).

+ +

The template’s display name was William’s Template. The workspace build was initiated by joe.

+
+
+ =20 + + View build + + =20 +
+ +
+ + + +--ac32d74ecad98ce821f696bf87be1764d39d76dc61eee7ee421e2009b3b7-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.golden.html new file mode 100644 index 0000000000000..cfdda1ba8d9a7 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.golden.html @@ -0,0 +1,84 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Workspace "bobby-workspace" marked for deletion +Message-Id: 7ea43573-bbdf-4b51-88a5-87d3bd64c83b@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:47 +0000 +Content-Type: multipart/alternative; boundary=9862c4af60850822ade0609cbcbf878b331710c32323741c36b88e67dec1 +MIME-Version: 1.0 + +--9862c4af60850822ade0609cbcbf878b331710c32323741c36b88e67dec1 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +Your workspace bobby-workspace has been marked for deletion after 24 hours = +of dormancy (https://coder.com/docs/templates/schedule#dormancy-auto-deleti= +on-enterprise) because of template updated to new dormancy policy. +To prevent deletion, use your workspace with the link below. + + +View workspace: http://test.com/@bobby/bobby-workspace + +--9862c4af60850822ade0609cbcbf878b331710c32323741c36b88e67dec1 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Workspace "bobby-workspace" marked for deletion +

+
+

Hi Bobby,

+ +

Your workspace bobby-workspace has been marked for deletion after 24 hours of dormancy because o= +f template updated to new dormancy policy.
+To prevent deletion, use your workspace with the link below.

+
+
+ =20 + + View workspace + + =20 +
+ +
+ + + +--9862c4af60850822ade0609cbcbf878b331710c32323741c36b88e67dec1-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.golden.html new file mode 100644 index 0000000000000..541dd5745dbcc --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.golden.html @@ -0,0 +1,78 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Your account "bobby" has been activated +Message-Id: aa349d9b-7756-4acd-ab9c-177ac221d4d8@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:48 +0000 +Content-Type: multipart/alternative; boundary=70f570397cfce0e1db16cdb64c8d46faf5a81804cb11806e296171556fa6 +MIME-Version: 1.0 + +--70f570397cfce0e1db16cdb64c8d46faf5a81804cb11806e296171556fa6 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +Your account bobby has been activated by rob. + + +Open Coder: http://test.com + +--70f570397cfce0e1db16cdb64c8d46faf5a81804cb11806e296171556fa6 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Your account "bobby" has been activated +

+
+

Hi Bobby,

+ +

Your account bobby has been activated by rob.

+
+
+ =20 + + Open Coder + + =20 +
+ +
+ + + +--70f570397cfce0e1db16cdb64c8d46faf5a81804cb11806e296171556fa6-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.golden.html new file mode 100644 index 0000000000000..0193809bfeece --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.golden.html @@ -0,0 +1,70 @@ +From: system@coder.com +To: bobby@coder.com +Subject: Your account "bobby" has been suspended +Message-Id: 550fe308-20ff-4342-ae71-b298885d2f71@blush-whale-48 +Date: Fri, 11 Oct 2024 07:07:48 +0000 +Content-Type: multipart/alternative; boundary=060f5769384e657ec3b7f27e657d1bd0e290877808ba41be59389da3fe57 +MIME-Version: 1.0 + +--060f5769384e657ec3b7f27e657d1bd0e290877808ba41be59389da3fe57 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 + +Hi Bobby, + +Your account bobby has been suspended by rob. + + +--060f5769384e657ec3b7f27e657d1bd0e290877808ba41be59389da3fe57 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/html; charset=UTF-8 + + + + + + + Codestin Search App + + +
+
+ 3D"Cod= +
+

+ Your account "bobby" has been suspended +

+
+

Hi Bobby,

+ +

Your account bobby has been suspended by rob.

+
+
+ =20 +
+ +
+ + + +--060f5769384e657ec3b7f27e657d1bd0e290877808ba41be59389da3fe57-- diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.golden.json new file mode 100644 index 0000000000000..2b37a9c99b41f --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.golden.json @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "529c1604-edb2-4e95-a3c0-7c216dcc60de", + "payload": { + "_version": "1.1", + "notification_name": "Template Deleted", + "notification_template_id": "29a09665-2a4c-403f-9648-54301670e7be", + "user_id": "c7d31df2-cf63-4d99-b42c-a92bdb673cf8", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View templates", + "url": "http://test.com/templates" + } + ], + "labels": { + "display_name": "Bobby's Template", + "initiator": "rob", + "name": "bobby-template" + }, + "data": null + }, + "title": "Template \"bobby-template\" deleted", + "title_markdown": "Template \"bobby-template\" deleted", + "body": "Hi Bobby,\n\nThe template bobby-template was deleted by rob.\n\nThe template's display name was Bobby's Template.", + "body_markdown": "Hi Bobby,\n\nThe template **bobby-template** was deleted by **rob**.\n\nThe template's display name was **Bobby's Template**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.golden.json new file mode 100644 index 0000000000000..c66ae226faf53 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.golden.json @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "bdbbf8ed-56aa-4b7d-aa4a-acf310dd0ec8", + "payload": { + "_version": "1.1", + "notification_name": "User account activated", + "notification_template_id": "9f5af851-8408-4e73-a7a1-c6502ba46689", + "user_id": "54fe51a0-5945-446d-9025-a954f486462a", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View accounts", + "url": "http://test.com/deployment/users?filter=status%3Aactive" + } + ], + "labels": { + "account_activator_user_name": "rob", + "activated_account_name": "bobby", + "activated_account_user_name": "william tables" + }, + "data": null + }, + "title": "User account \"bobby\" activated", + "title_markdown": "User account \"bobby\" activated", + "body": "Hi Bobby,\n\nUser account bobby has been activated.\n\nThe newly activated account belongs to william tables and was activated by rob.", + "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **william tables** and was activated by **rob**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.golden.json new file mode 100644 index 0000000000000..3132d689ee503 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.golden.json @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "8a9a8b0e-4d58-4ccb-850d-01aee95ca1ff", + "payload": { + "_version": "1.1", + "notification_name": "User account created", + "notification_template_id": "4e19c0ac-94e1-4532-9515-d1801aa283b2", + "user_id": "f10e40f9-0230-4764-bd76-fb5d6dbeda78", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View accounts", + "url": "http://test.com/deployment/users?filter=status%3Aactive" + } + ], + "labels": { + "account_creator": "rob", + "created_account_name": "bobby", + "created_account_user_name": "William Tables" + }, + "data": null + }, + "title": "User account \"bobby\" created", + "title_markdown": "User account \"bobby\" created", + "body": "Hi Bobby,\n\nNew user account bobby has been created.\n\nThis new user account was created for William Tables by rob.", + "body_markdown": "Hi Bobby,\n\nNew user account **bobby** has been created.\n\nThis new user account was created for **William Tables** by **rob**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.golden.json new file mode 100644 index 0000000000000..b732cd6ec7ddb --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.golden.json @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "9a68b117-679e-4e41-b3ed-a351dede6756", + "payload": { + "_version": "1.1", + "notification_name": "User account deleted", + "notification_template_id": "f44d9314-ad03-4bc8-95d0-5cad491da6b6", + "user_id": "46344fbb-4c29-4094-aedc-81f189245b53", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View accounts", + "url": "http://test.com/deployment/users?filter=status%3Aactive" + } + ], + "labels": { + "account_deleter_user_name": "rob", + "deleted_account_name": "bobby", + "deleted_account_user_name": "william tables" + }, + "data": null + }, + "title": "User account \"bobby\" deleted", + "title_markdown": "User account \"bobby\" deleted", + "body": "Hi Bobby,\n\nUser account bobby has been deleted.\n\nThe deleted account belonged to william tables and was deleted by rob.", + "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been deleted.\n\nThe deleted account belonged to **william tables** and was deleted by **rob**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.golden.json new file mode 100644 index 0000000000000..dafce8d8ebe8d --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.golden.json @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "ba41f5c6-fc06-423a-9c37-4a8645baef39", + "payload": { + "_version": "1.1", + "notification_name": "User account suspended", + "notification_template_id": "b02ddd82-4733-4d02-a2d7-c36f3598997d", + "user_id": "b90405c6-b8cb-4040-888b-31364f736fcd", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View suspended accounts", + "url": "http://test.com/deployment/users?filter=status%3Asuspended" + } + ], + "labels": { + "account_suspender_user_name": "rob", + "suspended_account_name": "bobby", + "suspended_account_user_name": "william tables" + }, + "data": null + }, + "title": "User account \"bobby\" suspended", + "title_markdown": "User account \"bobby\" suspended", + "body": "Hi Bobby,\n\nUser account bobby has been suspended.\n\nThe newly suspended account belongs to william tables and was suspended by rob.", + "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been suspended.\n\nThe newly suspended account belongs to **william tables** and was suspended by **rob**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.golden.json new file mode 100644 index 0000000000000..341666ebf5562 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.golden.json @@ -0,0 +1,22 @@ +{ + "_version": "1.1", + "msg_id": "9c7572ee-235e-4776-963a-b89e46bcb905", + "payload": { + "_version": "1.1", + "notification_name": "One-Time Passcode", + "notification_template_id": "62f86a30-2330-4b61-a26d-311ff3b608cf", + "user_id": "82d75cc8-516f-4bdc-b2f9-71d5fbfae0b0", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [], + "labels": { + "one_time_passcode": "fad9020b-6562-4cdb-87f1-0486f1bea415" + }, + "data": null + }, + "title": "Your One-Time Passcode for Coder.", + "title_markdown": "Your One-Time Passcode for Coder.", + "body": "Hi Bobby,\n\nA request to reset the password for your Coder account has been made. Your one-time passcode is:\n\nfad9020b-6562-4cdb-87f1-0486f1bea415\n\nIf you did not request to reset your password, you can ignore this message.", + "body_markdown": "Hi Bobby,\n\nA request to reset the password for your Coder account has been made. Your one-time passcode is:\n\n**fad9020b-6562-4cdb-87f1-0486f1bea415**\n\nIf you did not request to reset your password, you can ignore this message." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.golden.json new file mode 100644 index 0000000000000..b8334730e52d9 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.golden.json @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "58f1bc95-7dfd-45fe-8a58-e8c940f47cbc", + "payload": { + "_version": "1.1", + "notification_name": "Workspace Updated Automatically", + "notification_template_id": "c34a0c09-0704-4cac-bd1c-0c0146811c2b", + "user_id": "d90e9b53-d3b1-4f2b-a4eb-efd61442cbb6", + "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_message": "template now includes catnip", + "template_version_name": "1.0" + }, + "data": null + }, + "title": "Workspace \"bobby-workspace\" updated automatically", + "title_markdown": "Workspace \"bobby-workspace\" updated automatically", + "body": "Hi Bobby,\n\nYour workspace bobby-workspace has been updated automatically to the latest template version (1.0).\n\nReason for update: template now includes catnip.", + "body_markdown": "Hi Bobby,\n\nYour workspace **bobby-workspace** has been updated automatically to the latest template version (1.0).\n\nReason for update: **template now includes catnip**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.golden.json new file mode 100644 index 0000000000000..4a623ebda2c0d --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.golden.json @@ -0,0 +1,66 @@ +{ + "_version": "1.1", + "msg_id": "527a83b3-c5ad-449d-9e51-f4b680a33655", + "payload": { + "_version": "1.1", + "notification_name": "Report: Workspace Builds Failed For Template", + "notification_template_id": "34a20db2-e9cc-4a93-b0e4-8569699d7a00", + "user_id": "7f78ad2c-8a9b-4f1b-82a1-50890b8c0f14", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View workspaces", + "url": "http://test.com/workspaces?filter=template%3Abobby-first-template" + } + ], + "labels": { + "template_display_name": "Bobby First Template", + "template_name": "bobby-first-template" + }, + "data": { + "failed_builds": 4, + "report_frequency": "week", + "template_versions": [ + { + "failed_builds": [ + { + "build_number": 1234, + "workspace_name": "workspace-1", + "workspace_owner_username": "mtojek" + }, + { + "build_number": 5678, + "workspace_name": "my-workspace-3", + "workspace_owner_username": "johndoe" + }, + { + "build_number": 774, + "workspace_name": "workwork", + "workspace_owner_username": "jack" + } + ], + "failed_count": 3, + "template_version_name": "bobby-template-version-1" + }, + { + "failed_builds": [ + { + "build_number": 8888, + "workspace_name": "cool-workspace", + "workspace_owner_username": "ben" + } + ], + "failed_count": 1, + "template_version_name": "bobby-template-version-2" + } + ], + "total_builds": 55 + } + }, + "title": "Workspace builds failed for template \"Bobby First Template\"", + "title_markdown": "Workspace builds failed for template \"Bobby First Template\"", + "body": "Hi Bobby,\n\nTemplate Bobby First Template has failed to build 4/55 times over the last week.\n\nReport:\n\nbobby-template-version-1 failed 3 times:\n\nmtojek / workspace-1 / #1234 (http://test.com/@mtojek/workspace-1/builds/1234)\njohndoe / my-workspace-3 / #5678 (http://test.com/@johndoe/my-workspace-3/builds/5678)\njack / workwork / #774 (http://test.com/@jack/workwork/builds/774)\n\nbobby-template-version-2 failed 1 time:\n\nben / cool-workspace / #8888 (http://test.com/@ben/cool-workspace/builds/8888)\n\nWe recommend reviewing these issues to ensure future builds are successful.", + "body_markdown": "Hi Bobby,\n\nTemplate **Bobby First Template** has failed to build 4/55 times over the last week.\n\n**Report:**\n\n**bobby-template-version-1** failed 3 times:\n\n* [mtojek / workspace-1 / #1234](http://test.com/@mtojek/workspace-1/builds/1234)\n* [johndoe / my-workspace-3 / #5678](http://test.com/@johndoe/my-workspace-3/builds/5678)\n* [jack / workwork / #774](http://test.com/@jack/workwork/builds/774)\n\n**bobby-template-version-2** failed 1 time:\n\n* [ben / cool-workspace / #8888](http://test.com/@ben/cool-workspace/builds/8888)\n\nWe recommend reviewing these issues to ensure future builds are successful." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.golden.json new file mode 100644 index 0000000000000..13e3e4658c1e2 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.golden.json @@ -0,0 +1,31 @@ +{ + "_version": "1.1", + "msg_id": "5bf8d6d0-64d4-4a2b-8861-7263e2d48f85", + "payload": { + "_version": "1.1", + "notification_name": "Workspace Marked as Dormant", + "notification_template_id": "0ea69165-ec14-4314-91f1-69566ac3c5a0", + "user_id": "f91d903f-2148-4172-80d0-3f829cfe99bd", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View workspace", + "url": "http://test.com/@bobby/bobby-workspace" + } + ], + "labels": { + "dormancyHours": "24", + "initiator": "autobuild", + "name": "bobby-workspace", + "reason": "breached the template's threshold for inactivity", + "timeTilDormant": "24 hours" + }, + "data": null + }, + "title": "Workspace \"bobby-workspace\" marked as dormant", + "title_markdown": "Workspace \"bobby-workspace\" marked as dormant", + "body": "Hi Bobby,\n\nYour workspace bobby-workspace has been marked as dormant (https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity.\nDormant workspaces are automatically deleted (https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity.\nTo prevent deletion, use your workspace with the link below.", + "body_markdown": "Hi Bobby,\n\nYour workspace **bobby-workspace** has been marked as [**dormant**](https://coder.com/docs/templates/schedule#dormancy-threshold-enterprise) because of breached the template's threshold for inactivity.\nDormant workspaces are [automatically deleted](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) after 24 hours of inactivity.\nTo prevent deletion, use your workspace with the link below." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.golden.json new file mode 100644 index 0000000000000..d679acfa52c3b --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.golden.json @@ -0,0 +1,30 @@ +{ + "_version": "1.1", + "msg_id": "b32dca04-5d8e-4ef8-ac85-e037d802fcdf", + "payload": { + "_version": "1.1", + "notification_name": "Workspace Marked for Deletion", + "notification_template_id": "51ce2fdf-c9ca-4be1-8d70-628674f9bc42", + "user_id": "254a02ca-d975-49fc-ba7f-30d887f71c5b", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View workspace", + "url": "http://test.com/@bobby/bobby-workspace" + } + ], + "labels": { + "dormancyHours": "24", + "name": "bobby-workspace", + "reason": "template updated to new dormancy policy", + "timeTilDormant": "24 hours" + }, + "data": null + }, + "title": "Workspace \"bobby-workspace\" marked for deletion", + "title_markdown": "Workspace \"bobby-workspace\" marked for deletion", + "body": "Hi Bobby,\n\nYour workspace bobby-workspace has been marked for deletion after 24 hours of dormancy (https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy.\nTo prevent deletion, use your workspace with the link below.", + "body_markdown": "Hi Bobby,\n\nYour workspace **bobby-workspace** has been marked for **deletion** after 24 hours of [dormancy](https://coder.com/docs/templates/schedule#dormancy-auto-deletion-enterprise) because of template updated to new dormancy policy.\nTo prevent deletion, use your workspace with the link below." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.golden.json new file mode 100644 index 0000000000000..b4178c8ccbff8 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.golden.json @@ -0,0 +1,28 @@ +{ + "_version": "1.1", + "msg_id": "a8c39bf1-0287-4504-b9a0-c10ad7cb4bec", + "payload": { + "_version": "1.1", + "notification_name": "Your account has been activated", + "notification_template_id": "1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4", + "user_id": "add943c4-3625-4539-aa42-7746d62dfc96", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "Open Coder", + "url": "http://test.com" + } + ], + "labels": { + "account_activator_user_name": "rob", + "activated_account_name": "bobby" + }, + "data": null + }, + "title": "Your account \"bobby\" has been activated", + "title_markdown": "Your account \"bobby\" has been activated", + "body": "Hi Bobby,\n\nYour account bobby has been activated by rob.", + "body_markdown": "Hi Bobby,\n\nYour account **bobby** has been activated by **rob**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.golden.json new file mode 100644 index 0000000000000..4d24c1e6c7f40 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.golden.json @@ -0,0 +1,23 @@ +{ + "_version": "1.1", + "msg_id": "12ee9ab1-a216-437c-a947-9126caffa515", + "payload": { + "_version": "1.1", + "notification_name": "Your account has been suspended", + "notification_template_id": "6a2f0609-9b69-4d36-a989-9f5925b6cbff", + "user_id": "91875bd4-1abb-468b-95fe-5861774a8d71", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [], + "labels": { + "account_suspender_user_name": "rob", + "suspended_account_name": "bobby" + }, + "data": null + }, + "title": "Your account \"bobby\" has been suspended", + "title_markdown": "Your account \"bobby\" has been suspended", + "body": "Hi Bobby,\n\nYour account bobby has been suspended by rob.", + "body_markdown": "Hi Bobby,\n\nYour account **bobby** has been suspended by **rob**." +} \ No newline at end of file From 8989a4412771cd92e57d6eac28954e0860f2bc90 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 08:06:33 +0000 Subject: [PATCH 25/44] chore(coderd/notifications): replace sleep with require.eventually in test --- coderd/notifications/notifications_test.go | 36 ++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index fdcec9c107d78..7ed9ae8bf0c58 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -1107,21 +1107,24 @@ func TestNotificationTemplates_Golden(t *testing.T) { require.NoError(t, err) // Wait for the message to be fetched - time.Sleep(notificationCfg.FetchInterval.Value()) + var msg *mock_smtp.Message + require.Eventually(t, func() bool { + msg = backend.LastMessage() + return msg != nil + }, testutil.WaitShort, testutil.IntervalFast) + require.NotNil(t, msg, "want a message to be sent") err = smtpManager.Stop(ctx) require.NoError(t, err) - msg := backend.LastMessage() - require.NotNil(t, msg, "want a message to be sent") - partialName := strings.Split(t.Name(), "/")[1] - goldenFile := filepath.Join("testdata", "rendered-templates", "smtp", partialName+".golden.html") - // TODO: add flag to update golden files - err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) - require.NoError(t, err, "want no error creating golden file directory") - err = os.WriteFile(goldenFile, []byte(msg.Contents), 0o600) - require.NoError(t, err, "want no error writing body golden file") + goldenFile := filepath.Join("testdata", "rendered-templates", "smtp", partialName+".html.golden") + if *updateGoldenFiles { + err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) + require.NoError(t, err, "want no error creating golden file directory") + err = os.WriteFile(goldenFile, []byte(msg.Contents), 0o600) + require.NoError(t, err, "want no error writing body golden file") + } }) t.Run("webhook", func(t *testing.T) { @@ -1158,12 +1161,13 @@ func TestNotificationTemplates_Golden(t *testing.T) { require.NoError(t, err) partialName := strings.Split(t.Name(), "/")[1] - goldenFile := filepath.Join("testdata", "rendered-templates", "webhook", partialName+".golden.json") - // TODO: add flag to update golden files - err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) - require.NoError(t, err, "want no error creating golden file directory") - err = os.WriteFile(goldenFile, prettyJSON.Bytes(), 0o600) - require.NoError(t, err, "want no error writing body golden file") + goldenFile := filepath.Join("testdata", "rendered-templates", "webhook", partialName+".json.golden") + if *updateGoldenFiles { + err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) + require.NoError(t, err, "want no error creating golden file directory") + err = os.WriteFile(goldenFile, prettyJSON.Bytes(), 0o600) + require.NoError(t, err, "want no error writing body golden file") + } w.WriteHeader(http.StatusOK) })) From ed91226b2d1fde08b2e0fe2b2855f2f5cba2ed7f Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 08:48:14 +0000 Subject: [PATCH 26/44] chore(coderd/notifications): rename and regenerate notifications files --- coderd/notifications/notifications_test.go | 53 +++++-------------- ...ml => TemplateTemplateDeleted.html.golden} | 12 ++--- ... TemplateUserAccountActivated.html.golden} | 12 ++--- ...=> TemplateUserAccountCreated.html.golden} | 12 ++--- ...=> TemplateUserAccountDeleted.html.golden} | 12 ++--- ... TemplateUserAccountSuspended.html.golden} | 12 ++--- ...eUserRequestedOneTimePasscode.html.golden} | 12 ++--- ... TemplateWorkspaceAutoUpdated.html.golden} | 12 ++--- ...plateWorkspaceAutobuildFailed.html.golden} | 12 ++--- ...teWorkspaceBuildsFailedReport.html.golden} | 12 ++--- ...l => TemplateWorkspaceDeleted.html.golden} | 12 ++--- ...l => TemplateWorkspaceDormant.html.golden} | 12 ++--- ...ateWorkspaceManualBuildFailed.html.golden} | 12 ++--- ...ateWorkspaceMarkedForDeletion.html.golden} | 12 ++--- ... TemplateYourAccountActivated.html.golden} | 12 ++--- ... TemplateYourAccountSuspended.html.golden} | 12 ++--- .../TemplateTemplateDeleted.golden.json | 29 ---------- .../TemplateUserAccountActivated.golden.json | 29 ---------- .../TemplateUserAccountCreated.golden.json | 29 ---------- ...=> TemplateUserAccountDeleted.json.golden} | 4 +- ... TemplateUserAccountSuspended.json.golden} | 4 +- ...eUserRequestedOneTimePasscode.json.golden} | 4 +- ... TemplateWorkspaceAutoUpdated.json.golden} | 4 +- ...teWorkspaceBuildsFailedReport.json.golden} | 4 +- .../TemplateWorkspaceDeleted.json.golden | 33 ++++++++++++ ...n => TemplateWorkspaceDormant.json.golden} | 4 +- ...lateWorkspaceManualBuildFailed.json.golden | 33 ++++++++++++ ...ateWorkspaceMarkedForDeletion.json.golden} | 4 +- .../TemplateYourAccountActivated.golden.json | 28 ---------- ... TemplateYourAccountSuspended.json.golden} | 4 +- 30 files changed, 184 insertions(+), 262 deletions(-) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateTemplateDeleted.golden.html => TemplateTemplateDeleted.html.golden} (85%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateUserAccountActivated.golden.html => TemplateUserAccountActivated.html.golden} (85%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateUserAccountCreated.golden.html => TemplateUserAccountCreated.html.golden} (85%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateUserAccountDeleted.golden.html => TemplateUserAccountDeleted.html.golden} (85%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateUserAccountSuspended.golden.html => TemplateUserAccountSuspended.html.golden} (85%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateUserRequestedOneTimePasscode.golden.html => TemplateUserRequestedOneTimePasscode.html.golden} (84%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateWorkspaceAutoUpdated.golden.html => TemplateWorkspaceAutoUpdated.html.golden} (85%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateWorkspaceAutobuildFailed.golden.html => TemplateWorkspaceAutobuildFailed.html.golden} (85%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateWorkspaceBuildsFailedReport.golden.html => TemplateWorkspaceBuildsFailedReport.html.golden} (88%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateWorkspaceDeleted.golden.html => TemplateWorkspaceDeleted.html.golden} (86%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateWorkspaceDormant.golden.html => TemplateWorkspaceDormant.html.golden} (87%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateWorkspaceManualBuildFailed.golden.html => TemplateWorkspaceManualBuildFailed.html.golden} (86%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateWorkspaceMarkedForDeletion.golden.html => TemplateWorkspaceMarkedForDeletion.html.golden} (86%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateYourAccountActivated.golden.html => TemplateYourAccountActivated.html.golden} (84%) rename coderd/notifications/testdata/rendered-templates/smtp/{TemplateYourAccountSuspended.golden.html => TemplateYourAccountSuspended.html.golden} (83%) delete mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.golden.json delete mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.golden.json delete mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.golden.json rename coderd/notifications/testdata/rendered-templates/webhook/{TemplateUserAccountDeleted.golden.json => TemplateUserAccountDeleted.json.golden} (90%) rename coderd/notifications/testdata/rendered-templates/webhook/{TemplateUserAccountSuspended.golden.json => TemplateUserAccountSuspended.json.golden} (90%) rename coderd/notifications/testdata/rendered-templates/webhook/{TemplateUserRequestedOneTimePasscode.golden.json => TemplateUserRequestedOneTimePasscode.json.golden} (90%) rename coderd/notifications/testdata/rendered-templates/webhook/{TemplateWorkspaceAutoUpdated.golden.json => TemplateWorkspaceAutoUpdated.json.golden} (91%) rename coderd/notifications/testdata/rendered-templates/webhook/{TemplateWorkspaceBuildsFailedReport.golden.json => TemplateWorkspaceBuildsFailedReport.json.golden} (96%) create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden rename coderd/notifications/testdata/rendered-templates/webhook/{TemplateWorkspaceDormant.golden.json => TemplateWorkspaceDormant.json.golden} (94%) create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden rename coderd/notifications/testdata/rendered-templates/webhook/{TemplateWorkspaceMarkedForDeletion.golden.json => TemplateWorkspaceMarkedForDeletion.json.golden} (92%) delete mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.golden.json rename coderd/notifications/testdata/rendered-templates/webhook/{TemplateYourAccountSuspended.golden.json => TemplateYourAccountSuspended.json.golden} (86%) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 7ed9ae8bf0c58..f393482dc26b8 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -703,6 +703,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { hello = "localhost" from = "system@coder.com" + hint = "run \"DB=ci make update-golden-files\" and commit the changes" ) tests := []struct { @@ -1124,7 +1125,12 @@ func TestNotificationTemplates_Golden(t *testing.T) { require.NoError(t, err, "want no error creating golden file directory") err = os.WriteFile(goldenFile, []byte(msg.Contents), 0o600) require.NoError(t, err, "want no error writing body golden file") + return } + + wantBody, err := os.ReadFile(goldenFile) + require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) + require.Equal(t, string(wantBody), msg.Contents, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint)) }) t.Run("webhook", func(t *testing.T) { @@ -1167,8 +1173,14 @@ func TestNotificationTemplates_Golden(t *testing.T) { require.NoError(t, err, "want no error creating golden file directory") err = os.WriteFile(goldenFile, prettyJSON.Bytes(), 0o600) require.NoError(t, err, "want no error writing body golden file") + w.WriteHeader(http.StatusOK) + return } + wantBody, err := os.ReadFile(goldenFile) + require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) + require.Equal(t, string(wantBody), prettyJSON, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint)) + w.WriteHeader(http.StatusOK) })) t.Cleanup(server.Close) @@ -1520,47 +1532,6 @@ func (f *fakeHandler) Dispatcher(payload types.MessagePayload, _, _ string) (dis }, nil } -type goldenFileHandler struct { - t *testing.T - goldenFileName string - updateGoldenFiles bool -} - -func (f *goldenFileHandler) Dispatcher(payload types.MessagePayload, title, body string) (dispatch.DeliveryFunc, error) { - return func(_ context.Context, _ uuid.UUID) (retryable bool, err error) { - // UserIDs change on every test run. We need to set it to a known value to compare golden files. - payload.UserID = "00000000-0000-0000-0000-000000000000" - - // The following is done by the stmp handler during dispatch. - // By doing it here we get an accurate golden representation of - // what would have been sent. We don't need to maintain parity - // with how the SMTP handler does it. We just need an accurate - // representation of the payload, and the rendered body and title. - payload.Labels["_body"] = body - payload.Labels["_title"] = title - - payloadJSON, err := json.MarshalIndent(payload, "", " ") - require.NoError(f.t, err, "want no error marshaling payload to JSON") - - if *updateGoldenFiles { - err = os.MkdirAll(filepath.Dir(f.goldenFileName), 0o755) - require.NoError(f.t, err, "want no error creating golden file directory") - err = os.WriteFile(f.goldenFileName, payloadJSON, 0o600) - require.NoError(f.t, err, "want no error writing body golden file") - return false, nil - } - - const hint = "run \"DB=ci make update-golden-files\" and commit the changes" - - wantBody, err := os.ReadFile(f.goldenFileName) - require.NoError(f.t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) - - require.Equal(f.t, string(wantBody), body, fmt.Sprintf("rendered template body does not match golden file. If this is expected, %s", hint)) - - return false, nil - }, nil -} - // noopStoreSyncer pretends to perform store syncs, but does not; leading to messages being stuck in "leased" state. type noopStoreSyncer struct { *acquireSignalingInterceptor diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden similarity index 85% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden index ab5fd2bd646c9..39785f26a2679 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Template "bobby-template" deleted -Message-Id: f7c231e3-3c60-40f9-87e4-e2187c33f61c@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:47 +0000 -Content-Type: multipart/alternative; boundary=c2b474e4ddaacbd4a99ed66399f8163284628d966bbbe1d7e78b3dc7fd9f +Message-Id: 594e3030-3739-4fbe-9b87-d0a938643421@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:19 +0000 +Content-Type: multipart/alternative; boundary=447921ad2714ac4f86104675f6509e2680c989166680aa4f7cae88d6750f MIME-Version: 1.0 ---c2b474e4ddaacbd4a99ed66399f8163284628d966bbbe1d7e78b3dc7fd9f +--447921ad2714ac4f86104675f6509e2680c989166680aa4f7cae88d6750f Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ View templates: http://test.com/templates ---c2b474e4ddaacbd4a99ed66399f8163284628d966bbbe1d7e78b3dc7fd9f +--447921ad2714ac4f86104675f6509e2680c989166680aa4f7cae88d6750f Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ ---c2b474e4ddaacbd4a99ed66399f8163284628d966bbbe1d7e78b3dc7fd9f-- +--447921ad2714ac4f86104675f6509e2680c989166680aa4f7cae88d6750f-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden similarity index 85% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden index 8da1d976aba52..c3981364d61e6 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" activated -Message-Id: f53579e9-e0f6-4e5f-8b5f-ffb143ffbfc2@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:47 +0000 -Content-Type: multipart/alternative; boundary=bdd4f63bddac33f9c64dc637e930cb8b7b7a78aadfa2e26c608ecbcab9d8 +Message-Id: 6c9a538c-f8b3-4f9c-8547-bb52d757b184@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:19 +0000 +Content-Type: multipart/alternative; boundary=d44e54c0e6b873b490ad047485e07977c08f31eea714f7ba723d6a18dcb6 MIME-Version: 1.0 ---bdd4f63bddac33f9c64dc637e930cb8b7b7a78aadfa2e26c608ecbcab9d8 +--d44e54c0e6b873b490ad047485e07977c08f31eea714f7ba723d6a18dcb6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---bdd4f63bddac33f9c64dc637e930cb8b7b7a78aadfa2e26c608ecbcab9d8 +--d44e54c0e6b873b490ad047485e07977c08f31eea714f7ba723d6a18dcb6 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -81,4 +81,4 @@ ---bdd4f63bddac33f9c64dc637e930cb8b7b7a78aadfa2e26c608ecbcab9d8-- +--d44e54c0e6b873b490ad047485e07977c08f31eea714f7ba723d6a18dcb6-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden similarity index 85% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden index 1a7e33cc1a67d..8a160970b25f4 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" created -Message-Id: de6644cd-9024-4022-bcd2-26e2e16ad7a9@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:47 +0000 -Content-Type: multipart/alternative; boundary=554f2d9c541e7f980805085bf6318568f21a41b0b102c0538e52c1faf36f +Message-Id: 9a5175ad-aaf7-4c63-b9c9-3fbf32a9521d@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:21 +0000 +Content-Type: multipart/alternative; boundary=5a39f983512f0a37c4267f0a1947a75384e3e007827db26aab1207d1d51d MIME-Version: 1.0 ---554f2d9c541e7f980805085bf6318568f21a41b0b102c0538e52c1faf36f +--5a39f983512f0a37c4267f0a1947a75384e3e007827db26aab1207d1d51d Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---554f2d9c541e7f980805085bf6318568f21a41b0b102c0538e52c1faf36f +--5a39f983512f0a37c4267f0a1947a75384e3e007827db26aab1207d1d51d Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ ---554f2d9c541e7f980805085bf6318568f21a41b0b102c0538e52c1faf36f-- +--5a39f983512f0a37c4267f0a1947a75384e3e007827db26aab1207d1d51d-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden similarity index 85% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden index 3a452e06f1282..f0487c6f3c1c4 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" deleted -Message-Id: 4c0b275e-1407-44de-a19c-dace68e6b569@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:48 +0000 -Content-Type: multipart/alternative; boundary=0a4f71d4690a1db88c14d9c076d11c45d7ad9f9a3296c118dc38acf001be +Message-Id: d00c1134-3931-435c-b629-28614b1f06c6@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:20 +0000 +Content-Type: multipart/alternative; boundary=f058ea3e397629381c9a67aa79759cb51fa9834e0b92219e4e4c04f2a42f MIME-Version: 1.0 ---0a4f71d4690a1db88c14d9c076d11c45d7ad9f9a3296c118dc38acf001be +--f058ea3e397629381c9a67aa79759cb51fa9834e0b92219e4e4c04f2a42f Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---0a4f71d4690a1db88c14d9c076d11c45d7ad9f9a3296c118dc38acf001be +--f058ea3e397629381c9a67aa79759cb51fa9834e0b92219e4e4c04f2a42f Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ ---0a4f71d4690a1db88c14d9c076d11c45d7ad9f9a3296c118dc38acf001be-- +--f058ea3e397629381c9a67aa79759cb51fa9834e0b92219e4e4c04f2a42f-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden similarity index 85% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden index 02c7390e80b20..967ea0487fc26 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" suspended -Message-Id: a8116eb1-a491-4ad5-8046-3439a8c7c2bb@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:48 +0000 -Content-Type: multipart/alternative; boundary=f966987bcfd6e14cfb8c13b387636b8bf5598e59aebd7645be43727ff3d3 +Message-Id: ab5f31a2-db2a-4e79-ac9d-d0f8a00724ad@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:21 +0000 +Content-Type: multipart/alternative; boundary=819d44b7bb641ccf7500ad9f4b8ec0f5a30bb8e366c06d5ce48ad3bda838 MIME-Version: 1.0 ---f966987bcfd6e14cfb8c13b387636b8bf5598e59aebd7645be43727ff3d3 +--819d44b7bb641ccf7500ad9f4b8ec0f5a30bb8e366c06d5ce48ad3bda838 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ View suspended accounts: http://test.com/deployment/users?filter=3Dstatus%3= Asuspended ---f966987bcfd6e14cfb8c13b387636b8bf5598e59aebd7645be43727ff3d3 +--819d44b7bb641ccf7500ad9f4b8ec0f5a30bb8e366c06d5ce48ad3bda838 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -82,4 +82,4 @@ ---f966987bcfd6e14cfb8c13b387636b8bf5598e59aebd7645be43727ff3d3-- +--819d44b7bb641ccf7500ad9f4b8ec0f5a30bb8e366c06d5ce48ad3bda838-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden similarity index 84% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden index be3be35085c1a..ee764df3eb1e1 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Your One-Time Passcode for Coder. -Message-Id: 88c8e582-31e6-4340-91db-625ee94cff41@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:47 +0000 -Content-Type: multipart/alternative; boundary=8d6dd286d3988e88511d6c79b25669b6652d49c6a6cfe3e3ac22ed7c498e +Message-Id: d368bc59-2aa5-477d-adc3-dfb5c905ef2e@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:19 +0000 +Content-Type: multipart/alternative; boundary=7ba286314219f64e5482c0c4f30a001bd4bbbf66c0b8c9ea110715bf5944 MIME-Version: 1.0 ---8d6dd286d3988e88511d6c79b25669b6652d49c6a6cfe3e3ac22ed7c498e +--7ba286314219f64e5482c0c4f30a001bd4bbbf66c0b8c9ea110715bf5944 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ If you did not request to reset your password, you can ignore this message. ---8d6dd286d3988e88511d6c79b25669b6652d49c6a6cfe3e3ac22ed7c498e +--7ba286314219f64e5482c0c4f30a001bd4bbbf66c0b8c9ea110715bf5944 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -77,4 +77,4 @@ ---8d6dd286d3988e88511d6c79b25669b6652d49c6a6cfe3e3ac22ed7c498e-- +--7ba286314219f64e5482c0c4f30a001bd4bbbf66c0b8c9ea110715bf5944-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden similarity index 85% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden index 2dc40797c2c83..2378296b5d854 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" updated automatically -Message-Id: 020bbf88-d7c2-4288-a793-77c71ad280ab@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:46 +0000 -Content-Type: multipart/alternative; boundary=a1bf50e5d03b4b474dcc7ff5ca29c57d75c87b5a5818af1ea4c70c74b929 +Message-Id: 9898c8e5-4041-4367-b40f-3b7856d76a23@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:20 +0000 +Content-Type: multipart/alternative; boundary=1ac2f0e4f21ec1ee3770de15791fc5e038e19727bb8184fde045b29fa385 MIME-Version: 1.0 ---a1bf50e5d03b4b474dcc7ff5ca29c57d75c87b5a5818af1ea4c70c74b929 +--1ac2f0e4f21ec1ee3770de15791fc5e038e19727bb8184fde045b29fa385 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ View workspace: http://test.com/@bobby/bobby-workspace ---a1bf50e5d03b4b474dcc7ff5ca29c57d75c87b5a5818af1ea4c70c74b929 +--1ac2f0e4f21ec1ee3770de15791fc5e038e19727bb8184fde045b29fa385 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ ---a1bf50e5d03b4b474dcc7ff5ca29c57d75c87b5a5818af1ea4c70c74b929-- +--1ac2f0e4f21ec1ee3770de15791fc5e038e19727bb8184fde045b29fa385-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden similarity index 85% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden index 5720d51170674..c4f5ff8645739 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" autobuild failed -Message-Id: 85797188-c342-42d4-baf8-82fa28ae0e5e@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:46 +0000 -Content-Type: multipart/alternative; boundary=22e99bbaa4b5e4842cfbfa98ce86e72701d3f527d851608b4264914714de +Message-Id: 6f923006-7d0d-4754-9d37-175df97de68a@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:20 +0000 +Content-Type: multipart/alternative; boundary=e2d2f921b2a16b9438a715de73cb6942bc52777cf2fe2e2335c24e35fb7d MIME-Version: 1.0 ---22e99bbaa4b5e4842cfbfa98ce86e72701d3f527d851608b4264914714de +--e2d2f921b2a16b9438a715de73cb6942bc52777cf2fe2e2335c24e35fb7d Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ View workspace: http://test.com/@bobby/bobby-workspace ---22e99bbaa4b5e4842cfbfa98ce86e72701d3f527d851608b4264914714de +--e2d2f921b2a16b9438a715de73cb6942bc52777cf2fe2e2335c24e35fb7d Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -79,4 +79,4 @@ ---22e99bbaa4b5e4842cfbfa98ce86e72701d3f527d851608b4264914714de-- +--e2d2f921b2a16b9438a715de73cb6942bc52777cf2fe2e2335c24e35fb7d-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden similarity index 88% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden index 62ae6b7624e15..2826179aa1bd7 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace builds failed for template "Bobby First Template" -Message-Id: 016fdea9-c110-4400-b4ee-01226ba4cca6@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:49 +0000 -Content-Type: multipart/alternative; boundary=efa4000d6a58234bb16aadeb7154404af355eee48b6c092305731104fb86 +Message-Id: e0da8dbd-8c83-4316-80a4-d5c38588d078@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:20 +0000 +Content-Type: multipart/alternative; boundary=be4e7b4085c012c76c863f28373423efe1f6867f3e3a32fe861b745a26c1 MIME-Version: 1.0 ---efa4000d6a58234bb16aadeb7154404af355eee48b6c092305731104fb86 +--be4e7b4085c012c76c863f28373423efe1f6867f3e3a32fe861b745a26c1 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -36,7 +36,7 @@ View workspaces: http://test.com/workspaces?filter=3Dtemplate%3Abobby-first= -template ---efa4000d6a58234bb16aadeb7154404af355eee48b6c092305731104fb86 +--be4e7b4085c012c76c863f28373423efe1f6867f3e3a32fe861b745a26c1 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -123,4 +123,4 @@ ---efa4000d6a58234bb16aadeb7154404af355eee48b6c092305731104fb86-- +--be4e7b4085c012c76c863f28373423efe1f6867f3e3a32fe861b745a26c1-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden similarity index 86% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden index 4c968b9a81f09..992a76a08fbf5 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" deleted -Message-Id: 3755291a-a7af-4d98-849d-31cc268420ad@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:48 +0000 -Content-Type: multipart/alternative; boundary=a2ac3693060ec5a6eec4291417263bc512450a8a12175f14357e39c5897d +Message-Id: 4a2693d0-217d-4b5f-93dd-ddd01f468754@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:20 +0000 +Content-Type: multipart/alternative; boundary=433a452845ca4849cfd341dacc13786c1370a43411418f886679b0f31c67 MIME-Version: 1.0 ---a2ac3693060ec5a6eec4291417263bc512450a8a12175f14357e39c5897d +--433a452845ca4849cfd341dacc13786c1370a43411418f886679b0f31c67 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ View templates: http://test.com/templates ---a2ac3693060ec5a6eec4291417263bc512450a8a12175f14357e39c5897d +--433a452845ca4849cfd341dacc13786c1370a43411418f886679b0f31c67 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -87,4 +87,4 @@ ---a2ac3693060ec5a6eec4291417263bc512450a8a12175f14357e39c5897d-- +--433a452845ca4849cfd341dacc13786c1370a43411418f886679b0f31c67-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden similarity index 87% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden index 05c691e8a15fc..484f232b1063a 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" marked as dormant -Message-Id: 21006a6f-db94-410d-a12b-8b1d7e1c14b6@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:48 +0000 -Content-Type: multipart/alternative; boundary=10a16dabe06abad8dc2a402a4845e82da5077f4357086d29682759903ab4 +Message-Id: 7eac38f6-49c5-4bfe-9aef-ecb97ba2301f@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:20 +0000 +Content-Type: multipart/alternative; boundary=a10a7cffac232483ab8b79adbccbf93e2b633a8a800770fa7c887ad07581 MIME-Version: 1.0 ---10a16dabe06abad8dc2a402a4845e82da5077f4357086d29682759903ab4 +--a10a7cffac232483ab8b79adbccbf93e2b633a8a800770fa7c887ad07581 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -23,7 +23,7 @@ View workspace: http://test.com/@bobby/bobby-workspace ---10a16dabe06abad8dc2a402a4845e82da5077f4357086d29682759903ab4 +--a10a7cffac232483ab8b79adbccbf93e2b633a8a800770fa7c887ad07581 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -87,4 +87,4 @@ ---10a16dabe06abad8dc2a402a4845e82da5077f4357086d29682759903ab4-- +--a10a7cffac232483ab8b79adbccbf93e2b633a8a800770fa7c887ad07581-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden similarity index 86% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden index eff610da2db63..a073f7abffadb 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" manual build failed -Message-Id: b2076a0a-b9d9-4c46-950c-194a3838e68f@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:46 +0000 -Content-Type: multipart/alternative; boundary=ac32d74ecad98ce821f696bf87be1764d39d76dc61eee7ee421e2009b3b7 +Message-Id: 8f4288e7-21d1-4ffc-aee8-03477b7f7528@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:20 +0000 +Content-Type: multipart/alternative; boundary=cd3836d096e1aa52ee20ee886c6451a5818cb89fedeb95f6c5ecaae05c1b MIME-Version: 1.0 ---ac32d74ecad98ce821f696bf87be1764d39d76dc61eee7ee421e2009b3b7 +--cd3836d096e1aa52ee20ee886c6451a5818cb89fedeb95f6c5ecaae05c1b Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ View build: http://test.com/@mrbobby/bobby-workspace/builds/3 ---ac32d74ecad98ce821f696bf87be1764d39d76dc61eee7ee421e2009b3b7 +--cd3836d096e1aa52ee20ee886c6451a5818cb89fedeb95f6c5ecaae05c1b Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -83,4 +83,4 @@ ---ac32d74ecad98ce821f696bf87be1764d39d76dc61eee7ee421e2009b3b7-- +--cd3836d096e1aa52ee20ee886c6451a5818cb89fedeb95f6c5ecaae05c1b-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden similarity index 86% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden index cfdda1ba8d9a7..dd0459d943fa3 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" marked for deletion -Message-Id: 7ea43573-bbdf-4b51-88a5-87d3bd64c83b@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:47 +0000 -Content-Type: multipart/alternative; boundary=9862c4af60850822ade0609cbcbf878b331710c32323741c36b88e67dec1 +Message-Id: 7b69076f-5ff7-464e-b900-e9cf196b833b@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:19 +0000 +Content-Type: multipart/alternative; boundary=4a5d477affccf7f0e3204afecf0fd5dff7967619853c65b8d7361f84d4e9 MIME-Version: 1.0 ---9862c4af60850822ade0609cbcbf878b331710c32323741c36b88e67dec1 +--4a5d477affccf7f0e3204afecf0fd5dff7967619853c65b8d7361f84d4e9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ View workspace: http://test.com/@bobby/bobby-workspace ---9862c4af60850822ade0609cbcbf878b331710c32323741c36b88e67dec1 +--4a5d477affccf7f0e3204afecf0fd5dff7967619853c65b8d7361f84d4e9 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -81,4 +81,4 @@ ---9862c4af60850822ade0609cbcbf878b331710c32323741c36b88e67dec1-- +--4a5d477affccf7f0e3204afecf0fd5dff7967619853c65b8d7361f84d4e9-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden similarity index 84% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden index 541dd5745dbcc..a4e2cd73031ce 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Your account "bobby" has been activated -Message-Id: aa349d9b-7756-4acd-ab9c-177ac221d4d8@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:48 +0000 -Content-Type: multipart/alternative; boundary=70f570397cfce0e1db16cdb64c8d46faf5a81804cb11806e296171556fa6 +Message-Id: 40aca67b-1800-4a31-bbd2-02c4795bcd69@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:20 +0000 +Content-Type: multipart/alternative; boundary=fd26e44cae82afa85bf853900feb4d7d60f926d8824d0ccee20ce5bd1fac MIME-Version: 1.0 ---70f570397cfce0e1db16cdb64c8d46faf5a81804cb11806e296171556fa6 +--fd26e44cae82afa85bf853900feb4d7d60f926d8824d0ccee20ce5bd1fac Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -17,7 +17,7 @@ Open Coder: http://test.com ---70f570397cfce0e1db16cdb64c8d46faf5a81804cb11806e296171556fa6 +--fd26e44cae82afa85bf853900feb4d7d60f926d8824d0ccee20ce5bd1fac Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -75,4 +75,4 @@ ---70f570397cfce0e1db16cdb64c8d46faf5a81804cb11806e296171556fa6-- +--fd26e44cae82afa85bf853900feb4d7d60f926d8824d0ccee20ce5bd1fac-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.golden.html b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden similarity index 83% rename from coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.golden.html rename to coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden index 0193809bfeece..73469cb31ff50 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.golden.html +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Your account "bobby" has been suspended -Message-Id: 550fe308-20ff-4342-ae71-b298885d2f71@blush-whale-48 -Date: Fri, 11 Oct 2024 07:07:48 +0000 -Content-Type: multipart/alternative; boundary=060f5769384e657ec3b7f27e657d1bd0e290877808ba41be59389da3fe57 +Message-Id: 343918fb-d0a5-4f56-bd78-c3b6b69bdc35@blush-whale-48 +Date: Fri, 11 Oct 2024 08:47:21 +0000 +Content-Type: multipart/alternative; boundary=d9cb9c933e63b78261d6dc46623e61d8586e8f282898d3cf2d6a890ea428 MIME-Version: 1.0 ---060f5769384e657ec3b7f27e657d1bd0e290877808ba41be59389da3fe57 +--d9cb9c933e63b78261d6dc46623e61d8586e8f282898d3cf2d6a890ea428 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -15,7 +15,7 @@ Your account bobby has been suspended by rob. ---060f5769384e657ec3b7f27e657d1bd0e290877808ba41be59389da3fe57 +--d9cb9c933e63b78261d6dc46623e61d8586e8f282898d3cf2d6a890ea428 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -67,4 +67,4 @@ ---060f5769384e657ec3b7f27e657d1bd0e290877808ba41be59389da3fe57-- +--d9cb9c933e63b78261d6dc46623e61d8586e8f282898d3cf2d6a890ea428-- diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.golden.json deleted file mode 100644 index 2b37a9c99b41f..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.golden.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "_version": "1.1", - "msg_id": "529c1604-edb2-4e95-a3c0-7c216dcc60de", - "payload": { - "_version": "1.1", - "notification_name": "Template Deleted", - "notification_template_id": "29a09665-2a4c-403f-9648-54301670e7be", - "user_id": "c7d31df2-cf63-4d99-b42c-a92bdb673cf8", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View templates", - "url": "http://test.com/templates" - } - ], - "labels": { - "display_name": "Bobby's Template", - "initiator": "rob", - "name": "bobby-template" - }, - "data": null - }, - "title": "Template \"bobby-template\" deleted", - "title_markdown": "Template \"bobby-template\" deleted", - "body": "Hi Bobby,\n\nThe template bobby-template was deleted by rob.\n\nThe template's display name was Bobby's Template.", - "body_markdown": "Hi Bobby,\n\nThe template **bobby-template** was deleted by **rob**.\n\nThe template's display name was **Bobby's Template**." -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.golden.json deleted file mode 100644 index c66ae226faf53..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.golden.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "_version": "1.1", - "msg_id": "bdbbf8ed-56aa-4b7d-aa4a-acf310dd0ec8", - "payload": { - "_version": "1.1", - "notification_name": "User account activated", - "notification_template_id": "9f5af851-8408-4e73-a7a1-c6502ba46689", - "user_id": "54fe51a0-5945-446d-9025-a954f486462a", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View accounts", - "url": "http://test.com/deployment/users?filter=status%3Aactive" - } - ], - "labels": { - "account_activator_user_name": "rob", - "activated_account_name": "bobby", - "activated_account_user_name": "william tables" - }, - "data": null - }, - "title": "User account \"bobby\" activated", - "title_markdown": "User account \"bobby\" activated", - "body": "Hi Bobby,\n\nUser account bobby has been activated.\n\nThe newly activated account belongs to william tables and was activated by rob.", - "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **william tables** and was activated by **rob**." -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.golden.json deleted file mode 100644 index 3132d689ee503..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.golden.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "_version": "1.1", - "msg_id": "8a9a8b0e-4d58-4ccb-850d-01aee95ca1ff", - "payload": { - "_version": "1.1", - "notification_name": "User account created", - "notification_template_id": "4e19c0ac-94e1-4532-9515-d1801aa283b2", - "user_id": "f10e40f9-0230-4764-bd76-fb5d6dbeda78", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "View accounts", - "url": "http://test.com/deployment/users?filter=status%3Aactive" - } - ], - "labels": { - "account_creator": "rob", - "created_account_name": "bobby", - "created_account_user_name": "William Tables" - }, - "data": null - }, - "title": "User account \"bobby\" created", - "title_markdown": "User account \"bobby\" created", - "body": "Hi Bobby,\n\nNew user account bobby has been created.\n\nThis new user account was created for William Tables by rob.", - "body_markdown": "Hi Bobby,\n\nNew user account **bobby** has been created.\n\nThis new user account was created for **William Tables** by **rob**." -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden similarity index 90% rename from coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.golden.json rename to coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden index b732cd6ec7ddb..0dd6ef8c73284 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.golden.json +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "9a68b117-679e-4e41-b3ed-a351dede6756", + "msg_id": "189afc53-45a9-4ad4-9fc9-a356371213d8", "payload": { "_version": "1.1", "notification_name": "User account deleted", "notification_template_id": "f44d9314-ad03-4bc8-95d0-5cad491da6b6", - "user_id": "46344fbb-4c29-4094-aedc-81f189245b53", + "user_id": "624591bd-4b2c-4043-8de0-f5117def9cac", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden similarity index 90% rename from coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.golden.json rename to coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden index dafce8d8ebe8d..044700ae8b708 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.golden.json +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "ba41f5c6-fc06-423a-9c37-4a8645baef39", + "msg_id": "82610ed1-3183-458f-8511-bb2783949df6", "payload": { "_version": "1.1", "notification_name": "User account suspended", "notification_template_id": "b02ddd82-4733-4d02-a2d7-c36f3598997d", - "user_id": "b90405c6-b8cb-4040-888b-31364f736fcd", + "user_id": "f6f64453-a003-49ea-9798-b95f806a05ef", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden similarity index 90% rename from coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.golden.json rename to coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden index 341666ebf5562..a12b15294de1a 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.golden.json +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "9c7572ee-235e-4776-963a-b89e46bcb905", + "msg_id": "e01e2d20-a2e4-46d4-baf3-f6e415f86a1c", "payload": { "_version": "1.1", "notification_name": "One-Time Passcode", "notification_template_id": "62f86a30-2330-4b61-a26d-311ff3b608cf", - "user_id": "82d75cc8-516f-4bdc-b2f9-71d5fbfae0b0", + "user_id": "dcd3ed36-b669-42b0-843c-d37fbe5aecd8", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden similarity index 91% rename from coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.golden.json rename to coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden index b8334730e52d9..de7af7dcee5f5 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.golden.json +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "58f1bc95-7dfd-45fe-8a58-e8c940f47cbc", + "msg_id": "c4d7beb1-af71-4d06-b857-f33848c6c7a3", "payload": { "_version": "1.1", "notification_name": "Workspace Updated Automatically", "notification_template_id": "c34a0c09-0704-4cac-bd1c-0c0146811c2b", - "user_id": "d90e9b53-d3b1-4f2b-a4eb-efd61442cbb6", + "user_id": "5d049111-4dde-44f5-bcaa-df91ffa623e2", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden similarity index 96% rename from coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.golden.json rename to coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden index 4a623ebda2c0d..1607568637adf 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.golden.json +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "527a83b3-c5ad-449d-9e51-f4b680a33655", + "msg_id": "3bead610-6bb2-4e5a-a1e9-b1d7710be8b8", "payload": { "_version": "1.1", "notification_name": "Report: Workspace Builds Failed For Template", "notification_template_id": "34a20db2-e9cc-4a93-b0e4-8569699d7a00", - "user_id": "7f78ad2c-8a9b-4f1b-82a1-50890b8c0f14", + "user_id": "bffed10b-d7bb-4588-a536-da8001ca31a0", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden new file mode 100644 index 0000000000000..62481cfd9f427 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden @@ -0,0 +1,33 @@ +{ + "_version": "1.1", + "msg_id": "61237bb8-5d56-4c16-b9a8-c56d405cb852", + "payload": { + "_version": "1.1", + "notification_name": "Workspace Deleted", + "notification_template_id": "f517da0b-cdc9-410f-ab89-a86107c420ed", + "user_id": "ff5ba700-51c0-491d-bcda-cd76791dd451", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View workspaces", + "url": "http://test.com/workspaces" + }, + { + "label": "View templates", + "url": "http://test.com/templates" + } + ], + "labels": { + "initiator": "autobuild", + "name": "bobby-workspace", + "reason": "autodeleted due to dormancy" + }, + "data": null + }, + "title": "Workspace \"bobby-workspace\" deleted", + "title_markdown": "Workspace \"bobby-workspace\" deleted", + "body": "Hi Bobby,\n\nYour workspace bobby-workspace was deleted.\n\nThe specified reason was \"autodeleted due to dormancy (autobuild)\".", + "body_markdown": "Hi Bobby,\n\nYour workspace **bobby-workspace** was deleted.\n\nThe specified reason was \"**autodeleted due to dormancy (autobuild)**\"." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden similarity index 94% rename from coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.golden.json rename to coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden index 13e3e4658c1e2..101be46806a97 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.golden.json +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "5bf8d6d0-64d4-4a2b-8861-7263e2d48f85", + "msg_id": "32482851-cf1b-4613-b0d2-a999f54f4f10", "payload": { "_version": "1.1", "notification_name": "Workspace Marked as Dormant", "notification_template_id": "0ea69165-ec14-4314-91f1-69566ac3c5a0", - "user_id": "f91d903f-2148-4172-80d0-3f829cfe99bd", + "user_id": "23ad77bf-b02b-42a6-9b4a-bd2637300cbd", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden new file mode 100644 index 0000000000000..15ed6de77c349 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden @@ -0,0 +1,33 @@ +{ + "_version": "1.1", + "msg_id": "af88d7f4-cb57-4baf-afc3-01e41a57164a", + "payload": { + "_version": "1.1", + "notification_name": "Workspace Manual Build Failed", + "notification_template_id": "2faeee0f-26cb-4e96-821c-85ccb9f71513", + "user_id": "9766302b-44d8-4e38-84fc-2817969c6790", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View build", + "url": "http://test.com/@mrbobby/bobby-workspace/builds/3" + } + ], + "labels": { + "initiator": "joe", + "name": "bobby-workspace", + "template_display_name": "William's Template", + "template_name": "bobby-template", + "template_version_name": "bobby-template-version", + "workspace_build_number": "3", + "workspace_owner_username": "mrbobby" + }, + "data": null + }, + "title": "Workspace \"bobby-workspace\" manual build failed", + "title_markdown": "Workspace \"bobby-workspace\" manual build failed", + "body": "Hi Bobby,\n\nA manual build of the workspace bobby-workspace using the template bobby-template failed (version: bobby-template-version).\n\nThe template's display name was William's Template. The workspace build was initiated by joe.", + "body_markdown": "Hi Bobby,\n\nA manual build of the workspace **bobby-workspace** using the template **bobby-template** failed (version: **bobby-template-version**).\n\nThe template's display name was **William's Template**. The workspace build was initiated by **joe**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden similarity index 92% rename from coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.golden.json rename to coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden index d679acfa52c3b..874eb3a240873 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.golden.json +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "b32dca04-5d8e-4ef8-ac85-e037d802fcdf", + "msg_id": "c354e9b3-03f9-4f14-9dbf-d327f96bf465", "payload": { "_version": "1.1", "notification_name": "Workspace Marked for Deletion", "notification_template_id": "51ce2fdf-c9ca-4be1-8d70-628674f9bc42", - "user_id": "254a02ca-d975-49fc-ba7f-30d887f71c5b", + "user_id": "6f8e5805-dbba-4aa5-ba80-6cc0b393a790", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.golden.json deleted file mode 100644 index b4178c8ccbff8..0000000000000 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.golden.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "_version": "1.1", - "msg_id": "a8c39bf1-0287-4504-b9a0-c10ad7cb4bec", - "payload": { - "_version": "1.1", - "notification_name": "Your account has been activated", - "notification_template_id": "1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4", - "user_id": "add943c4-3625-4539-aa42-7746d62dfc96", - "user_email": "bobby@coder.com", - "user_name": "Bobby", - "user_username": "bobby", - "actions": [ - { - "label": "Open Coder", - "url": "http://test.com" - } - ], - "labels": { - "account_activator_user_name": "rob", - "activated_account_name": "bobby" - }, - "data": null - }, - "title": "Your account \"bobby\" has been activated", - "title_markdown": "Your account \"bobby\" has been activated", - "body": "Hi Bobby,\n\nYour account bobby has been activated by rob.", - "body_markdown": "Hi Bobby,\n\nYour account **bobby** has been activated by **rob**." -} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.golden.json b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden similarity index 86% rename from coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.golden.json rename to coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden index 4d24c1e6c7f40..80e7cf9f9afd3 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.golden.json +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "12ee9ab1-a216-437c-a947-9126caffa515", + "msg_id": "1c9bf8bb-e871-4b90-a6af-415f65263af5", "payload": { "_version": "1.1", "notification_name": "Your account has been suspended", "notification_template_id": "6a2f0609-9b69-4d36-a989-9f5925b6cbff", - "user_id": "91875bd4-1abb-468b-95fe-5861774a8d71", + "user_id": "df02aa0c-66fb-4fed-8a48-1c83f5d7fa97", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", From 91e3f94534a9ba54ab2208a0cc5774bc19f5e515 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 08:51:44 +0000 Subject: [PATCH 27/44] chore(coderd/notifications): remove defunct test --- coderd/notifications/dispatch/smtp_test.go | 130 --------------------- 1 file changed, 130 deletions(-) diff --git a/coderd/notifications/dispatch/smtp_test.go b/coderd/notifications/dispatch/smtp_test.go index 05dc0b80a2a7f..febc646f53d39 100644 --- a/coderd/notifications/dispatch/smtp_test.go +++ b/coderd/notifications/dispatch/smtp_test.go @@ -5,9 +5,6 @@ import ( _ "embed" "fmt" "log" - "os" - "path/filepath" - "strings" "sync" "testing" @@ -524,130 +521,3 @@ func TestSMTP(t *testing.T) { }) } } - -func TestSMTPGolden(t *testing.T) { - t.Parallel() - - const ( - username = "bob" - password = "🤫" - - hello = "localhost" - from = "system@coder.com" - ) - - tcs := []struct { - name string - cfg codersdk.NotificationsEmailConfig - payload types.MessagePayload - // TODO: should this be part of the payload: - subject string - body string - }{ - { - name: "_body", - cfg: codersdk.NotificationsEmailConfig{ - Hello: hello, - From: from, - - Auth: codersdk.NotificationsEmailAuthConfig{ - Username: username, - Password: password, - }, - }, - payload: types.MessagePayload{ - UserName: "Bobby", - UserEmail: "bobby@coder.com", - UserUsername: "bobby", - Labels: map[string]string{ - "name": "bobby-workspace", - "reason": "autodeleted due to dormancy", - "initiator": "autobuild", - }, - }, - subject: "Workspace bobby-workspace has been deleted", - body: "Workspace bobby-workspace has been deleted due to dormancy by autobuild.", - }, - } - for _, tc := range tcs { - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - ctx := testutil.Context(t, testutil.WaitShort) - - backend := mock_smtp.NewBackend(mock_smtp.Config{ - AuthMechanisms: []string{sasl.Login}, - - AcceptedIdentity: tc.cfg.Auth.Identity.String(), - AcceptedUsername: username, - AcceptedPassword: password, - }) - - // Create a mock SMTP server which conditionally listens for plain or TLS connections. - srv, listen, err := mock_smtp.CreateMockSMTPServer(backend, false) - require.NoError(t, err) - t.Cleanup(func() { - // We expect that the server has already been closed in the test - assert.ErrorIs(t, srv.Shutdown(ctx), smtp.ErrServerClosed) - }) - - var hp serpent.HostPort - require.NoError(t, hp.Set(listen.Addr().String())) - tc.cfg.Smarthost = hp - - // Start mock SMTP server in the background. - var wg sync.WaitGroup - wg.Add(1) - go func() { - defer wg.Done() - assert.NoError(t, srv.Serve(listen)) - }() - - // Wait for the server to become pingable. - require.Eventually(t, func() bool { - cl, err := mock_smtp.PingClient(listen, false, tc.cfg.TLS.StartTLS.Value()) - if err != nil { - t.Logf("smtp not yet dialable: %s", err) - return false - } - - if err = cl.Noop(); err != nil { - t.Logf("smtp not yet noopable: %s", err) - return false - } - - if err = cl.Close(); err != nil { - t.Logf("smtp didn't close properly: %s", err) - return false - } - - return true - }, testutil.WaitShort, testutil.IntervalFast) - - logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true, IgnoredErrorIs: []error{}}).Leveled(slog.LevelDebug) - helpers := map[string]any{ - "base_url": func() string { return "http://test.com" }, - "current_year": func() string { return "2024" }, - } - handler := dispatch.NewSMTPHandler(tc.cfg, helpers, logger.Named("smtp")) - dispatchFn, err := handler.Dispatcher(tc.payload, tc.subject, tc.body) - require.NoError(t, err) - msgID := uuid.New() - retryable, err := dispatchFn(ctx, msgID) - require.NoError(t, err) - require.False(t, retryable) - - msg := backend.LastMessage() - - // msgJSON, err := json.MarshalIndent(msg, "", " ") - // require.NoError(t, err, "want no error marshaling payload to JSON") - - partialName := strings.Split(t.Name(), "/")[1] - goldenFile := filepath.Join("testdata", "rendered-templates", partialName+".golden.html") - // TODO: add flag to update golden files - err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) - require.NoError(t, err, "want no error creating golden file directory") - err = os.WriteFile(goldenFile, []byte(msg.Contents), 0o600) - require.NoError(t, err, "want no error writing body golden file") - }) - } -} From 34305802c18d711c0cbbe8a1e7d5f6e723d17921 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 09:03:43 +0000 Subject: [PATCH 28/44] chore(coderd/notifications): half the number of db containers needed for the golden file test --- coderd/notifications/notifications_test.go | 59 ++++++------------- .../smtp/TemplateTemplateDeleted.html.golden | 12 ++-- .../TemplateUserAccountActivated.html.golden | 12 ++-- .../TemplateUserAccountCreated.html.golden | 12 ++-- .../TemplateUserAccountDeleted.html.golden | 12 ++-- .../TemplateUserAccountSuspended.html.golden | 12 ++-- ...teUserRequestedOneTimePasscode.html.golden | 12 ++-- .../TemplateWorkspaceAutoUpdated.html.golden | 12 ++-- ...mplateWorkspaceAutobuildFailed.html.golden | 12 ++-- ...ateWorkspaceBuildsFailedReport.html.golden | 12 ++-- .../smtp/TemplateWorkspaceDeleted.html.golden | 12 ++-- .../smtp/TemplateWorkspaceDormant.html.golden | 12 ++-- ...lateWorkspaceManualBuildFailed.html.golden | 12 ++-- ...lateWorkspaceMarkedForDeletion.html.golden | 12 ++-- .../TemplateYourAccountActivated.html.golden | 12 ++-- .../TemplateYourAccountSuspended.html.golden | 12 ++-- .../TemplateTemplateDeleted.json.golden | 29 +++++++++ .../TemplateUserAccountActivated.json.golden | 29 +++++++++ .../TemplateUserAccountCreated.json.golden | 29 +++++++++ .../TemplateUserAccountDeleted.json.golden | 4 +- .../TemplateUserAccountSuspended.json.golden | 4 +- ...teUserRequestedOneTimePasscode.json.golden | 4 +- .../TemplateWorkspaceAutoUpdated.json.golden | 4 +- ...ateWorkspaceBuildsFailedReport.json.golden | 4 +- .../TemplateWorkspaceDeleted.json.golden | 4 +- .../TemplateWorkspaceDormant.json.golden | 4 +- ...lateWorkspaceManualBuildFailed.json.golden | 4 +- ...lateWorkspaceMarkedForDeletion.json.golden | 4 +- .../TemplateYourAccountActivated.json.golden | 28 +++++++++ .../TemplateYourAccountSuspended.json.golden | 4 +- 30 files changed, 244 insertions(+), 150 deletions(-) create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.json.golden create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index f393482dc26b8..9d2bd5db046e6 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -984,31 +984,30 @@ func TestNotificationTemplates_Golden(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() + // Spin up the DB + db, logger, user := func() (*database.Store, *slog.Logger, *codersdk.User) { + adminClient, _, api := coderdtest.NewWithAPI(t, nil) + db := api.Database + firstUser := coderdtest.CreateFirstUser(t, adminClient) + + _, user := coderdtest.CreateAnotherUserMutators( + t, + adminClient, + firstUser.OrganizationID, + []rbac.RoleIdentifier{rbac.RoleUserAdmin()}, + func(r *codersdk.CreateUserRequestWithOrgs) { + r.Username = tc.payload.UserUsername + r.Email = tc.payload.UserEmail + r.Name = tc.payload.UserName + }, + ) + return &db, &api.Logger, &user + }() t.Run("smtp", func(t *testing.T) { t.Parallel() // nolint:gocritic // Unit test. ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong)) - // Spin up the DB - db, logger, user := func() (*database.Store, *slog.Logger, *codersdk.User) { - adminClient, _, api := coderdtest.NewWithAPI(t, nil) - db := api.Database - firstUser := coderdtest.CreateFirstUser(t, adminClient) - - _, user := coderdtest.CreateAnotherUserMutators( - t, - adminClient, - firstUser.OrganizationID, - []rbac.RoleIdentifier{rbac.RoleUserAdmin()}, - func(r *codersdk.CreateUserRequestWithOrgs) { - r.Username = tc.payload.UserUsername - r.Email = tc.payload.UserEmail - r.Name = tc.payload.UserName - }, - ) - return &db, &api.Logger, &user - }() - // smtp config shared between client and server smtpConfig := codersdk.NotificationsEmailConfig{ Hello: hello, @@ -1138,26 +1137,6 @@ func TestNotificationTemplates_Golden(t *testing.T) { // nolint:gocritic // Unit test. ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong)) - // Spin up the DB - db, logger, user := func() (*database.Store, *slog.Logger, *codersdk.User) { - adminClient, _, api := coderdtest.NewWithAPI(t, nil) - db := api.Database - firstUser := coderdtest.CreateFirstUser(t, adminClient) - - _, user := coderdtest.CreateAnotherUserMutators( - t, - adminClient, - firstUser.OrganizationID, - []rbac.RoleIdentifier{rbac.RoleUserAdmin()}, - func(r *codersdk.CreateUserRequestWithOrgs) { - r.Username = tc.payload.UserUsername - r.Email = tc.payload.UserEmail - r.Name = tc.payload.UserName - }, - ) - return &db, &api.Logger, &user - }() - // Spin up the mock webhook server server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { body, err := io.ReadAll(r.Body) diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden index 39785f26a2679..b08603ceb8196 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Template "bobby-template" deleted -Message-Id: 594e3030-3739-4fbe-9b87-d0a938643421@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:19 +0000 -Content-Type: multipart/alternative; boundary=447921ad2714ac4f86104675f6509e2680c989166680aa4f7cae88d6750f +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 ---447921ad2714ac4f86104675f6509e2680c989166680aa4f7cae88d6750f +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The template's display name was Bobby's Template. View templates: http://test.com/templates ---447921ad2714ac4f86104675f6509e2680c989166680aa4f7cae88d6750f +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ settings

---447921ad2714ac4f86104675f6509e2680c989166680aa4f7cae88d6750f-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden index c3981364d61e6..cdce55c3e295d 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" activated -Message-Id: 6c9a538c-f8b3-4f9c-8547-bb52d757b184@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:19 +0000 -Content-Type: multipart/alternative; boundary=d44e54c0e6b873b490ad047485e07977c08f31eea714f7ba723d6a18dcb6 +Message-Id: b461ba56-abab-4008-bfa4-4e771113e754@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:07 +0000 +Content-Type: multipart/alternative; boundary=f04cc50c02020a85ebc3097e203e5e3a5f276b38125682d672f749887f49 MIME-Version: 1.0 ---d44e54c0e6b873b490ad047485e07977c08f31eea714f7ba723d6a18dcb6 +--f04cc50c02020a85ebc3097e203e5e3a5f276b38125682d672f749887f49 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---d44e54c0e6b873b490ad047485e07977c08f31eea714f7ba723d6a18dcb6 +--f04cc50c02020a85ebc3097e203e5e3a5f276b38125682d672f749887f49 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -81,4 +81,4 @@ af851-8408-4e73-a7a1-c6502ba46689" style=3D"color: #2563eb; text-decoration= ---d44e54c0e6b873b490ad047485e07977c08f31eea714f7ba723d6a18dcb6-- +--f04cc50c02020a85ebc3097e203e5e3a5f276b38125682d672f749887f49-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden index 8a160970b25f4..da4b507ee025b 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" created -Message-Id: 9a5175ad-aaf7-4c63-b9c9-3fbf32a9521d@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:21 +0000 -Content-Type: multipart/alternative; boundary=5a39f983512f0a37c4267f0a1947a75384e3e007827db26aab1207d1d51d +Message-Id: 8e831cb4-db87-486b-b78a-acfabedb9cbd@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:05 +0000 +Content-Type: multipart/alternative; boundary=4d7b42ea36b6ca3e087492b5929487d17ad55632cb0fca8da9d89c55e320 MIME-Version: 1.0 ---5a39f983512f0a37c4267f0a1947a75384e3e007827db26aab1207d1d51d +--4d7b42ea36b6ca3e087492b5929487d17ad55632cb0fca8da9d89c55e320 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ This new user account was created for William Tables by rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---5a39f983512f0a37c4267f0a1947a75384e3e007827db26aab1207d1d51d +--4d7b42ea36b6ca3e087492b5929487d17ad55632cb0fca8da9d89c55e320 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ settings

---5a39f983512f0a37c4267f0a1947a75384e3e007827db26aab1207d1d51d-- +--4d7b42ea36b6ca3e087492b5929487d17ad55632cb0fca8da9d89c55e320-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden index f0487c6f3c1c4..73abeaffde76a 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" deleted -Message-Id: d00c1134-3931-435c-b629-28614b1f06c6@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:20 +0000 -Content-Type: multipart/alternative; boundary=f058ea3e397629381c9a67aa79759cb51fa9834e0b92219e4e4c04f2a42f +Message-Id: 170b30b6-f691-4b13-919e-80818944aeb1@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:06 +0000 +Content-Type: multipart/alternative; boundary=de0048dbc8bca99bd1ab342049c61f4476f453b1e1d73d2875a4bcde73ee MIME-Version: 1.0 ---f058ea3e397629381c9a67aa79759cb51fa9834e0b92219e4e4c04f2a42f +--de0048dbc8bca99bd1ab342049c61f4476f453b1e1d73d2875a4bcde73ee Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The deleted account belonged to william tables and was deleted by rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---f058ea3e397629381c9a67aa79759cb51fa9834e0b92219e4e4c04f2a42f +--de0048dbc8bca99bd1ab342049c61f4476f453b1e1d73d2875a4bcde73ee Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ d9314-ad03-4bc8-95d0-5cad491da6b6" style=3D"color: #2563eb; text-decoration= ---f058ea3e397629381c9a67aa79759cb51fa9834e0b92219e4e4c04f2a42f-- +--de0048dbc8bca99bd1ab342049c61f4476f453b1e1d73d2875a4bcde73ee-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden index 967ea0487fc26..3f50991095816 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" suspended -Message-Id: ab5f31a2-db2a-4e79-ac9d-d0f8a00724ad@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:21 +0000 -Content-Type: multipart/alternative; boundary=819d44b7bb641ccf7500ad9f4b8ec0f5a30bb8e366c06d5ce48ad3bda838 +Message-Id: ed015d1a-c965-466c-92a0-0e045bf628c4@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:06 +0000 +Content-Type: multipart/alternative; boundary=c2cb4b8b684d58736742e5586bdcdf7eb651bcf544531168cab4c54bfc3c MIME-Version: 1.0 ---819d44b7bb641ccf7500ad9f4b8ec0f5a30bb8e366c06d5ce48ad3bda838 +--c2cb4b8b684d58736742e5586bdcdf7eb651bcf544531168cab4c54bfc3c Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ rob. View suspended accounts: http://test.com/deployment/users?filter=3Dstatus%3= Asuspended ---819d44b7bb641ccf7500ad9f4b8ec0f5a30bb8e366c06d5ce48ad3bda838 +--c2cb4b8b684d58736742e5586bdcdf7eb651bcf544531168cab4c54bfc3c Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -82,4 +82,4 @@ ddd82-4733-4d02-a2d7-c36f3598997d" style=3D"color: #2563eb; text-decoration= ---819d44b7bb641ccf7500ad9f4b8ec0f5a30bb8e366c06d5ce48ad3bda838-- +--c2cb4b8b684d58736742e5586bdcdf7eb651bcf544531168cab4c54bfc3c-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden index ee764df3eb1e1..24643c8dc6e1b 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Your One-Time Passcode for Coder. -Message-Id: d368bc59-2aa5-477d-adc3-dfb5c905ef2e@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:19 +0000 -Content-Type: multipart/alternative; boundary=7ba286314219f64e5482c0c4f30a001bd4bbbf66c0b8c9ea110715bf5944 +Message-Id: 6009ee2f-caa3-4737-a45b-f44dae2cc3f1@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:07 +0000 +Content-Type: multipart/alternative; boundary=3153b54208d8ff0152f85b69baff66db80db5ed650a3785e4b5826d9d122 MIME-Version: 1.0 ---7ba286314219f64e5482c0c4f30a001bd4bbbf66c0b8c9ea110715bf5944 +--3153b54208d8ff0152f85b69baff66db80db5ed650a3785e4b5826d9d122 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ fad9020b-6562-4cdb-87f1-0486f1bea415 If you did not request to reset your password, you can ignore this message. ---7ba286314219f64e5482c0c4f30a001bd4bbbf66c0b8c9ea110715bf5944 +--3153b54208d8ff0152f85b69baff66db80db5ed650a3785e4b5826d9d122 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -77,4 +77,4 @@ settings

---7ba286314219f64e5482c0c4f30a001bd4bbbf66c0b8c9ea110715bf5944-- +--3153b54208d8ff0152f85b69baff66db80db5ed650a3785e4b5826d9d122-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden index 2378296b5d854..81604406132e1 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" updated automatically -Message-Id: 9898c8e5-4041-4367-b40f-3b7856d76a23@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:20 +0000 -Content-Type: multipart/alternative; boundary=1ac2f0e4f21ec1ee3770de15791fc5e038e19727bb8184fde045b29fa385 +Message-Id: 9774959e-fb51-4f31-b0ea-0de197a7a388@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:06 +0000 +Content-Type: multipart/alternative; boundary=8cafbf6465dc72be0db427eaf016e3a3be04541d8acf2897e93e07b73d2a MIME-Version: 1.0 ---1ac2f0e4f21ec1ee3770de15791fc5e038e19727bb8184fde045b29fa385 +--8cafbf6465dc72be0db427eaf016e3a3be04541d8acf2897e93e07b73d2a Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ Reason for update: template now includes catnip. View workspace: http://test.com/@bobby/bobby-workspace ---1ac2f0e4f21ec1ee3770de15791fc5e038e19727bb8184fde045b29fa385 +--8cafbf6465dc72be0db427eaf016e3a3be04541d8acf2897e93e07b73d2a Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ a0c09-0704-4cac-bd1c-0c0146811c2b" style=3D"color: #2563eb; text-decoration= ---1ac2f0e4f21ec1ee3770de15791fc5e038e19727bb8184fde045b29fa385-- +--8cafbf6465dc72be0db427eaf016e3a3be04541d8acf2897e93e07b73d2a-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden index c4f5ff8645739..343e36046982b 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" autobuild failed -Message-Id: 6f923006-7d0d-4754-9d37-175df97de68a@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:20 +0000 -Content-Type: multipart/alternative; boundary=e2d2f921b2a16b9438a715de73cb6942bc52777cf2fe2e2335c24e35fb7d +Message-Id: 6305d418-20e5-4dc7-83f1-9d8ad735b6b2@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:06 +0000 +Content-Type: multipart/alternative; boundary=d56d3764d42cbbc7e0ca6b63ac5b20b5dbe48f1f95ec3f5cc9857bf4ef85 MIME-Version: 1.0 ---e2d2f921b2a16b9438a715de73cb6942bc52777cf2fe2e2335c24e35fb7d +--d56d3764d42cbbc7e0ca6b63ac5b20b5dbe48f1f95ec3f5cc9857bf4ef85 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The specified reason was "autostart". View workspace: http://test.com/@bobby/bobby-workspace ---e2d2f921b2a16b9438a715de73cb6942bc52777cf2fe2e2335c24e35fb7d +--d56d3764d42cbbc7e0ca6b63ac5b20b5dbe48f1f95ec3f5cc9857bf4ef85 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -79,4 +79,4 @@ df2a9-c0c0-4749-420f-80a9280c66f9" style=3D"color: #2563eb; text-decoration= ---e2d2f921b2a16b9438a715de73cb6942bc52777cf2fe2e2335c24e35fb7d-- +--d56d3764d42cbbc7e0ca6b63ac5b20b5dbe48f1f95ec3f5cc9857bf4ef85-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden index 2826179aa1bd7..cd6e269b4069b 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace builds failed for template "Bobby First Template" -Message-Id: e0da8dbd-8c83-4316-80a4-d5c38588d078@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:20 +0000 -Content-Type: multipart/alternative; boundary=be4e7b4085c012c76c863f28373423efe1f6867f3e3a32fe861b745a26c1 +Message-Id: 5e3a6c97-f422-4f24-a4b7-bc7dd0496201@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:07 +0000 +Content-Type: multipart/alternative; boundary=21e938349974f6fb155498c7ad0fb081c6d264ffb38ca8108d3bf8264d4e MIME-Version: 1.0 ---be4e7b4085c012c76c863f28373423efe1f6867f3e3a32fe861b745a26c1 +--21e938349974f6fb155498c7ad0fb081c6d264ffb38ca8108d3bf8264d4e Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -36,7 +36,7 @@ We recommend reviewing these issues to ensure future builds are successful. View workspaces: http://test.com/workspaces?filter=3Dtemplate%3Abobby-first= -template ---be4e7b4085c012c76c863f28373423efe1f6867f3e3a32fe861b745a26c1 +--21e938349974f6fb155498c7ad0fb081c6d264ffb38ca8108d3bf8264d4e Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -123,4 +123,4 @@ settings

---be4e7b4085c012c76c863f28373423efe1f6867f3e3a32fe861b745a26c1-- +--21e938349974f6fb155498c7ad0fb081c6d264ffb38ca8108d3bf8264d4e-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden index 992a76a08fbf5..9798b1a37cda1 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" deleted -Message-Id: 4a2693d0-217d-4b5f-93dd-ddd01f468754@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:20 +0000 -Content-Type: multipart/alternative; boundary=433a452845ca4849cfd341dacc13786c1370a43411418f886679b0f31c67 +Message-Id: aa79c7ce-c406-4133-9454-8de5386e3fa2@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:07 +0000 +Content-Type: multipart/alternative; boundary=a5c60a371038ba0928462f9ecb9941040823dee28a4cafcbaecc23628b3f MIME-Version: 1.0 ---433a452845ca4849cfd341dacc13786c1370a43411418f886679b0f31c67 +--a5c60a371038ba0928462f9ecb9941040823dee28a4cafcbaecc23628b3f Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ View workspaces: http://test.com/workspaces View templates: http://test.com/templates ---433a452845ca4849cfd341dacc13786c1370a43411418f886679b0f31c67 +--a5c60a371038ba0928462f9ecb9941040823dee28a4cafcbaecc23628b3f Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -87,4 +87,4 @@ settings

---433a452845ca4849cfd341dacc13786c1370a43411418f886679b0f31c67-- +--a5c60a371038ba0928462f9ecb9941040823dee28a4cafcbaecc23628b3f-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden index 484f232b1063a..4db7fc7a50b48 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" marked as dormant -Message-Id: 7eac38f6-49c5-4bfe-9aef-ecb97ba2301f@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:20 +0000 -Content-Type: multipart/alternative; boundary=a10a7cffac232483ab8b79adbccbf93e2b633a8a800770fa7c887ad07581 +Message-Id: 034ab939-ef9f-4d40-b356-9a3fe50fa43a@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:06 +0000 +Content-Type: multipart/alternative; boundary=0ddb9c71df3785fb8bf571c38008ccf50a655b2572464aaba406d6b9b5d2 MIME-Version: 1.0 ---a10a7cffac232483ab8b79adbccbf93e2b633a8a800770fa7c887ad07581 +--0ddb9c71df3785fb8bf571c38008ccf50a655b2572464aaba406d6b9b5d2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -23,7 +23,7 @@ To prevent deletion, use your workspace with the link below. View workspace: http://test.com/@bobby/bobby-workspace ---a10a7cffac232483ab8b79adbccbf93e2b633a8a800770fa7c887ad07581 +--0ddb9c71df3785fb8bf571c38008ccf50a655b2572464aaba406d6b9b5d2 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -87,4 +87,4 @@ settings

---a10a7cffac232483ab8b79adbccbf93e2b633a8a800770fa7c887ad07581-- +--0ddb9c71df3785fb8bf571c38008ccf50a655b2572464aaba406d6b9b5d2-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden index a073f7abffadb..62698a8e96755 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" manual build failed -Message-Id: 8f4288e7-21d1-4ffc-aee8-03477b7f7528@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:20 +0000 -Content-Type: multipart/alternative; boundary=cd3836d096e1aa52ee20ee886c6451a5818cb89fedeb95f6c5ecaae05c1b +Message-Id: 9e1a8c51-ba7a-476a-8841-78c5311113c7@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:06 +0000 +Content-Type: multipart/alternative; boundary=aa5483a898ac4c112833763b8a7f0434ae1a507d213a3f0fb105b638d517 MIME-Version: 1.0 ---cd3836d096e1aa52ee20ee886c6451a5818cb89fedeb95f6c5ecaae05c1b +--aa5483a898ac4c112833763b8a7f0434ae1a507d213a3f0fb105b638d517 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ The template's display name was William's Template. The workspace build was= View build: http://test.com/@mrbobby/bobby-workspace/builds/3 ---cd3836d096e1aa52ee20ee886c6451a5818cb89fedeb95f6c5ecaae05c1b +--aa5483a898ac4c112833763b8a7f0434ae1a507d213a3f0fb105b638d517 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -83,4 +83,4 @@ eee0f-26cb-4e96-821c-85ccb9f71513" style=3D"color: #2563eb; text-decoration= ---cd3836d096e1aa52ee20ee886c6451a5818cb89fedeb95f6c5ecaae05c1b-- +--aa5483a898ac4c112833763b8a7f0434ae1a507d213a3f0fb105b638d517-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden index dd0459d943fa3..4a30d26e5b07f 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" marked for deletion -Message-Id: 7b69076f-5ff7-464e-b900-e9cf196b833b@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:19 +0000 -Content-Type: multipart/alternative; boundary=4a5d477affccf7f0e3204afecf0fd5dff7967619853c65b8d7361f84d4e9 +Message-Id: 24d9a559-ab86-41ce-89b4-281b0815f95e@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:06 +0000 +Content-Type: multipart/alternative; boundary=2d0f93482ad27ef16601523ee4474bd3e1d9dfc889a02e7c3e41eab2524b MIME-Version: 1.0 ---4a5d477affccf7f0e3204afecf0fd5dff7967619853c65b8d7361f84d4e9 +--2d0f93482ad27ef16601523ee4474bd3e1d9dfc889a02e7c3e41eab2524b Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ To prevent deletion, use your workspace with the link below. View workspace: http://test.com/@bobby/bobby-workspace ---4a5d477affccf7f0e3204afecf0fd5dff7967619853c65b8d7361f84d4e9 +--2d0f93482ad27ef16601523ee4474bd3e1d9dfc889a02e7c3e41eab2524b Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -81,4 +81,4 @@ e2fdf-c9ca-4be1-8d70-628674f9bc42" style=3D"color: #2563eb; text-decoration= ---4a5d477affccf7f0e3204afecf0fd5dff7967619853c65b8d7361f84d4e9-- +--2d0f93482ad27ef16601523ee4474bd3e1d9dfc889a02e7c3e41eab2524b-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden index a4e2cd73031ce..153570eb57f9f 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Your account "bobby" has been activated -Message-Id: 40aca67b-1800-4a31-bbd2-02c4795bcd69@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:20 +0000 -Content-Type: multipart/alternative; boundary=fd26e44cae82afa85bf853900feb4d7d60f926d8824d0ccee20ce5bd1fac +Message-Id: 9ec28fa4-e75c-4b32-a1ac-9622fa7212cf@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:06 +0000 +Content-Type: multipart/alternative; boundary=1b77880f5aa13bedc165ced8e5b766fb55b5490b2b2a9ef3233081821878 MIME-Version: 1.0 ---fd26e44cae82afa85bf853900feb4d7d60f926d8824d0ccee20ce5bd1fac +--1b77880f5aa13bedc165ced8e5b766fb55b5490b2b2a9ef3233081821878 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -17,7 +17,7 @@ Your account bobby has been activated by rob. Open Coder: http://test.com ---fd26e44cae82afa85bf853900feb4d7d60f926d8824d0ccee20ce5bd1fac +--1b77880f5aa13bedc165ced8e5b766fb55b5490b2b2a9ef3233081821878 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -75,4 +75,4 @@ a6bea-ee0a-43e2-9e7c-eabdb53730e4" style=3D"color: #2563eb; text-decoration= ---fd26e44cae82afa85bf853900feb4d7d60f926d8824d0ccee20ce5bd1fac-- +--1b77880f5aa13bedc165ced8e5b766fb55b5490b2b2a9ef3233081821878-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden index 73469cb31ff50..9836bbb5cd702 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Your account "bobby" has been suspended -Message-Id: 343918fb-d0a5-4f56-bd78-c3b6b69bdc35@blush-whale-48 -Date: Fri, 11 Oct 2024 08:47:21 +0000 -Content-Type: multipart/alternative; boundary=d9cb9c933e63b78261d6dc46623e61d8586e8f282898d3cf2d6a890ea428 +Message-Id: 2a4061e2-3049-477f-80c8-e67323a395cf@blush-whale-48 +Date: Fri, 11 Oct 2024 09:03:08 +0000 +Content-Type: multipart/alternative; boundary=60ded561f65e41fefc3a22e0b5d5ed3e9e6cb08eca49aa6dc740f1bffb92 MIME-Version: 1.0 ---d9cb9c933e63b78261d6dc46623e61d8586e8f282898d3cf2d6a890ea428 +--60ded561f65e41fefc3a22e0b5d5ed3e9e6cb08eca49aa6dc740f1bffb92 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -15,7 +15,7 @@ Hi Bobby, Your account bobby has been suspended by rob. ---d9cb9c933e63b78261d6dc46623e61d8586e8f282898d3cf2d6a890ea428 +--60ded561f65e41fefc3a22e0b5d5ed3e9e6cb08eca49aa6dc740f1bffb92 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -67,4 +67,4 @@ f0609-9b69-4d36-a989-9f5925b6cbff" style=3D"color: #2563eb; text-decoration= ---d9cb9c933e63b78261d6dc46623e61d8586e8f282898d3cf2d6a890ea428-- +--60ded561f65e41fefc3a22e0b5d5ed3e9e6cb08eca49aa6dc740f1bffb92-- diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.json.golden new file mode 100644 index 0000000000000..686c46a28c7d6 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.json.golden @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "8400889e-b369-4237-ad18-809d82e778fd", + "payload": { + "_version": "1.1", + "notification_name": "Template Deleted", + "notification_template_id": "29a09665-2a4c-403f-9648-54301670e7be", + "user_id": "37a2f3a5-ce78-4da7-8ee4-0a985ce5dad1", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View templates", + "url": "http://test.com/templates" + } + ], + "labels": { + "display_name": "Bobby's Template", + "initiator": "rob", + "name": "bobby-template" + }, + "data": null + }, + "title": "Template \"bobby-template\" deleted", + "title_markdown": "Template \"bobby-template\" deleted", + "body": "Hi Bobby,\n\nThe template bobby-template was deleted by rob.\n\nThe template's display name was Bobby's Template.", + "body_markdown": "Hi Bobby,\n\nThe template **bobby-template** was deleted by **rob**.\n\nThe template's display name was **Bobby's Template**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden new file mode 100644 index 0000000000000..5f04757910824 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "64d6e886-c75d-474c-b0cc-a0c2ee7d7b9f", + "payload": { + "_version": "1.1", + "notification_name": "User account activated", + "notification_template_id": "9f5af851-8408-4e73-a7a1-c6502ba46689", + "user_id": "0c91b12d-2732-4122-abe3-cee2bf64f1c2", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View accounts", + "url": "http://test.com/deployment/users?filter=status%3Aactive" + } + ], + "labels": { + "account_activator_user_name": "rob", + "activated_account_name": "bobby", + "activated_account_user_name": "william tables" + }, + "data": null + }, + "title": "User account \"bobby\" activated", + "title_markdown": "User account \"bobby\" activated", + "body": "Hi Bobby,\n\nUser account bobby has been activated.\n\nThe newly activated account belongs to william tables and was activated by rob.", + "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **william tables** and was activated by **rob**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden new file mode 100644 index 0000000000000..e5e2894c75717 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden @@ -0,0 +1,29 @@ +{ + "_version": "1.1", + "msg_id": "ed1515ce-1458-4901-a924-4a62933525f5", + "payload": { + "_version": "1.1", + "notification_name": "User account created", + "notification_template_id": "4e19c0ac-94e1-4532-9515-d1801aa283b2", + "user_id": "68bd9314-7226-4dc0-a4e7-166904706195", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "View accounts", + "url": "http://test.com/deployment/users?filter=status%3Aactive" + } + ], + "labels": { + "account_creator": "rob", + "created_account_name": "bobby", + "created_account_user_name": "William Tables" + }, + "data": null + }, + "title": "User account \"bobby\" created", + "title_markdown": "User account \"bobby\" created", + "body": "Hi Bobby,\n\nNew user account bobby has been created.\n\nThis new user account was created for William Tables by rob.", + "body_markdown": "Hi Bobby,\n\nNew user account **bobby** has been created.\n\nThis new user account was created for **William Tables** by **rob**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden index 0dd6ef8c73284..7ee7f01c40716 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "189afc53-45a9-4ad4-9fc9-a356371213d8", + "msg_id": "c8465b51-0d63-404c-b03f-f10b79cf8a5d", "payload": { "_version": "1.1", "notification_name": "User account deleted", "notification_template_id": "f44d9314-ad03-4bc8-95d0-5cad491da6b6", - "user_id": "624591bd-4b2c-4043-8de0-f5117def9cac", + "user_id": "c21d5acf-5e23-4843-80e0-e21409d31800", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden index 044700ae8b708..ad6c47238fa04 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "82610ed1-3183-458f-8511-bb2783949df6", + "msg_id": "2c313281-0c86-46ac-9867-43fab07affce", "payload": { "_version": "1.1", "notification_name": "User account suspended", "notification_template_id": "b02ddd82-4733-4d02-a2d7-c36f3598997d", - "user_id": "f6f64453-a003-49ea-9798-b95f806a05ef", + "user_id": "7c41c766-5f78-4b2b-b294-cae6918f4dfc", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden index a12b15294de1a..5f3913cc3698d 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "e01e2d20-a2e4-46d4-baf3-f6e415f86a1c", + "msg_id": "73c92921-b640-4ca0-8fae-c3d44b9886db", "payload": { "_version": "1.1", "notification_name": "One-Time Passcode", "notification_template_id": "62f86a30-2330-4b61-a26d-311ff3b608cf", - "user_id": "dcd3ed36-b669-42b0-843c-d37fbe5aecd8", + "user_id": "3b8e4ed5-10c0-40dd-87c3-b931c575adb9", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden index de7af7dcee5f5..88b42a771dc7b 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "c4d7beb1-af71-4d06-b857-f33848c6c7a3", + "msg_id": "0d2a1c10-6000-4e5d-9caa-2951fbc1b63d", "payload": { "_version": "1.1", "notification_name": "Workspace Updated Automatically", "notification_template_id": "c34a0c09-0704-4cac-bd1c-0c0146811c2b", - "user_id": "5d049111-4dde-44f5-bcaa-df91ffa623e2", + "user_id": "4fe26e16-c23c-40db-9649-612ed02c531a", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden index 1607568637adf..8560d69100507 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "3bead610-6bb2-4e5a-a1e9-b1d7710be8b8", + "msg_id": "d0566fff-9315-4e91-a055-28b7158b7ec9", "payload": { "_version": "1.1", "notification_name": "Report: Workspace Builds Failed For Template", "notification_template_id": "34a20db2-e9cc-4a93-b0e4-8569699d7a00", - "user_id": "bffed10b-d7bb-4588-a536-da8001ca31a0", + "user_id": "e28bc1f4-836b-41ae-a3e3-19a3c2050ac3", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden index 62481cfd9f427..10ba2f4fe6158 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "61237bb8-5d56-4c16-b9a8-c56d405cb852", + "msg_id": "f14e06d6-0798-4027-9b05-a1c818a02099", "payload": { "_version": "1.1", "notification_name": "Workspace Deleted", "notification_template_id": "f517da0b-cdc9-410f-ab89-a86107c420ed", - "user_id": "ff5ba700-51c0-491d-bcda-cd76791dd451", + "user_id": "78daa6f4-11d6-4d81-a8d4-87a335730c08", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden index 101be46806a97..d881d37bf2dae 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "32482851-cf1b-4613-b0d2-a999f54f4f10", + "msg_id": "0203cfea-c559-4e29-a0ca-b88218df57ef", "payload": { "_version": "1.1", "notification_name": "Workspace Marked as Dormant", "notification_template_id": "0ea69165-ec14-4314-91f1-69566ac3c5a0", - "user_id": "23ad77bf-b02b-42a6-9b4a-bd2637300cbd", + "user_id": "428dd40d-3f51-4e1a-8a28-5d2e6fe8f323", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden index 15ed6de77c349..4ee301aebc5a8 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "af88d7f4-cb57-4baf-afc3-01e41a57164a", + "msg_id": "bd14c03f-fc48-4ca1-9b46-9201e732e657", "payload": { "_version": "1.1", "notification_name": "Workspace Manual Build Failed", "notification_template_id": "2faeee0f-26cb-4e96-821c-85ccb9f71513", - "user_id": "9766302b-44d8-4e38-84fc-2817969c6790", + "user_id": "5c34a281-2fda-4064-ac0a-88979c2c5bd2", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden index 874eb3a240873..f1505ce77d95c 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "c354e9b3-03f9-4f14-9dbf-d327f96bf465", + "msg_id": "5fe52634-c753-489c-8ba2-e31075fa0122", "payload": { "_version": "1.1", "notification_name": "Workspace Marked for Deletion", "notification_template_id": "51ce2fdf-c9ca-4be1-8d70-628674f9bc42", - "user_id": "6f8e5805-dbba-4aa5-ba80-6cc0b393a790", + "user_id": "a0a91a17-a760-4da4-b471-ecbf193b323f", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden new file mode 100644 index 0000000000000..76d901c50f0b1 --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden @@ -0,0 +1,28 @@ +{ + "_version": "1.1", + "msg_id": "a7084e57-fd18-4bb8-9320-63060592f7aa", + "payload": { + "_version": "1.1", + "notification_name": "Your account has been activated", + "notification_template_id": "1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4", + "user_id": "7b7cc6a1-29d5-4d5e-8b33-3810346885fe", + "user_email": "bobby@coder.com", + "user_name": "Bobby", + "user_username": "bobby", + "actions": [ + { + "label": "Open Coder", + "url": "http://test.com" + } + ], + "labels": { + "account_activator_user_name": "rob", + "activated_account_name": "bobby" + }, + "data": null + }, + "title": "Your account \"bobby\" has been activated", + "title_markdown": "Your account \"bobby\" has been activated", + "body": "Hi Bobby,\n\nYour account bobby has been activated by rob.", + "body_markdown": "Hi Bobby,\n\nYour account **bobby** has been activated by **rob**." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden index 80e7cf9f9afd3..47a674b07e3e0 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "1c9bf8bb-e871-4b90-a6af-415f65263af5", + "msg_id": "6c60d9dc-36b2-4f93-a19d-4e7308820ede", "payload": { "_version": "1.1", "notification_name": "Your account has been suspended", "notification_template_id": "6a2f0609-9b69-4d36-a989-9f5925b6cbff", - "user_id": "df02aa0c-66fb-4fed-8a48-1c83f5d7fa97", + "user_id": "c97b703e-203e-4db4-ad18-29136f6ffb80", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", From 9d477856f80d6826936114561eec743fa46a68f8 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 09:21:33 +0000 Subject: [PATCH 29/44] chore(coderd/notifications): ensure that all rendered golden files are idempotent --- coderd/notifications/notifications_test.go | 37 +++++++++++++++++-- .../smtp/TemplateTemplateDeleted.html.golden | 12 +++--- .../TemplateUserAccountActivated.html.golden | 12 +++--- .../TemplateUserAccountCreated.html.golden | 12 +++--- .../TemplateUserAccountDeleted.html.golden | 12 +++--- .../TemplateUserAccountSuspended.html.golden | 12 +++--- ...teUserRequestedOneTimePasscode.html.golden | 12 +++--- .../TemplateWorkspaceAutoUpdated.html.golden | 12 +++--- ...mplateWorkspaceAutobuildFailed.html.golden | 12 +++--- ...ateWorkspaceBuildsFailedReport.html.golden | 12 +++--- .../smtp/TemplateWorkspaceDeleted.html.golden | 12 +++--- .../smtp/TemplateWorkspaceDormant.html.golden | 12 +++--- ...lateWorkspaceManualBuildFailed.html.golden | 12 +++--- ...lateWorkspaceMarkedForDeletion.html.golden | 12 +++--- .../TemplateYourAccountActivated.html.golden | 12 +++--- .../TemplateYourAccountSuspended.html.golden | 12 +++--- .../TemplateTemplateDeleted.json.golden | 6 +-- .../TemplateUserAccountActivated.json.golden | 4 +- .../TemplateUserAccountCreated.json.golden | 6 +-- .../TemplateUserAccountDeleted.json.golden | 4 +- .../TemplateUserAccountSuspended.json.golden | 6 +-- .../TemplateWorkspaceAutoUpdated.json.golden | 6 +-- ...mplateWorkspaceAutobuildFailed.json.golden | 28 ++++++++++++++ ...ateWorkspaceBuildsFailedReport.json.golden | 4 +- .../TemplateWorkspaceDeleted.json.golden | 6 +-- .../TemplateWorkspaceDormant.json.golden | 6 +-- ...lateWorkspaceManualBuildFailed.json.golden | 6 +-- ...lateWorkspaceMarkedForDeletion.json.golden | 4 +- .../TemplateYourAccountActivated.json.golden | 6 +-- .../TemplateYourAccountSuspended.json.golden | 6 +-- 30 files changed, 187 insertions(+), 128 deletions(-) create mode 100644 coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutobuildFailed.json.golden diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 9d2bd5db046e6..640cd71c1eaa0 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -16,6 +16,7 @@ import ( "net/url" "os" "path/filepath" + "regexp" "slices" "sort" "strings" @@ -1114,6 +1115,8 @@ func TestNotificationTemplates_Golden(t *testing.T) { }, testutil.WaitShort, testutil.IntervalFast) require.NotNil(t, msg, "want a message to be sent") + body := constantifyGoldenEmail([]byte(msg.Contents)) + err = smtpManager.Stop(ctx) require.NoError(t, err) @@ -1122,14 +1125,14 @@ func TestNotificationTemplates_Golden(t *testing.T) { if *updateGoldenFiles { err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) require.NoError(t, err, "want no error creating golden file directory") - err = os.WriteFile(goldenFile, []byte(msg.Contents), 0o600) + err = os.WriteFile(goldenFile, body, 0o600) require.NoError(t, err, "want no error writing body golden file") return } wantBody, err := os.ReadFile(goldenFile) require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) - require.Equal(t, string(wantBody), msg.Contents, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint)) + require.Equal(t, string(wantBody), string(body), fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint)) }) t.Run("webhook", func(t *testing.T) { @@ -1145,12 +1148,14 @@ func TestNotificationTemplates_Golden(t *testing.T) { err = json.Indent(&prettyJSON, body, "", " ") require.NoError(t, err) + content := constantifyGoldenWebhook(prettyJSON.Bytes()) + partialName := strings.Split(t.Name(), "/")[1] goldenFile := filepath.Join("testdata", "rendered-templates", "webhook", partialName+".json.golden") if *updateGoldenFiles { err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) require.NoError(t, err, "want no error creating golden file directory") - err = os.WriteFile(goldenFile, prettyJSON.Bytes(), 0o600) + err = os.WriteFile(goldenFile, content, 0o600) require.NoError(t, err, "want no error writing body golden file") w.WriteHeader(http.StatusOK) return @@ -1211,6 +1216,32 @@ func TestNotificationTemplates_Golden(t *testing.T) { } } +func constantifyGoldenEmail(content []byte) []byte { + const ( + constantDate = "Fri, 11 Oct 2024 09:03:06 +0000" + constantMessageID = "02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48" + constantBoundary = "bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4" + ) + + dateRegex := regexp.MustCompile(`Date: .+`) + messageIDRegex := regexp.MustCompile(`Message-Id: .+`) + boundaryRegex := regexp.MustCompile(`boundary=.+`) + + content = dateRegex.ReplaceAll(content, []byte("Date: "+constantDate)) + content = messageIDRegex.ReplaceAll(content, []byte("Message-Id: "+constantMessageID)) + content = boundaryRegex.ReplaceAll(content, []byte("boundary="+constantBoundary)) + + return content +} + +func constantifyGoldenWebhook(content []byte) []byte { + const constantUUID = "00000000-0000-0000-0000-000000000000" + uuidRegex := regexp.MustCompile(`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`) + content = uuidRegex.ReplaceAll(content, []byte(constantUUID)) + + return content +} + // TestDisabledBeforeEnqueue ensures that notifications cannot be enqueued once a user has disabled that notification template func TestDisabledBeforeEnqueue(t *testing.T) { t.Parallel() diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden index b08603ceb8196..d7c014ded539b 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Template "bobby-template" deleted -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 +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 +--52a54cf75286afea52caccee3f80d8009b149fa636540750ccc6c23b560a Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The template's display name was Bobby's Template. View templates: http://test.com/templates ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--52a54cf75286afea52caccee3f80d8009b149fa636540750ccc6c23b560a Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ settings

---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- +--52a54cf75286afea52caccee3f80d8009b149fa636540750ccc6c23b560a-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden index cdce55c3e295d..cf8430583271e 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" activated -Message-Id: b461ba56-abab-4008-bfa4-4e771113e754@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:07 +0000 -Content-Type: multipart/alternative; boundary=f04cc50c02020a85ebc3097e203e5e3a5f276b38125682d672f749887f49 +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 ---f04cc50c02020a85ebc3097e203e5e3a5f276b38125682d672f749887f49 +--a67aa67e0f976132dec706b08d966add4d34d5f7ef3ccdf0fd1bc3bf80ec Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---f04cc50c02020a85ebc3097e203e5e3a5f276b38125682d672f749887f49 +--a67aa67e0f976132dec706b08d966add4d34d5f7ef3ccdf0fd1bc3bf80ec Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -81,4 +81,4 @@ af851-8408-4e73-a7a1-c6502ba46689" style=3D"color: #2563eb; text-decoration= ---f04cc50c02020a85ebc3097e203e5e3a5f276b38125682d672f749887f49-- +--a67aa67e0f976132dec706b08d966add4d34d5f7ef3ccdf0fd1bc3bf80ec-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden index da4b507ee025b..599df0788764e 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" created -Message-Id: 8e831cb4-db87-486b-b78a-acfabedb9cbd@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:05 +0000 -Content-Type: multipart/alternative; boundary=4d7b42ea36b6ca3e087492b5929487d17ad55632cb0fca8da9d89c55e320 +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 ---4d7b42ea36b6ca3e087492b5929487d17ad55632cb0fca8da9d89c55e320 +--66ddaa699eb126a27ee6a1bbac51e14ebcbe56e91f3eeddfa67ad5285f1d Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ This new user account was created for William Tables by rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---4d7b42ea36b6ca3e087492b5929487d17ad55632cb0fca8da9d89c55e320 +--66ddaa699eb126a27ee6a1bbac51e14ebcbe56e91f3eeddfa67ad5285f1d Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ settings

---4d7b42ea36b6ca3e087492b5929487d17ad55632cb0fca8da9d89c55e320-- +--66ddaa699eb126a27ee6a1bbac51e14ebcbe56e91f3eeddfa67ad5285f1d-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden index 73abeaffde76a..f061464c69f70 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" deleted -Message-Id: 170b30b6-f691-4b13-919e-80818944aeb1@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:06 +0000 -Content-Type: multipart/alternative; boundary=de0048dbc8bca99bd1ab342049c61f4476f453b1e1d73d2875a4bcde73ee +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 ---de0048dbc8bca99bd1ab342049c61f4476f453b1e1d73d2875a4bcde73ee +--998f5d0d0246082bf54bca704425fc986f82ade768328b250c250b4f4d80 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The deleted account belonged to william tables and was deleted by rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---de0048dbc8bca99bd1ab342049c61f4476f453b1e1d73d2875a4bcde73ee +--998f5d0d0246082bf54bca704425fc986f82ade768328b250c250b4f4d80 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ d9314-ad03-4bc8-95d0-5cad491da6b6" style=3D"color: #2563eb; text-decoration= ---de0048dbc8bca99bd1ab342049c61f4476f453b1e1d73d2875a4bcde73ee-- +--998f5d0d0246082bf54bca704425fc986f82ade768328b250c250b4f4d80-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden index 3f50991095816..367ae48f503e4 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: User account "bobby" suspended -Message-Id: ed015d1a-c965-466c-92a0-0e045bf628c4@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:06 +0000 -Content-Type: multipart/alternative; boundary=c2cb4b8b684d58736742e5586bdcdf7eb651bcf544531168cab4c54bfc3c +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 ---c2cb4b8b684d58736742e5586bdcdf7eb651bcf544531168cab4c54bfc3c +--4ba749f14224ba55fa51d3de2422e4de3009d565826840df4bb5772e23a5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ rob. View suspended accounts: http://test.com/deployment/users?filter=3Dstatus%3= Asuspended ---c2cb4b8b684d58736742e5586bdcdf7eb651bcf544531168cab4c54bfc3c +--4ba749f14224ba55fa51d3de2422e4de3009d565826840df4bb5772e23a5 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -82,4 +82,4 @@ ddd82-4733-4d02-a2d7-c36f3598997d" style=3D"color: #2563eb; text-decoration= ---c2cb4b8b684d58736742e5586bdcdf7eb651bcf544531168cab4c54bfc3c-- +--4ba749f14224ba55fa51d3de2422e4de3009d565826840df4bb5772e23a5-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden index 24643c8dc6e1b..0a6682eee302c 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Your One-Time Passcode for Coder. -Message-Id: 6009ee2f-caa3-4737-a45b-f44dae2cc3f1@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:07 +0000 -Content-Type: multipart/alternative; boundary=3153b54208d8ff0152f85b69baff66db80db5ed650a3785e4b5826d9d122 +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 ---3153b54208d8ff0152f85b69baff66db80db5ed650a3785e4b5826d9d122 +--068fc0a963631c8983b970f5db0a87b9351378dbca491477a611d040086d Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ fad9020b-6562-4cdb-87f1-0486f1bea415 If you did not request to reset your password, you can ignore this message. ---3153b54208d8ff0152f85b69baff66db80db5ed650a3785e4b5826d9d122 +--068fc0a963631c8983b970f5db0a87b9351378dbca491477a611d040086d Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -77,4 +77,4 @@ settings

---3153b54208d8ff0152f85b69baff66db80db5ed650a3785e4b5826d9d122-- +--068fc0a963631c8983b970f5db0a87b9351378dbca491477a611d040086d-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden index 81604406132e1..e167fdd744877 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" updated automatically -Message-Id: 9774959e-fb51-4f31-b0ea-0de197a7a388@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:06 +0000 -Content-Type: multipart/alternative; boundary=8cafbf6465dc72be0db427eaf016e3a3be04541d8acf2897e93e07b73d2a +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 ---8cafbf6465dc72be0db427eaf016e3a3be04541d8acf2897e93e07b73d2a +--66418e99f57ea5fc939f0e9d7b462076c7511d055a252d6ea1af01d05965 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ Reason for update: template now includes catnip. View workspace: http://test.com/@bobby/bobby-workspace ---8cafbf6465dc72be0db427eaf016e3a3be04541d8acf2897e93e07b73d2a +--66418e99f57ea5fc939f0e9d7b462076c7511d055a252d6ea1af01d05965 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ a0c09-0704-4cac-bd1c-0c0146811c2b" style=3D"color: #2563eb; text-decoration= ---8cafbf6465dc72be0db427eaf016e3a3be04541d8acf2897e93e07b73d2a-- +--66418e99f57ea5fc939f0e9d7b462076c7511d055a252d6ea1af01d05965-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden index 343e36046982b..5157bee36bc6a 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" autobuild failed -Message-Id: 6305d418-20e5-4dc7-83f1-9d8ad735b6b2@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:06 +0000 -Content-Type: multipart/alternative; boundary=d56d3764d42cbbc7e0ca6b63ac5b20b5dbe48f1f95ec3f5cc9857bf4ef85 +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 ---d56d3764d42cbbc7e0ca6b63ac5b20b5dbe48f1f95ec3f5cc9857bf4ef85 +--715a44de21bb450061035597981181e8ac3262375a751a6a6028843c53f5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The specified reason was "autostart". View workspace: http://test.com/@bobby/bobby-workspace ---d56d3764d42cbbc7e0ca6b63ac5b20b5dbe48f1f95ec3f5cc9857bf4ef85 +--715a44de21bb450061035597981181e8ac3262375a751a6a6028843c53f5 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -79,4 +79,4 @@ df2a9-c0c0-4749-420f-80a9280c66f9" style=3D"color: #2563eb; text-decoration= ---d56d3764d42cbbc7e0ca6b63ac5b20b5dbe48f1f95ec3f5cc9857bf4ef85-- +--715a44de21bb450061035597981181e8ac3262375a751a6a6028843c53f5-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden index cd6e269b4069b..052376f813d02 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace builds failed for template "Bobby First Template" -Message-Id: 5e3a6c97-f422-4f24-a4b7-bc7dd0496201@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:07 +0000 -Content-Type: multipart/alternative; boundary=21e938349974f6fb155498c7ad0fb081c6d264ffb38ca8108d3bf8264d4e +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 ---21e938349974f6fb155498c7ad0fb081c6d264ffb38ca8108d3bf8264d4e +--d7dea7ed44cd783d368dcbdf772d9ea9f370f2da767ff629f7184a2863b2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -36,7 +36,7 @@ We recommend reviewing these issues to ensure future builds are successful. View workspaces: http://test.com/workspaces?filter=3Dtemplate%3Abobby-first= -template ---21e938349974f6fb155498c7ad0fb081c6d264ffb38ca8108d3bf8264d4e +--d7dea7ed44cd783d368dcbdf772d9ea9f370f2da767ff629f7184a2863b2 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -123,4 +123,4 @@ settings

---21e938349974f6fb155498c7ad0fb081c6d264ffb38ca8108d3bf8264d4e-- +--d7dea7ed44cd783d368dcbdf772d9ea9f370f2da767ff629f7184a2863b2-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden index 9798b1a37cda1..58f5b9970fd09 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" deleted -Message-Id: aa79c7ce-c406-4133-9454-8de5386e3fa2@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:07 +0000 -Content-Type: multipart/alternative; boundary=a5c60a371038ba0928462f9ecb9941040823dee28a4cafcbaecc23628b3f +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 ---a5c60a371038ba0928462f9ecb9941040823dee28a4cafcbaecc23628b3f +--fcea2c9aa7fac008c94a71712284022745e09cc7d7243ed564b03fa9182f Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ View workspaces: http://test.com/workspaces View templates: http://test.com/templates ---a5c60a371038ba0928462f9ecb9941040823dee28a4cafcbaecc23628b3f +--fcea2c9aa7fac008c94a71712284022745e09cc7d7243ed564b03fa9182f Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -87,4 +87,4 @@ settings

---a5c60a371038ba0928462f9ecb9941040823dee28a4cafcbaecc23628b3f-- +--fcea2c9aa7fac008c94a71712284022745e09cc7d7243ed564b03fa9182f-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden index 4db7fc7a50b48..6b8bdde1f5329 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" marked as dormant -Message-Id: 034ab939-ef9f-4d40-b356-9a3fe50fa43a@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:06 +0000 -Content-Type: multipart/alternative; boundary=0ddb9c71df3785fb8bf571c38008ccf50a655b2572464aaba406d6b9b5d2 +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 ---0ddb9c71df3785fb8bf571c38008ccf50a655b2572464aaba406d6b9b5d2 +--f50cfd8467c183909c83829e40866199dd75521170ab78a589d2997c1a3f Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -23,7 +23,7 @@ To prevent deletion, use your workspace with the link below. View workspace: http://test.com/@bobby/bobby-workspace ---0ddb9c71df3785fb8bf571c38008ccf50a655b2572464aaba406d6b9b5d2 +--f50cfd8467c183909c83829e40866199dd75521170ab78a589d2997c1a3f Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -87,4 +87,4 @@ settings

---0ddb9c71df3785fb8bf571c38008ccf50a655b2572464aaba406d6b9b5d2-- +--f50cfd8467c183909c83829e40866199dd75521170ab78a589d2997c1a3f-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden index 62698a8e96755..55c4fc120ad61 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" manual build failed -Message-Id: 9e1a8c51-ba7a-476a-8841-78c5311113c7@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:06 +0000 -Content-Type: multipart/alternative; boundary=aa5483a898ac4c112833763b8a7f0434ae1a507d213a3f0fb105b638d517 +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 ---aa5483a898ac4c112833763b8a7f0434ae1a507d213a3f0fb105b638d517 +--dbf85892c2e844136150393b08284629ffe02296ae5af159433eeab0d892 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ The template's display name was William's Template. The workspace build was= View build: http://test.com/@mrbobby/bobby-workspace/builds/3 ---aa5483a898ac4c112833763b8a7f0434ae1a507d213a3f0fb105b638d517 +--dbf85892c2e844136150393b08284629ffe02296ae5af159433eeab0d892 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -83,4 +83,4 @@ eee0f-26cb-4e96-821c-85ccb9f71513" style=3D"color: #2563eb; text-decoration= ---aa5483a898ac4c112833763b8a7f0434ae1a507d213a3f0fb105b638d517-- +--dbf85892c2e844136150393b08284629ffe02296ae5af159433eeab0d892-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden index 4a30d26e5b07f..ac89654c979cd 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Workspace "bobby-workspace" marked for deletion -Message-Id: 24d9a559-ab86-41ce-89b4-281b0815f95e@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:06 +0000 -Content-Type: multipart/alternative; boundary=2d0f93482ad27ef16601523ee4474bd3e1d9dfc889a02e7c3e41eab2524b +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 ---2d0f93482ad27ef16601523ee4474bd3e1d9dfc889a02e7c3e41eab2524b +--80423a728797d414bf90c4779b6ba7c2a4ee3d4cf1c18a7abe9c40021c10 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ To prevent deletion, use your workspace with the link below. View workspace: http://test.com/@bobby/bobby-workspace ---2d0f93482ad27ef16601523ee4474bd3e1d9dfc889a02e7c3e41eab2524b +--80423a728797d414bf90c4779b6ba7c2a4ee3d4cf1c18a7abe9c40021c10 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -81,4 +81,4 @@ e2fdf-c9ca-4be1-8d70-628674f9bc42" style=3D"color: #2563eb; text-decoration= ---2d0f93482ad27ef16601523ee4474bd3e1d9dfc889a02e7c3e41eab2524b-- +--80423a728797d414bf90c4779b6ba7c2a4ee3d4cf1c18a7abe9c40021c10-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden index 153570eb57f9f..74285ba088d64 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Your account "bobby" has been activated -Message-Id: 9ec28fa4-e75c-4b32-a1ac-9622fa7212cf@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:06 +0000 -Content-Type: multipart/alternative; boundary=1b77880f5aa13bedc165ced8e5b766fb55b5490b2b2a9ef3233081821878 +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 ---1b77880f5aa13bedc165ced8e5b766fb55b5490b2b2a9ef3233081821878 +--ee29141f0e810ffae5cfb3e9238a272350b29db90d1624a8136ef9017bbe Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -17,7 +17,7 @@ Your account bobby has been activated by rob. Open Coder: http://test.com ---1b77880f5aa13bedc165ced8e5b766fb55b5490b2b2a9ef3233081821878 +--ee29141f0e810ffae5cfb3e9238a272350b29db90d1624a8136ef9017bbe Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -75,4 +75,4 @@ a6bea-ee0a-43e2-9e7c-eabdb53730e4" style=3D"color: #2563eb; text-decoration= ---1b77880f5aa13bedc165ced8e5b766fb55b5490b2b2a9ef3233081821878-- +--ee29141f0e810ffae5cfb3e9238a272350b29db90d1624a8136ef9017bbe-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden index 9836bbb5cd702..889a3bd9d7457 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden @@ -1,12 +1,12 @@ From: system@coder.com To: bobby@coder.com Subject: Your account "bobby" has been suspended -Message-Id: 2a4061e2-3049-477f-80c8-e67323a395cf@blush-whale-48 -Date: Fri, 11 Oct 2024 09:03:08 +0000 -Content-Type: multipart/alternative; boundary=60ded561f65e41fefc3a22e0b5d5ed3e9e6cb08eca49aa6dc740f1bffb92 +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 ---60ded561f65e41fefc3a22e0b5d5ed3e9e6cb08eca49aa6dc740f1bffb92 +--6faccf8327c6c4402edd0ee758592d9ebe71250a114362f1c2d9d45d9f99 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -15,7 +15,7 @@ Hi Bobby, Your account bobby has been suspended by rob. ---60ded561f65e41fefc3a22e0b5d5ed3e9e6cb08eca49aa6dc740f1bffb92 +--6faccf8327c6c4402edd0ee758592d9ebe71250a114362f1c2d9d45d9f99 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -67,4 +67,4 @@ f0609-9b69-4d36-a989-9f5925b6cbff" style=3D"color: #2563eb; text-decoration= ---60ded561f65e41fefc3a22e0b5d5ed3e9e6cb08eca49aa6dc740f1bffb92-- +--6faccf8327c6c4402edd0ee758592d9ebe71250a114362f1c2d9d45d9f99-- diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.json.golden index 686c46a28c7d6..4a97b3a14f866 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateTemplateDeleted.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "8400889e-b369-4237-ad18-809d82e778fd", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "Template Deleted", - "notification_template_id": "29a09665-2a4c-403f-9648-54301670e7be", - "user_id": "37a2f3a5-ce78-4da7-8ee4-0a985ce5dad1", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden index 5f04757910824..bb2c26a91a2ac 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "64d6e886-c75d-474c-b0cc-a0c2ee7d7b9f", + "msg_id": "a059b846-92c0-41dc-a64a-832f0035ecd3", "payload": { "_version": "1.1", "notification_name": "User account activated", "notification_template_id": "9f5af851-8408-4e73-a7a1-c6502ba46689", - "user_id": "0c91b12d-2732-4122-abe3-cee2bf64f1c2", + "user_id": "e0a02b9f-3d4f-4f62-b4b3-cfaf2177d651", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden index e5e2894c75717..6425496bf1cff 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "ed1515ce-1458-4901-a924-4a62933525f5", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "User account created", - "notification_template_id": "4e19c0ac-94e1-4532-9515-d1801aa283b2", - "user_id": "68bd9314-7226-4dc0-a4e7-166904706195", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden index 7ee7f01c40716..96a572d3c3f89 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "c8465b51-0d63-404c-b03f-f10b79cf8a5d", + "msg_id": "3f997656-aef7-4f1f-bf4c-b77896ad0fa1", "payload": { "_version": "1.1", "notification_name": "User account deleted", "notification_template_id": "f44d9314-ad03-4bc8-95d0-5cad491da6b6", - "user_id": "c21d5acf-5e23-4843-80e0-e21409d31800", + "user_id": "0308cdf5-a046-43bb-9e87-8a5053e53eb7", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden index ad6c47238fa04..2d9a8fc2dc234 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "2c313281-0c86-46ac-9867-43fab07affce", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "User account suspended", - "notification_template_id": "b02ddd82-4733-4d02-a2d7-c36f3598997d", - "user_id": "7c41c766-5f78-4b2b-b294-cae6918f4dfc", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden index 88b42a771dc7b..917904a2495aa 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutoUpdated.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "0d2a1c10-6000-4e5d-9caa-2951fbc1b63d", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "Workspace Updated Automatically", - "notification_template_id": "c34a0c09-0704-4cac-bd1c-0c0146811c2b", - "user_id": "4fe26e16-c23c-40db-9649-612ed02c531a", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutobuildFailed.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutobuildFailed.json.golden new file mode 100644 index 0000000000000..45b64a31a0adb --- /dev/null +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceAutobuildFailed.json.golden @@ -0,0 +1,28 @@ +{ + "_version": "1.1", + "msg_id": "00000000-0000-0000-0000-000000000000", + "payload": { + "_version": "1.1", + "notification_name": "Workspace Autobuild Failed", + "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", + "reason": "autostart" + }, + "data": null + }, + "title": "Workspace \"bobby-workspace\" autobuild failed", + "title_markdown": "Workspace \"bobby-workspace\" autobuild failed", + "body": "Hi Bobby,\n\nAutomatic build of your workspace bobby-workspace failed.\n\nThe specified reason was \"autostart\".", + "body_markdown": "Hi Bobby,\n\nAutomatic build of your workspace **bobby-workspace** failed.\n\nThe specified reason was \"**autostart**\"." +} \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden index 8560d69100507..df5fa6d039e91 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "d0566fff-9315-4e91-a055-28b7158b7ec9", + "msg_id": "9931e7fb-d410-45f4-9f59-0260d3c1f0ac", "payload": { "_version": "1.1", "notification_name": "Report: Workspace Builds Failed For Template", "notification_template_id": "34a20db2-e9cc-4a93-b0e4-8569699d7a00", - "user_id": "e28bc1f4-836b-41ae-a3e3-19a3c2050ac3", + "user_id": "5ca12b9f-6505-49aa-899a-5c07fc3871e8", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden index 10ba2f4fe6158..171e893dd943f 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDeleted.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "f14e06d6-0798-4027-9b05-a1c818a02099", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "Workspace Deleted", - "notification_template_id": "f517da0b-cdc9-410f-ab89-a86107c420ed", - "user_id": "78daa6f4-11d6-4d81-a8d4-87a335730c08", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden index d881d37bf2dae..00c591d9d15d3 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceDormant.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "0203cfea-c559-4e29-a0ca-b88218df57ef", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "Workspace Marked as Dormant", - "notification_template_id": "0ea69165-ec14-4314-91f1-69566ac3c5a0", - "user_id": "428dd40d-3f51-4e1a-8a28-5d2e6fe8f323", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden index 4ee301aebc5a8..8fe2b8b86fd03 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManualBuildFailed.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "bd14c03f-fc48-4ca1-9b46-9201e732e657", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "Workspace Manual Build Failed", - "notification_template_id": "2faeee0f-26cb-4e96-821c-85ccb9f71513", - "user_id": "5c34a281-2fda-4064-ac0a-88979c2c5bd2", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden index f1505ce77d95c..e80cdde92cf2a 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "5fe52634-c753-489c-8ba2-e31075fa0122", + "msg_id": "dd7df2e0-deb1-461d-9b0a-f8219179c6ae", "payload": { "_version": "1.1", "notification_name": "Workspace Marked for Deletion", "notification_template_id": "51ce2fdf-c9ca-4be1-8d70-628674f9bc42", - "user_id": "a0a91a17-a760-4da4-b471-ecbf193b323f", + "user_id": "cece1f51-badc-4f7f-a440-5896d4b352df", "user_email": "bobby@coder.com", "user_name": "Bobby", "user_username": "bobby", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden index 76d901c50f0b1..333964aa57799 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "a7084e57-fd18-4bb8-9320-63060592f7aa", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "Your account has been activated", - "notification_template_id": "1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4", - "user_id": "7b7cc6a1-29d5-4d5e-8b33-3810346885fe", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden index 47a674b07e3e0..768f9839126ea 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "6c60d9dc-36b2-4f93-a19d-4e7308820ede", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "Your account has been suspended", - "notification_template_id": "6a2f0609-9b69-4d36-a989-9f5925b6cbff", - "user_id": "c97b703e-203e-4db4-ad18-29136f6ffb80", + "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", From 7ab16646f4ecb1813213c9b091989e2967134bc5 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 09:42:36 +0000 Subject: [PATCH 30/44] chore(coderd/notifications): ensure that all rendered golden files are idempotent --- coderd/notifications/notifications_test.go | 9 +++++---- .../smtp/TemplateTemplateDeleted.html.golden | 6 +++--- .../smtp/TemplateUserAccountActivated.html.golden | 6 +++--- .../smtp/TemplateUserAccountCreated.html.golden | 6 +++--- .../smtp/TemplateUserAccountDeleted.html.golden | 6 +++--- .../smtp/TemplateUserAccountSuspended.html.golden | 6 +++--- .../TemplateUserRequestedOneTimePasscode.html.golden | 6 +++--- .../smtp/TemplateWorkspaceAutoUpdated.html.golden | 6 +++--- .../TemplateWorkspaceAutobuildFailed.html.golden | 6 +++--- .../TemplateWorkspaceBuildsFailedReport.html.golden | 6 +++--- .../smtp/TemplateWorkspaceDeleted.html.golden | 6 +++--- .../smtp/TemplateWorkspaceDormant.html.golden | 6 +++--- .../TemplateWorkspaceManualBuildFailed.html.golden | 6 +++--- .../TemplateWorkspaceMarkedForDeletion.html.golden | 6 +++--- .../smtp/TemplateYourAccountActivated.html.golden | 6 +++--- .../smtp/TemplateYourAccountSuspended.html.golden | 6 +++--- .../webhook/TemplateUserAccountActivated.json.golden | 6 +++--- .../webhook/TemplateUserAccountDeleted.json.golden | 6 +++--- .../TemplateUserRequestedOneTimePasscode.json.golden | 12 ++++++------ .../TemplateWorkspaceBuildsFailedReport.json.golden | 6 +++--- .../TemplateWorkspaceMarkedForDeletion.json.golden | 6 +++--- 21 files changed, 68 insertions(+), 67 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 640cd71c1eaa0..0b61090067bcc 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -1115,7 +1115,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { }, testutil.WaitShort, testutil.IntervalFast) require.NotNil(t, msg, "want a message to be sent") - body := constantifyGoldenEmail([]byte(msg.Contents)) + body := normalizeGoldenEmail([]byte(msg.Contents)) err = smtpManager.Stop(ctx) require.NoError(t, err) @@ -1216,7 +1216,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { } } -func constantifyGoldenEmail(content []byte) []byte { +func normalizeGoldenEmail(content []byte) []byte { const ( constantDate = "Fri, 11 Oct 2024 09:03:06 +0000" constantMessageID = "02ee4935-73be-4fa1-a290-ff9999026b13@blush-whale-48" @@ -1225,11 +1225,12 @@ func constantifyGoldenEmail(content []byte) []byte { dateRegex := regexp.MustCompile(`Date: .+`) messageIDRegex := regexp.MustCompile(`Message-Id: .+`) - boundaryRegex := regexp.MustCompile(`boundary=.+`) + boundaryRegex := regexp.MustCompile(`boundary=(.+)`) + boundary := boundaryRegex.FindSubmatch(content)[1] content = dateRegex.ReplaceAll(content, []byte("Date: "+constantDate)) content = messageIDRegex.ReplaceAll(content, []byte("Message-Id: "+constantMessageID)) - content = boundaryRegex.ReplaceAll(content, []byte("boundary="+constantBoundary)) + content = bytes.ReplaceAll(content, boundary, []byte(constantBoundary)) return content } diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden index d7c014ded539b..7c8eb24639d46 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---52a54cf75286afea52caccee3f80d8009b149fa636540750ccc6c23b560a +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The template's display name was Bobby's Template. View templates: http://test.com/templates ---52a54cf75286afea52caccee3f80d8009b149fa636540750ccc6c23b560a +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ settings

---52a54cf75286afea52caccee3f80d8009b149fa636540750ccc6c23b560a-- +--e5a27fd0f641bfa8f48c14e3eb3d5c38dc378a451883c00640eed63e34ad-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden index cf8430583271e..19d1558f6e68c 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---a67aa67e0f976132dec706b08d966add4d34d5f7ef3ccdf0fd1bc3bf80ec +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---a67aa67e0f976132dec706b08d966add4d34d5f7ef3ccdf0fd1bc3bf80ec +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -81,4 +81,4 @@ af851-8408-4e73-a7a1-c6502ba46689" style=3D"color: #2563eb; text-decoration= ---a67aa67e0f976132dec706b08d966add4d34d5f7ef3ccdf0fd1bc3bf80ec-- +--125fcaffaa7a815194a8b41947a37fbb9e9174811f8aff561f5190871663-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden index 599df0788764e..cfa13dbe65633 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---66ddaa699eb126a27ee6a1bbac51e14ebcbe56e91f3eeddfa67ad5285f1d +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ This new user account was created for William Tables by rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---66ddaa699eb126a27ee6a1bbac51e14ebcbe56e91f3eeddfa67ad5285f1d +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ settings

---66ddaa699eb126a27ee6a1bbac51e14ebcbe56e91f3eeddfa67ad5285f1d-- +--9ebb7a4f4681f63b596c6b4e669ae92c6fc4763e0495ecc9d74dfe2920a8-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden index f061464c69f70..b441bb26146b9 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---998f5d0d0246082bf54bca704425fc986f82ade768328b250c250b4f4d80 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The deleted account belonged to william tables and was deleted by rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---998f5d0d0246082bf54bca704425fc986f82ade768328b250c250b4f4d80 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ d9314-ad03-4bc8-95d0-5cad491da6b6" style=3D"color: #2563eb; text-decoration= ---998f5d0d0246082bf54bca704425fc986f82ade768328b250c250b4f4d80-- +--69633b22afbe4db1452725e20c8187c395809819969e96bd6de1db335ece-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden index 367ae48f503e4..54dd98e57c215 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---4ba749f14224ba55fa51d3de2422e4de3009d565826840df4bb5772e23a5 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ rob. View suspended accounts: http://test.com/deployment/users?filter=3Dstatus%3= Asuspended ---4ba749f14224ba55fa51d3de2422e4de3009d565826840df4bb5772e23a5 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -82,4 +82,4 @@ ddd82-4733-4d02-a2d7-c36f3598997d" style=3D"color: #2563eb; text-decoration= ---4ba749f14224ba55fa51d3de2422e4de3009d565826840df4bb5772e23a5-- +--9caa82c934b0a330ac53c78ad8b3a3411d7d3c41e7181999aaf68a06d20e-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden index 0a6682eee302c..0bf4d0b264730 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---068fc0a963631c8983b970f5db0a87b9351378dbca491477a611d040086d +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ fad9020b-6562-4cdb-87f1-0486f1bea415 If you did not request to reset your password, you can ignore this message. ---068fc0a963631c8983b970f5db0a87b9351378dbca491477a611d040086d +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -77,4 +77,4 @@ settings

---068fc0a963631c8983b970f5db0a87b9351378dbca491477a611d040086d-- +--7ed04fd01fc924ab470298c6ba6188f5e9035fc3eb774e3fd339d36c4dc4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden index e167fdd744877..2cdc40a337523 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---66418e99f57ea5fc939f0e9d7b462076c7511d055a252d6ea1af01d05965 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ Reason for update: template now includes catnip. View workspace: http://test.com/@bobby/bobby-workspace ---66418e99f57ea5fc939f0e9d7b462076c7511d055a252d6ea1af01d05965 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ a0c09-0704-4cac-bd1c-0c0146811c2b" style=3D"color: #2563eb; text-decoration= ---66418e99f57ea5fc939f0e9d7b462076c7511d055a252d6ea1af01d05965-- +--d1f28b4266f2ea85551415e024fca1c38694a6831501d8830875ad975e8a-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden index 5157bee36bc6a..496c85ea2cab2 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---715a44de21bb450061035597981181e8ac3262375a751a6a6028843c53f5 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The specified reason was "autostart". View workspace: http://test.com/@bobby/bobby-workspace ---715a44de21bb450061035597981181e8ac3262375a751a6a6028843c53f5 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -79,4 +79,4 @@ df2a9-c0c0-4749-420f-80a9280c66f9" style=3D"color: #2563eb; text-decoration= ---715a44de21bb450061035597981181e8ac3262375a751a6a6028843c53f5-- +--1ddc9ed5515d31aca71cb6ca481dce7b297c99004328bd84668bb8721c8c-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden index 052376f813d02..a20b84e9eb6c9 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---d7dea7ed44cd783d368dcbdf772d9ea9f370f2da767ff629f7184a2863b2 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -36,7 +36,7 @@ We recommend reviewing these issues to ensure future builds are successful. View workspaces: http://test.com/workspaces?filter=3Dtemplate%3Abobby-first= -template ---d7dea7ed44cd783d368dcbdf772d9ea9f370f2da767ff629f7184a2863b2 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -123,4 +123,4 @@ settings

---d7dea7ed44cd783d368dcbdf772d9ea9f370f2da767ff629f7184a2863b2-- +--b8d91de6b3f8b1d36fc61ab2437bd8db9a7e587492a42a12d8e912684846-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden index 58f5b9970fd09..9a708ffa6bb72 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---fcea2c9aa7fac008c94a71712284022745e09cc7d7243ed564b03fa9182f +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ View workspaces: http://test.com/workspaces View templates: http://test.com/templates ---fcea2c9aa7fac008c94a71712284022745e09cc7d7243ed564b03fa9182f +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -87,4 +87,4 @@ settings

---fcea2c9aa7fac008c94a71712284022745e09cc7d7243ed564b03fa9182f-- +--a351ac59bf3516b291c349f148cf3c9080070ff8299496dccbfd4d5ad743-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden index 6b8bdde1f5329..4960712d20916 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---f50cfd8467c183909c83829e40866199dd75521170ab78a589d2997c1a3f +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -23,7 +23,7 @@ To prevent deletion, use your workspace with the link below. View workspace: http://test.com/@bobby/bobby-workspace ---f50cfd8467c183909c83829e40866199dd75521170ab78a589d2997c1a3f +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -87,4 +87,4 @@ settings

---f50cfd8467c183909c83829e40866199dd75521170ab78a589d2997c1a3f-- +--0d857ed2f89760f121d91688b38e543d8932aa89442ad23fe0da9c01c936-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden index 55c4fc120ad61..7e36e1bb5f72d 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---dbf85892c2e844136150393b08284629ffe02296ae5af159433eeab0d892 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ The template's display name was William's Template. The workspace build was= View build: http://test.com/@mrbobby/bobby-workspace/builds/3 ---dbf85892c2e844136150393b08284629ffe02296ae5af159433eeab0d892 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -83,4 +83,4 @@ eee0f-26cb-4e96-821c-85ccb9f71513" style=3D"color: #2563eb; text-decoration= ---dbf85892c2e844136150393b08284629ffe02296ae5af159433eeab0d892-- +--c5454084fc2a92215bf9a4fe7dde7700b6b7decd47e8eacbb4a32a3629dc-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden index ac89654c979cd..f8cef915e666a 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---80423a728797d414bf90c4779b6ba7c2a4ee3d4cf1c18a7abe9c40021c10 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ To prevent deletion, use your workspace with the link below. View workspace: http://test.com/@bobby/bobby-workspace ---80423a728797d414bf90c4779b6ba7c2a4ee3d4cf1c18a7abe9c40021c10 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -81,4 +81,4 @@ e2fdf-c9ca-4be1-8d70-628674f9bc42" style=3D"color: #2563eb; text-decoration= ---80423a728797d414bf90c4779b6ba7c2a4ee3d4cf1c18a7abe9c40021c10-- +--39975012df383d4aa0ff8ee7cf2a840d57e36d4cdf3d2a3551c7b9cdfc99-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden index 74285ba088d64..6591d9cf5dc53 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---ee29141f0e810ffae5cfb3e9238a272350b29db90d1624a8136ef9017bbe +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -17,7 +17,7 @@ Your account bobby has been activated by rob. Open Coder: http://test.com ---ee29141f0e810ffae5cfb3e9238a272350b29db90d1624a8136ef9017bbe +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -75,4 +75,4 @@ a6bea-ee0a-43e2-9e7c-eabdb53730e4" style=3D"color: #2563eb; text-decoration= ---ee29141f0e810ffae5cfb3e9238a272350b29db90d1624a8136ef9017bbe-- +--7b52fa32f187a77847c0b7dcadecc42881a3d6033289856c80d46b27c295-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden index 889a3bd9d7457..efb903263d981 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden @@ -6,7 +6,7 @@ Date: Fri, 11 Oct 2024 09:03:06 +0000 Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---6faccf8327c6c4402edd0ee758592d9ebe71250a114362f1c2d9d45d9f99 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -15,7 +15,7 @@ Hi Bobby, Your account bobby has been suspended by rob. ---6faccf8327c6c4402edd0ee758592d9ebe71250a114362f1c2d9d45d9f99 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -67,4 +67,4 @@ f0609-9b69-4d36-a989-9f5925b6cbff" style=3D"color: #2563eb; text-decoration= ---6faccf8327c6c4402edd0ee758592d9ebe71250a114362f1c2d9d45d9f99-- +--966b59c3ffdd1ddd7153b1bd8a93c26fea01112c60e1690555a60d419428-- diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden index bb2c26a91a2ac..847935aa904af 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "a059b846-92c0-41dc-a64a-832f0035ecd3", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "User account activated", - "notification_template_id": "9f5af851-8408-4e73-a7a1-c6502ba46689", - "user_id": "e0a02b9f-3d4f-4f62-b4b3-cfaf2177d651", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden index 96a572d3c3f89..6fa6379c812c2 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "3f997656-aef7-4f1f-bf4c-b77896ad0fa1", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "User account deleted", - "notification_template_id": "f44d9314-ad03-4bc8-95d0-5cad491da6b6", - "user_id": "0308cdf5-a046-43bb-9e87-8a5053e53eb7", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden index 5f3913cc3698d..2c03fc7c71905 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserRequestedOneTimePasscode.json.golden @@ -1,22 +1,22 @@ { "_version": "1.1", - "msg_id": "73c92921-b640-4ca0-8fae-c3d44b9886db", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "One-Time Passcode", - "notification_template_id": "62f86a30-2330-4b61-a26d-311ff3b608cf", - "user_id": "3b8e4ed5-10c0-40dd-87c3-b931c575adb9", + "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": [], "labels": { - "one_time_passcode": "fad9020b-6562-4cdb-87f1-0486f1bea415" + "one_time_passcode": "00000000-0000-0000-0000-000000000000" }, "data": null }, "title": "Your One-Time Passcode for Coder.", "title_markdown": "Your One-Time Passcode for Coder.", - "body": "Hi Bobby,\n\nA request to reset the password for your Coder account has been made. Your one-time passcode is:\n\nfad9020b-6562-4cdb-87f1-0486f1bea415\n\nIf you did not request to reset your password, you can ignore this message.", - "body_markdown": "Hi Bobby,\n\nA request to reset the password for your Coder account has been made. Your one-time passcode is:\n\n**fad9020b-6562-4cdb-87f1-0486f1bea415**\n\nIf you did not request to reset your password, you can ignore this message." + "body": "Hi Bobby,\n\nA request to reset the password for your Coder account has been made. Your one-time passcode is:\n\n00000000-0000-0000-0000-000000000000\n\nIf you did not request to reset your password, you can ignore this message.", + "body_markdown": "Hi Bobby,\n\nA request to reset the password for your Coder account has been made. Your one-time passcode is:\n\n**00000000-0000-0000-0000-000000000000**\n\nIf you did not request to reset your password, you can ignore this message." } \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden index df5fa6d039e91..c6dabbfb89d80 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceBuildsFailedReport.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "9931e7fb-d410-45f4-9f59-0260d3c1f0ac", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "Report: Workspace Builds Failed For Template", - "notification_template_id": "34a20db2-e9cc-4a93-b0e4-8569699d7a00", - "user_id": "5ca12b9f-6505-49aa-899a-5c07fc3871e8", + "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", diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden index e80cdde92cf2a..3cb1690b0b583 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceMarkedForDeletion.json.golden @@ -1,11 +1,11 @@ { "_version": "1.1", - "msg_id": "dd7df2e0-deb1-461d-9b0a-f8219179c6ae", + "msg_id": "00000000-0000-0000-0000-000000000000", "payload": { "_version": "1.1", "notification_name": "Workspace Marked for Deletion", - "notification_template_id": "51ce2fdf-c9ca-4be1-8d70-628674f9bc42", - "user_id": "cece1f51-badc-4f7f-a440-5896d4b352df", + "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", From 8f3ed160e4716ab45fe700571ed201c2f80d89a9 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 10:20:41 +0000 Subject: [PATCH 31/44] chore(coderd/notifications): ensure that all rendered golden files are idempotent --- coderd/notifications/notifications_test.go | 4 ++-- .../smtp/TemplateTemplateDeleted.html.golden | 8 ++++---- .../smtp/TemplateUserAccountActivated.html.golden | 8 ++++---- .../smtp/TemplateUserAccountCreated.html.golden | 8 ++++---- .../smtp/TemplateUserAccountDeleted.html.golden | 8 ++++---- .../smtp/TemplateUserAccountSuspended.html.golden | 8 ++++---- .../smtp/TemplateUserRequestedOneTimePasscode.html.golden | 8 ++++---- .../smtp/TemplateWorkspaceAutoUpdated.html.golden | 8 ++++---- .../smtp/TemplateWorkspaceAutobuildFailed.html.golden | 8 ++++---- .../smtp/TemplateWorkspaceBuildsFailedReport.html.golden | 8 ++++---- .../smtp/TemplateWorkspaceDeleted.html.golden | 8 ++++---- .../smtp/TemplateWorkspaceDormant.html.golden | 8 ++++---- .../smtp/TemplateWorkspaceManualBuildFailed.html.golden | 8 ++++---- .../smtp/TemplateWorkspaceMarkedForDeletion.html.golden | 8 ++++---- .../smtp/TemplateYourAccountActivated.html.golden | 8 ++++---- .../smtp/TemplateYourAccountSuspended.html.golden | 8 ++++---- 16 files changed, 62 insertions(+), 62 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 0b61090067bcc..b16764ffcd924 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -1125,7 +1125,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { if *updateGoldenFiles { err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) require.NoError(t, err, "want no error creating golden file directory") - err = os.WriteFile(goldenFile, body, 0o600) + err = os.WriteFile(goldenFile, []byte(body), 0o600) require.NoError(t, err, "want no error writing body golden file") return } @@ -1225,7 +1225,7 @@ func normalizeGoldenEmail(content []byte) []byte { dateRegex := regexp.MustCompile(`Date: .+`) messageIDRegex := regexp.MustCompile(`Message-Id: .+`) - boundaryRegex := regexp.MustCompile(`boundary=(.+)`) + boundaryRegex := regexp.MustCompile(`boundary=([0-9a-zA-Z]+)`) boundary := boundaryRegex.FindSubmatch(content)[1] content = dateRegex.ReplaceAll(content, []byte("Date: "+constantDate)) diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden index 7c8eb24639d46..ec7c3cfdce485 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateTemplateDeleted.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: Template "bobby-template" deleted 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The template's display name was Bobby's Template. View templates: http://test.com/templates ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ settings

---e5a27fd0f641bfa8f48c14e3eb3d5c38dc378a451883c00640eed63e34ad-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden index 19d1558f6e68c..218f0958bafec 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: User account "bobby" activated 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -81,4 +81,4 @@ af851-8408-4e73-a7a1-c6502ba46689" style=3D"color: #2563eb; text-decoration= ---125fcaffaa7a815194a8b41947a37fbb9e9174811f8aff561f5190871663-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden index cfa13dbe65633..9a6cab0989897 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountCreated.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: User account "bobby" created 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ This new user account was created for William Tables by rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ settings

---9ebb7a4f4681f63b596c6b4e669ae92c6fc4763e0495ecc9d74dfe2920a8-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden index b441bb26146b9..d0f1144f66cf3 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: User account "bobby" deleted 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The deleted account belonged to william tables and was deleted by rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ d9314-ad03-4bc8-95d0-5cad491da6b6" style=3D"color: #2563eb; text-decoration= ---69633b22afbe4db1452725e20c8187c395809819969e96bd6de1db335ece-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden index 54dd98e57c215..4323583c2ec5c 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: User account "bobby" suspended 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ rob. View suspended accounts: http://test.com/deployment/users?filter=3Dstatus%3= Asuspended ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -82,4 +82,4 @@ ddd82-4733-4d02-a2d7-c36f3598997d" style=3D"color: #2563eb; text-decoration= ---9caa82c934b0a330ac53c78ad8b3a3411d7d3c41e7181999aaf68a06d20e-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden index 0bf4d0b264730..2b61765813bcf 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserRequestedOneTimePasscode.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: Your One-Time Passcode for Coder. 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ fad9020b-6562-4cdb-87f1-0486f1bea415 If you did not request to reset your password, you can ignore this message. ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -77,4 +77,4 @@ settings

---7ed04fd01fc924ab470298c6ba6188f5e9035fc3eb774e3fd339d36c4dc4-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden index 2cdc40a337523..6c68cffa8bc1b 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutoUpdated.html.golden @@ -3,10 +3,10 @@ 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ Reason for update: template now includes catnip. View workspace: http://test.com/@bobby/bobby-workspace ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -80,4 +80,4 @@ a0c09-0704-4cac-bd1c-0c0146811c2b" style=3D"color: #2563eb; text-decoration= ---d1f28b4266f2ea85551415e024fca1c38694a6831501d8830875ad975e8a-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden index 496c85ea2cab2..340e794f15c74 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceAutobuildFailed.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: Workspace "bobby-workspace" autobuild failed 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -19,7 +19,7 @@ The specified reason was "autostart". View workspace: http://test.com/@bobby/bobby-workspace ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -79,4 +79,4 @@ df2a9-c0c0-4749-420f-80a9280c66f9" style=3D"color: #2563eb; text-decoration= ---1ddc9ed5515d31aca71cb6ca481dce7b297c99004328bd84668bb8721c8c-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden index a20b84e9eb6c9..7cc16f00f3796 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceBuildsFailedReport.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: Workspace builds failed for template "Bobby First Template" 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -36,7 +36,7 @@ We recommend reviewing these issues to ensure future builds are successful. View workspaces: http://test.com/workspaces?filter=3Dtemplate%3Abobby-first= -template ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -123,4 +123,4 @@ settings

---b8d91de6b3f8b1d36fc61ab2437bd8db9a7e587492a42a12d8e912684846-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden index 9a708ffa6bb72..0d821bdc4dacd 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDeleted.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: Workspace "bobby-workspace" deleted 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ View workspaces: http://test.com/workspaces View templates: http://test.com/templates ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -87,4 +87,4 @@ settings

---a351ac59bf3516b291c349f148cf3c9080070ff8299496dccbfd4d5ad743-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden index 4960712d20916..0c6cbf5a2dd85 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceDormant.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: Workspace "bobby-workspace" marked as dormant 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -23,7 +23,7 @@ To prevent deletion, use your workspace with the link below. View workspace: http://test.com/@bobby/bobby-workspace ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -87,4 +87,4 @@ settings

---0d857ed2f89760f121d91688b38e543d8932aa89442ad23fe0da9c01c936-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden index 7e36e1bb5f72d..a1711b70eae85 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManualBuildFailed.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: Workspace "bobby-workspace" manual build failed 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -21,7 +21,7 @@ The template's display name was William's Template. The workspace build was= View build: http://test.com/@mrbobby/bobby-workspace/builds/3 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -83,4 +83,4 @@ eee0f-26cb-4e96-821c-85ccb9f71513" style=3D"color: #2563eb; text-decoration= ---c5454084fc2a92215bf9a4fe7dde7700b6b7decd47e8eacbb4a32a3629dc-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden index f8cef915e666a..6d91458f2cbcc 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceMarkedForDeletion.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: Workspace "bobby-workspace" marked for deletion 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -20,7 +20,7 @@ To prevent deletion, use your workspace with the link below. View workspace: http://test.com/@bobby/bobby-workspace ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -81,4 +81,4 @@ e2fdf-c9ca-4be1-8d70-628674f9bc42" style=3D"color: #2563eb; text-decoration= ---39975012df383d4aa0ff8ee7cf2a840d57e36d4cdf3d2a3551c7b9cdfc99-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden index 6591d9cf5dc53..aef12ab957feb 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountActivated.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: Your account "bobby" has been activated 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -17,7 +17,7 @@ Your account bobby has been activated by rob. Open Coder: http://test.com ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -75,4 +75,4 @@ a6bea-ee0a-43e2-9e7c-eabdb53730e4" style=3D"color: #2563eb; text-decoration= ---7b52fa32f187a77847c0b7dcadecc42881a3d6033289856c80d46b27c295-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden index efb903263d981..d9406e2c1f344 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateYourAccountSuspended.html.golden @@ -3,10 +3,10 @@ To: bobby@coder.com Subject: Your account "bobby" has been suspended 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 +Content-Type: multipart/alternative; boundary=bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 MIME-Version: 1.0 ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 @@ -15,7 +15,7 @@ Hi Bobby, Your account bobby has been suspended by rob. ---bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8 @@ -67,4 +67,4 @@ f0609-9b69-4d36-a989-9f5925b6cbff" style=3D"color: #2563eb; text-decoration= ---966b59c3ffdd1ddd7153b1bd8a93c26fea01112c60e1690555a60d419428-- +--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4-- From ca9b13008b8fc747fac1f4d61ad93fcd036f1433 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 10:41:11 +0000 Subject: [PATCH 32/44] fix(coderd/notifications): use consistent labels throughout notifications --- ...ent_notification_initiator_naming.down.sql | 55 ++++++++++++++++++ ...stent_notification_initiator_naming.up.sql | 57 +++++++++++++++++++ coderd/notifications/notifications_test.go | 22 +++---- .../TemplateUserAccountActivated.html.golden | 4 +- .../TemplateUserAccountDeleted.html.golden | 4 +- .../TemplateUserAccountSuspended.html.golden | 4 +- .../TemplateUserAccountDeleted.json.golden | 8 +-- .../TemplateUserAccountSuspended.json.golden | 8 +-- .../TemplateYourAccountActivated.json.golden | 4 +- .../TemplateYourAccountSuspended.json.golden | 2 +- coderd/users.go | 8 +-- coderd/users_test.go | 2 +- 12 files changed, 145 insertions(+), 33 deletions(-) create mode 100644 coderd/database/migrations/000263_consistent_notification_initiator_naming.down.sql create mode 100644 coderd/database/migrations/000263_consistent_notification_initiator_naming.up.sql diff --git a/coderd/database/migrations/000263_consistent_notification_initiator_naming.down.sql b/coderd/database/migrations/000263_consistent_notification_initiator_naming.down.sql new file mode 100644 index 0000000000000..0e7823a3383dd --- /dev/null +++ b/coderd/database/migrations/000263_consistent_notification_initiator_naming.down.sql @@ -0,0 +1,55 @@ +-- UserAccountCreated +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || + E'New user account **{{.Labels.created_account_name}}** has been created.\n\n' || + -- Mention the real name of the user who created the account: + E'This new user account was created for **{{.Labels.created_account_user_name}}** by **{{.Labels.account_creator}}**.' +WHERE + id = '4e19c0ac-94e1-4532-9515-d1801aa283b2'; + +-- UserAccountDeleted +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || + E'User account **{{.Labels.deleted_account_name}}** has been deleted.\n\n' || + -- Mention the real name of the user who deleted the account: + E'The deleted account belonged to **{{.Labels.deleted_account_user_name}}** and was deleted by **{{.Labels.account_deleter_user_name}}**.' +WHERE + id = 'f44d9314-ad03-4bc8-95d0-5cad491da6b6'; + +-- UserAccountSuspended +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n + E'User account **{{.Labels.suspended_account_name}}** has been suspended.\n\n' || + -- Mention the real name of the user who suspended the account: + E'The newly suspended account belongs to **{{.Labels.suspended_account_user_name}}** and was suspended by **{{.Labels.account_suspender_user_name}}**.' +WHERE + id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; + +-- YourAccountSuspended +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n + E'Your account **{{.Labels.suspended_account_name}}** has been suspended by **{{.Labels.account_suspender_user_name}}**.' +WHERE + id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; + + +-- UserAccountActivated +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n + E'User account **{{.Labels.activated_account_name}}** has been activated.\n\n' || + E'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.account_activator_user_name}}**.' +WHERE + id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; + +-- YourAccountActivated +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n + E'Your account **{{.Labels.activated_account_name}}** has been activated by **{{.Labels.account_activator_user_name}}**.' +WHERE + id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; diff --git a/coderd/database/migrations/000263_consistent_notification_initiator_naming.up.sql b/coderd/database/migrations/000263_consistent_notification_initiator_naming.up.sql new file mode 100644 index 0000000000000..1357e7a1ef287 --- /dev/null +++ b/coderd/database/migrations/000263_consistent_notification_initiator_naming.up.sql @@ -0,0 +1,57 @@ +-- UserAccountCreated +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || + E'New user account **{{.Labels.created_account_name}}** has been created.\n\n' || + -- Use the conventional initiator label: + E'This new user account was created for **{{.Labels.created_account_user_name}}** by **{{.Labels.initiator}}**.' +WHERE + id = '4e19c0ac-94e1-4532-9515-d1801aa283b2'; + +-- UserAccountDeleted +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || + E'User account **{{.Labels.deleted_account_name}}** has been deleted.\n\n' || + -- Use the conventional initiator label: + E'The deleted account belonged to **{{.Labels.deleted_account_user_name}}** and was deleted by **{{.Labels.initiator}}**.' +WHERE + id = 'f44d9314-ad03-4bc8-95d0-5cad491da6b6'; + +-- UserAccountSuspended +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n + E'User account **{{.Labels.suspended_account_name}}** has been suspended.\n\n' || + -- Use the conventional initiator label: + E'The newly suspended account belongs to **{{.Labels.suspended_account_user_name}}** and was suspended by **{{.Labels.initiator}}**.' +WHERE + id = 'b02ddd82-4733-4d02-a2d7-c36f3598997d'; + +-- YourAccountSuspended +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n + -- Use the conventional initiator label: + E'Your account **{{.Labels.suspended_account_name}}** has been suspended by **{{.Labels.initiator}}**.' +WHERE + id = '6a2f0609-9b69-4d36-a989-9f5925b6cbff'; + +-- UserAccountActivated +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n + E'User account **{{.Labels.activated_account_name}}** has been activated.\n\n' || + -- Use the conventional initiator label: + E'The newly activated account belongs to **{{.Labels.activated_account_user_name}}** and was activated by **{{.Labels.initiator}}**.' +WHERE + id = '9f5af851-8408-4e73-a7a1-c6502ba46689'; + +-- YourAccountActivated +UPDATE notification_templates +SET + body_template = E'Hi {{.UserName}},\n\n' || -- Add a \n + -- Use the conventional initiator label: + E'Your account **{{.Labels.activated_account_name}}** has been activated by **{{.Labels.initiator}}**.' +WHERE + id = '1a6a6bea-ee0a-43e2-9e7c-eabdb53730e4'; diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index b16764ffcd924..bbe25f6525b6f 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -794,7 +794,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { Labels: map[string]string{ "created_account_name": "bobby", "created_account_user_name": "William Tables", - "account_creator": "rob", + "initiator": "rob", }, }, }, @@ -807,8 +807,8 @@ func TestNotificationTemplates_Golden(t *testing.T) { UserUsername: "bobby", Labels: map[string]string{ "deleted_account_name": "bobby", - "deleted_account_user_name": "william tables", - "account_deleter_user_name": "rob", + "deleted_account_user_name": "William Tables", + "initiator": "rob", }, }, }, @@ -821,8 +821,8 @@ func TestNotificationTemplates_Golden(t *testing.T) { UserUsername: "bobby", Labels: map[string]string{ "suspended_account_name": "bobby", - "suspended_account_user_name": "william tables", - "account_suspender_user_name": "rob", + "suspended_account_user_name": "William Tables", + "initiator": "rob", }, }, }, @@ -835,8 +835,8 @@ func TestNotificationTemplates_Golden(t *testing.T) { UserUsername: "bobby", Labels: map[string]string{ "activated_account_name": "bobby", - "activated_account_user_name": "william tables", - "account_activator_user_name": "rob", + "activated_account_user_name": "William Tables", + "initiator": "rob", }, }, }, @@ -848,8 +848,8 @@ func TestNotificationTemplates_Golden(t *testing.T) { UserEmail: "bobby@coder.com", UserUsername: "bobby", Labels: map[string]string{ - "suspended_account_name": "bobby", - "account_suspender_user_name": "rob", + "suspended_account_name": "bobby", + "initiator": "rob", }, }, }, @@ -861,8 +861,8 @@ func TestNotificationTemplates_Golden(t *testing.T) { UserEmail: "bobby@coder.com", UserUsername: "bobby", Labels: map[string]string{ - "activated_account_name": "bobby", - "account_activator_user_name": "rob", + "activated_account_name": "bobby", + "initiator": "rob", }, }, }, diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden index 218f0958bafec..81cbe7f54fd0e 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountActivated.html.golden @@ -14,7 +14,7 @@ Hi Bobby, User account bobby has been activated. -The newly activated account belongs to william tables and was activated by = +The newly activated account belongs to William Tables and was activated by = rob. @@ -52,7 +52,7 @@ argin: 8px 0 32px; line-height: 1.5;">

User account bobby has been activated.

-

The newly activated account belongs to william tables a= +

The newly activated account belongs to William Tables a= nd was activated by rob.

diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden index d0f1144f66cf3..c7daad54f028b 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountDeleted.html.golden @@ -14,7 +14,7 @@ Hi Bobby, User account bobby has been deleted. -The deleted account belonged to william tables and was deleted by rob. +The deleted account belonged to William Tables and was deleted by rob. View accounts: http://test.com/deployment/users?filter=3Dstatus%3Aactive @@ -51,7 +51,7 @@ argin: 8px 0 32px; line-height: 1.5;">

User account bobby has been deleted.

-

The deleted account belonged to william tables and was = +

The deleted account belonged to William Tables and was = deleted by rob.

diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden index 4323583c2ec5c..ccd40593ef5fb 100644 --- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden +++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateUserAccountSuspended.html.golden @@ -14,7 +14,7 @@ Hi Bobby, User account bobby has been suspended. -The newly suspended account belongs to william tables and was suspended by = +The newly suspended account belongs to William Tables and was suspended by = rob. @@ -53,7 +53,7 @@ argin: 8px 0 32px; line-height: 1.5;">

User account bobby has been suspended.

-

The newly suspended account belongs to william tables a= +

The newly suspended account belongs to William Tables a= nd was suspended by rob.

diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden index 6fa6379c812c2..10b7ddbca6853 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountDeleted.json.golden @@ -16,14 +16,14 @@ } ], "labels": { - "account_deleter_user_name": "rob", "deleted_account_name": "bobby", - "deleted_account_user_name": "william tables" + "deleted_account_user_name": "William Tables", + "initiator": "rob" }, "data": null }, "title": "User account \"bobby\" deleted", "title_markdown": "User account \"bobby\" deleted", - "body": "Hi Bobby,\n\nUser account bobby has been deleted.\n\nThe deleted account belonged to william tables and was deleted by rob.", - "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been deleted.\n\nThe deleted account belonged to **william tables** and was deleted by **rob**." + "body": "Hi Bobby,\n\nUser account bobby has been deleted.\n\nThe deleted account belonged to William Tables and was deleted by rob.", + "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been deleted.\n\nThe deleted account belonged to **William Tables** and was deleted by **rob**." } \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden index 2d9a8fc2dc234..04146d5e71400 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountSuspended.json.golden @@ -16,14 +16,14 @@ } ], "labels": { - "account_suspender_user_name": "rob", + "initiator": "rob", "suspended_account_name": "bobby", - "suspended_account_user_name": "william tables" + "suspended_account_user_name": "William Tables" }, "data": null }, "title": "User account \"bobby\" suspended", "title_markdown": "User account \"bobby\" suspended", - "body": "Hi Bobby,\n\nUser account bobby has been suspended.\n\nThe newly suspended account belongs to william tables and was suspended by rob.", - "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been suspended.\n\nThe newly suspended account belongs to **william tables** and was suspended by **rob**." + "body": "Hi Bobby,\n\nUser account bobby has been suspended.\n\nThe newly suspended account belongs to William Tables and was suspended by rob.", + "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been suspended.\n\nThe newly suspended account belongs to **William Tables** and was suspended by **rob**." } \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden index 333964aa57799..2e01ab7c631dc 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountActivated.json.golden @@ -16,8 +16,8 @@ } ], "labels": { - "account_activator_user_name": "rob", - "activated_account_name": "bobby" + "activated_account_name": "bobby", + "initiator": "rob" }, "data": null }, diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden index 768f9839126ea..53516dbdab5ce 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateYourAccountSuspended.json.golden @@ -11,7 +11,7 @@ "user_username": "bobby", "actions": [], "labels": { - "account_suspender_user_name": "rob", + "initiator": "rob", "suspended_account_name": "bobby" }, "data": null diff --git a/coderd/users.go b/coderd/users.go index 2356bf2211a61..78b88ba892426 100644 --- a/coderd/users.go +++ b/coderd/users.go @@ -604,7 +604,7 @@ func (api *API) deleteUser(rw http.ResponseWriter, r *http.Request) { map[string]string{ "deleted_account_name": user.Username, "deleted_account_user_name": user.Name, - "account_deleter_user_name": accountDeleter.Name, + "initiator": accountDeleter.Name, }, "api-users-delete", user.ID, @@ -918,7 +918,7 @@ func (api *API) notifyUserStatusChanged(ctx context.Context, actingUserName stri labels = map[string]string{ "suspended_account_name": targetUser.Username, "suspended_account_user_name": targetUser.Name, - "account_suspender_user_name": actingUserName, + "initiator": actingUserName, } adminTemplateID = notifications.TemplateUserAccountSuspended personalTemplateID = notifications.TemplateYourAccountSuspended @@ -926,7 +926,7 @@ func (api *API) notifyUserStatusChanged(ctx context.Context, actingUserName stri labels = map[string]string{ "activated_account_name": targetUser.Username, "activated_account_user_name": targetUser.Name, - "account_activator_user_name": actingUserName, + "initiator": actingUserName, } adminTemplateID = notifications.TemplateUserAccountActivated personalTemplateID = notifications.TemplateYourAccountActivated @@ -1407,7 +1407,7 @@ func (api *API) CreateUser(ctx context.Context, store database.Store, req Create map[string]string{ "created_account_name": user.Username, "created_account_user_name": user.Name, - "account_creator": req.accountCreatorName, + "initiator": req.accountCreatorName, }, "api-users-create", user.ID, ); err != nil { diff --git a/coderd/users_test.go b/coderd/users_test.go index 7406df75bf1db..ff7c63e63bebc 100644 --- a/coderd/users_test.go +++ b/coderd/users_test.go @@ -517,7 +517,7 @@ func TestNotifyDeletedUser(t *testing.T) { require.Contains(t, notifyEnq.Sent[1].Targets, user.ID) require.Equal(t, user.Username, notifyEnq.Sent[1].Labels["deleted_account_name"]) require.Equal(t, user.Name, notifyEnq.Sent[1].Labels["deleted_account_user_name"]) - require.Equal(t, firstUser.Name, notifyEnq.Sent[1].Labels["account_deleter_user_name"]) + require.Equal(t, firstUser.Name, notifyEnq.Sent[1].Labels["initiator"]) }) t.Run("UserAdminNotified", func(t *testing.T) { From ff620e57cebaad59d356fd1e444a8c22fcacc0ae Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 10:48:31 +0000 Subject: [PATCH 33/44] exempt notifications testdata from typo checking --- .github/workflows/typos.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/typos.toml b/.github/workflows/typos.toml index a9748c2d19ea0..b384068e831f2 100644 --- a/.github/workflows/typos.toml +++ b/.github/workflows/typos.toml @@ -41,4 +41,6 @@ extend-exclude = [ "tailnet/testdata/**", "site/src/pages/SetupPage/countries.tsx", "provisioner/terraform/testdata/**", + # notifications' golden files confuse the detector because of quoted-printable encoding + "coderd/notifications/testdata/**" ] From b08587cf3f748d7e86f9c2aecd8fa06cf82f7d71 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 10:57:08 +0000 Subject: [PATCH 34/44] chore(coderd/notifications) TestSMTP --- coderd/notifications/dispatch/smtp_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/coderd/notifications/dispatch/smtp_test.go b/coderd/notifications/dispatch/smtp_test.go index febc646f53d39..a161e163a9778 100644 --- a/coderd/notifications/dispatch/smtp_test.go +++ b/coderd/notifications/dispatch/smtp_test.go @@ -2,7 +2,6 @@ package dispatch_test import ( "bytes" - _ "embed" "fmt" "log" "sync" @@ -46,9 +45,9 @@ func TestSMTP(t *testing.T) { subject = "This is the subject" body = "This is the body" - caFile = "fixtures/ca.crt" - certFile = "fixtures/server.crt" - keyFile = "fixtures/server.key" + caFile = "mock_smtp/fixtures/ca.crt" + certFile = "mock_smtp/fixtures/server.crt" + keyFile = "mock_smtp/fixtures/server.key" ) logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true, IgnoredErrorIs: []error{}}).Leveled(slog.LevelDebug) @@ -124,7 +123,7 @@ func TestSMTP(t *testing.T) { Auth: codersdk.NotificationsEmailAuthConfig{ Username: username, - PasswordFile: "fixtures/password.txt", + PasswordFile: "mock_smtp/fixtures/password.txt", }, }, toAddrs: []string{to}, @@ -340,14 +339,14 @@ func TestSMTP(t *testing.T) { cfg: codersdk.NotificationsEmailConfig{ TLS: codersdk.NotificationsEmailTLSConfig{ CAFile: caFile, - CertFile: "fixtures/nope.cert", + CertFile: "mock_smtp/fixtures/nope.cert", KeyFile: keyFile, }, }, // not using full error message here since it differs on *nix and Windows: // *nix: no such file or directory // Windows: The system cannot find the file specified. - expectedErr: "open fixtures/nope.cert:", + expectedErr: "open mock_smtp/fixtures/nope.cert:", retryable: true, }, { @@ -357,13 +356,13 @@ func TestSMTP(t *testing.T) { TLS: codersdk.NotificationsEmailTLSConfig{ CAFile: caFile, CertFile: certFile, - KeyFile: "fixtures/nope.key", + KeyFile: "mock_smtp/fixtures/nope.key", }, }, // not using full error message here since it differs on *nix and Windows: // *nix: no such file or directory // Windows: The system cannot find the file specified. - expectedErr: "open fixtures/nope.key:", + expectedErr: "open mock_smtp/fixtures/nope.key:", retryable: true, }, /** From 99274344a2e355146c43863fe27da87e5bb8a4ec Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 11:07:21 +0000 Subject: [PATCH 35/44] chore(coderd/notifications) rename mock_smtp package to match linting rules --- .../{mock_smtp => mocksmtp}/fixtures/ca.conf | 0 .../{mock_smtp => mocksmtp}/fixtures/ca.crt | 0 .../{mock_smtp => mocksmtp}/fixtures/ca.key | 0 .../{mock_smtp => mocksmtp}/fixtures/ca.srl | 0 .../fixtures/generate.sh | 0 .../fixtures/password.txt | 0 .../fixtures/server.conf | 0 .../fixtures/server.crt | 0 .../fixtures/server.csr | 0 .../fixtures/server.key | 0 .../fixtures/v3_ext.conf | 0 .../{mock_smtp => mocksmtp}/server.go | 2 +- coderd/notifications/dispatch/smtp_test.go | 24 +++++++++---------- 13 files changed, 13 insertions(+), 13 deletions(-) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/ca.conf (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/ca.crt (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/ca.key (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/ca.srl (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/generate.sh (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/password.txt (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/server.conf (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/server.crt (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/server.csr (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/server.key (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/fixtures/v3_ext.conf (100%) rename coderd/notifications/dispatch/{mock_smtp => mocksmtp}/server.go (99%) diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/ca.conf b/coderd/notifications/dispatch/mocksmtp/fixtures/ca.conf similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/ca.conf rename to coderd/notifications/dispatch/mocksmtp/fixtures/ca.conf diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/ca.crt b/coderd/notifications/dispatch/mocksmtp/fixtures/ca.crt similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/ca.crt rename to coderd/notifications/dispatch/mocksmtp/fixtures/ca.crt diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/ca.key b/coderd/notifications/dispatch/mocksmtp/fixtures/ca.key similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/ca.key rename to coderd/notifications/dispatch/mocksmtp/fixtures/ca.key diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/ca.srl b/coderd/notifications/dispatch/mocksmtp/fixtures/ca.srl similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/ca.srl rename to coderd/notifications/dispatch/mocksmtp/fixtures/ca.srl diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/generate.sh b/coderd/notifications/dispatch/mocksmtp/fixtures/generate.sh similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/generate.sh rename to coderd/notifications/dispatch/mocksmtp/fixtures/generate.sh diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/password.txt b/coderd/notifications/dispatch/mocksmtp/fixtures/password.txt similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/password.txt rename to coderd/notifications/dispatch/mocksmtp/fixtures/password.txt diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/server.conf b/coderd/notifications/dispatch/mocksmtp/fixtures/server.conf similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/server.conf rename to coderd/notifications/dispatch/mocksmtp/fixtures/server.conf diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/server.crt b/coderd/notifications/dispatch/mocksmtp/fixtures/server.crt similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/server.crt rename to coderd/notifications/dispatch/mocksmtp/fixtures/server.crt diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/server.csr b/coderd/notifications/dispatch/mocksmtp/fixtures/server.csr similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/server.csr rename to coderd/notifications/dispatch/mocksmtp/fixtures/server.csr diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/server.key b/coderd/notifications/dispatch/mocksmtp/fixtures/server.key similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/server.key rename to coderd/notifications/dispatch/mocksmtp/fixtures/server.key diff --git a/coderd/notifications/dispatch/mock_smtp/fixtures/v3_ext.conf b/coderd/notifications/dispatch/mocksmtp/fixtures/v3_ext.conf similarity index 100% rename from coderd/notifications/dispatch/mock_smtp/fixtures/v3_ext.conf rename to coderd/notifications/dispatch/mocksmtp/fixtures/v3_ext.conf diff --git a/coderd/notifications/dispatch/mock_smtp/server.go b/coderd/notifications/dispatch/mocksmtp/server.go similarity index 99% rename from coderd/notifications/dispatch/mock_smtp/server.go rename to coderd/notifications/dispatch/mocksmtp/server.go index 1290be1bece49..14be7c567c0a3 100644 --- a/coderd/notifications/dispatch/mock_smtp/server.go +++ b/coderd/notifications/dispatch/mocksmtp/server.go @@ -1,4 +1,4 @@ -package mock_smtp +package mocksmtp import ( "crypto/tls" diff --git a/coderd/notifications/dispatch/smtp_test.go b/coderd/notifications/dispatch/smtp_test.go index a161e163a9778..d504896689c70 100644 --- a/coderd/notifications/dispatch/smtp_test.go +++ b/coderd/notifications/dispatch/smtp_test.go @@ -19,7 +19,7 @@ import ( "github.com/coder/serpent" "github.com/coder/coder/v2/coderd/notifications/dispatch" - "github.com/coder/coder/v2/coderd/notifications/dispatch/mock_smtp" + "github.com/coder/coder/v2/coderd/notifications/dispatch/mocksmtp" "github.com/coder/coder/v2/coderd/notifications/types" "github.com/coder/coder/v2/codersdk" "github.com/coder/coder/v2/testutil" @@ -45,9 +45,9 @@ func TestSMTP(t *testing.T) { subject = "This is the subject" body = "This is the body" - caFile = "mock_smtp/fixtures/ca.crt" - certFile = "mock_smtp/fixtures/server.crt" - keyFile = "mock_smtp/fixtures/server.key" + caFile = "mocksmtp/fixtures/ca.crt" + certFile = "mocksmtp/fixtures/server.crt" + keyFile = "mocksmtp/fixtures/server.key" ) logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true, IgnoredErrorIs: []error{}}).Leveled(slog.LevelDebug) @@ -123,7 +123,7 @@ func TestSMTP(t *testing.T) { Auth: codersdk.NotificationsEmailAuthConfig{ Username: username, - PasswordFile: "mock_smtp/fixtures/password.txt", + PasswordFile: "mocksmtp/fixtures/password.txt", }, }, toAddrs: []string{to}, @@ -339,14 +339,14 @@ func TestSMTP(t *testing.T) { cfg: codersdk.NotificationsEmailConfig{ TLS: codersdk.NotificationsEmailTLSConfig{ CAFile: caFile, - CertFile: "mock_smtp/fixtures/nope.cert", + CertFile: "mocksmtp/fixtures/nope.cert", KeyFile: keyFile, }, }, // not using full error message here since it differs on *nix and Windows: // *nix: no such file or directory // Windows: The system cannot find the file specified. - expectedErr: "open mock_smtp/fixtures/nope.cert:", + expectedErr: "open mocksmtp/fixtures/nope.cert:", retryable: true, }, { @@ -356,13 +356,13 @@ func TestSMTP(t *testing.T) { TLS: codersdk.NotificationsEmailTLSConfig{ CAFile: caFile, CertFile: certFile, - KeyFile: "mock_smtp/fixtures/nope.key", + KeyFile: "mocksmtp/fixtures/nope.key", }, }, // not using full error message here since it differs on *nix and Windows: // *nix: no such file or directory // Windows: The system cannot find the file specified. - expectedErr: "open mock_smtp/fixtures/nope.key:", + expectedErr: "open mocksmtp/fixtures/nope.key:", retryable: true, }, /** @@ -415,7 +415,7 @@ func TestSMTP(t *testing.T) { tc.cfg.ForceTLS = serpent.Bool(tc.useTLS) - backend := mock_smtp.NewBackend(mock_smtp.Config{ + backend := mocksmtp.NewBackend(mocksmtp.Config{ AuthMechanisms: tc.authMechs, AcceptedIdentity: tc.cfg.Auth.Identity.String(), @@ -426,7 +426,7 @@ func TestSMTP(t *testing.T) { }) // Create a mock SMTP server which conditionally listens for plain or TLS connections. - srv, listen, err := mock_smtp.CreateMockSMTPServer(backend, tc.useTLS) + srv, listen, err := mocksmtp.CreateMockSMTPServer(backend, tc.useTLS) require.NoError(t, err) t.Cleanup(func() { // We expect that the server has already been closed in the test @@ -458,7 +458,7 @@ func TestSMTP(t *testing.T) { // Wait for the server to become pingable. require.Eventually(t, func() bool { - cl, err := mock_smtp.PingClient(listen, tc.useTLS, tc.cfg.TLS.StartTLS.Value()) + cl, err := mocksmtp.PingClient(listen, tc.useTLS, tc.cfg.TLS.StartTLS.Value()) if err != nil { t.Logf("smtp not yet dialable: %s", err) return false From f6ef5c43de3435b968220e772794aeee296add52 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 11:08:46 +0000 Subject: [PATCH 36/44] chore(coderd/notifications) remove a defunct type conversion --- coderd/notifications/notifications_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index bbe25f6525b6f..454b32c30922d 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -1125,7 +1125,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { if *updateGoldenFiles { err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) require.NoError(t, err, "want no error creating golden file directory") - err = os.WriteFile(goldenFile, []byte(body), 0o600) + err = os.WriteFile(goldenFile, body, 0o600) require.NoError(t, err, "want no error writing body golden file") return } From dadad9f237ddd0aa316b91bba44b8765ed830aae Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 11:16:41 +0000 Subject: [PATCH 37/44] chore(coderd/notifications) rename mock_smtp package to match linting rules --- coderd/notifications/notifications_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 454b32c30922d..90003d7414b6d 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -48,7 +48,7 @@ import ( "github.com/coder/coder/v2/coderd/database/dbtestutil" "github.com/coder/coder/v2/coderd/notifications" "github.com/coder/coder/v2/coderd/notifications/dispatch" - "github.com/coder/coder/v2/coderd/notifications/dispatch/mock_smtp" + "github.com/coder/coder/v2/coderd/notifications/dispatch/mocksmtp" "github.com/coder/coder/v2/coderd/notifications/types" "github.com/coder/coder/v2/coderd/rbac" "github.com/coder/coder/v2/coderd/util/syncmap" @@ -1021,7 +1021,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { } // Spin up the mock SMTP server - backend := mock_smtp.NewBackend(mock_smtp.Config{ + backend := mocksmtp.NewBackend(mocksmtp.Config{ AuthMechanisms: []string{sasl.Login}, AcceptedIdentity: smtpConfig.Auth.Identity.String(), @@ -1030,7 +1030,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { }) // Create a mock SMTP server which conditionally listens for plain or TLS connections. - srv, listen, err := mock_smtp.CreateMockSMTPServer(backend, false) + srv, listen, err := mocksmtp.CreateMockSMTPServer(backend, false) require.NoError(t, err) t.Cleanup(func() { err := srv.Shutdown(ctx) @@ -1051,7 +1051,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { // Wait for the server to become pingable. require.Eventually(t, func() bool { - cl, err := mock_smtp.PingClient(listen, false, smtpConfig.TLS.StartTLS.Value()) + cl, err := mocksmtp.PingClient(listen, false, smtpConfig.TLS.StartTLS.Value()) if err != nil { t.Logf("smtp not yet dialable: %s", err) return false @@ -1108,7 +1108,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { require.NoError(t, err) // Wait for the message to be fetched - var msg *mock_smtp.Message + var msg *mocksmtp.Message require.Eventually(t, func() bool { msg = backend.LastMessage() return msg != nil From f93135afe6425aaab08f0cd00cf7dded779df86c Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 13:07:39 +0000 Subject: [PATCH 38/44] chore(coderd/notifications): fix golden file test --- coderd/notifications/notifications_test.go | 10 +++++----- .../webhook/TemplateUserAccountActivated.json.golden | 8 ++++---- .../webhook/TemplateUserAccountCreated.json.golden | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 90003d7414b6d..a9cf3cfd47c84 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -1142,13 +1142,15 @@ func TestNotificationTemplates_Golden(t *testing.T) { // Spin up the mock webhook server server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + body, err := io.ReadAll(r.Body) require.NoError(t, err) var prettyJSON bytes.Buffer err = json.Indent(&prettyJSON, body, "", " ") require.NoError(t, err) - content := constantifyGoldenWebhook(prettyJSON.Bytes()) + content := normalizeGoldenWebhook(prettyJSON.Bytes()) partialName := strings.Split(t.Name(), "/")[1] goldenFile := filepath.Join("testdata", "rendered-templates", "webhook", partialName+".json.golden") @@ -1157,15 +1159,13 @@ func TestNotificationTemplates_Golden(t *testing.T) { require.NoError(t, err, "want no error creating golden file directory") err = os.WriteFile(goldenFile, content, 0o600) require.NoError(t, err, "want no error writing body golden file") - w.WriteHeader(http.StatusOK) return } wantBody, err := os.ReadFile(goldenFile) require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) - require.Equal(t, string(wantBody), prettyJSON, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint)) + require.Equal(t, wantBody, content, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint)) - w.WriteHeader(http.StatusOK) })) t.Cleanup(server.Close) @@ -1235,7 +1235,7 @@ func normalizeGoldenEmail(content []byte) []byte { return content } -func constantifyGoldenWebhook(content []byte) []byte { +func normalizeGoldenWebhook(content []byte) []byte { const constantUUID = "00000000-0000-0000-0000-000000000000" uuidRegex := regexp.MustCompile(`[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}`) content = uuidRegex.ReplaceAll(content, []byte(constantUUID)) diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden index 847935aa904af..5da690875888e 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountActivated.json.golden @@ -16,14 +16,14 @@ } ], "labels": { - "account_activator_user_name": "rob", "activated_account_name": "bobby", - "activated_account_user_name": "william tables" + "activated_account_user_name": "William Tables", + "initiator": "rob" }, "data": null }, "title": "User account \"bobby\" activated", "title_markdown": "User account \"bobby\" activated", - "body": "Hi Bobby,\n\nUser account bobby has been activated.\n\nThe newly activated account belongs to william tables and was activated by rob.", - "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **william tables** and was activated by **rob**." + "body": "Hi Bobby,\n\nUser account bobby has been activated.\n\nThe newly activated account belongs to William Tables and was activated by rob.", + "body_markdown": "Hi Bobby,\n\nUser account **bobby** has been activated.\n\nThe newly activated account belongs to **William Tables** and was activated by **rob**." } \ No newline at end of file diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden index 6425496bf1cff..272a5628a20a7 100644 --- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden +++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateUserAccountCreated.json.golden @@ -16,9 +16,9 @@ } ], "labels": { - "account_creator": "rob", "created_account_name": "bobby", - "created_account_user_name": "William Tables" + "created_account_user_name": "William Tables", + "initiator": "rob" }, "data": null }, From 55e3d020e04fee84dc1e23a3ff9a3d05db017e51 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 13:11:46 +0000 Subject: [PATCH 39/44] chore(coderd/notifications): fix linting --- coderd/notifications/notifications_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index a9cf3cfd47c84..ee02b842842e4 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -1165,7 +1165,6 @@ func TestNotificationTemplates_Golden(t *testing.T) { wantBody, err := os.ReadFile(goldenFile) require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) require.Equal(t, wantBody, content, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint)) - })) t.Cleanup(server.Close) From be00f5949e4f3a4613b51276f41e99846d767b5c Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Fri, 11 Oct 2024 13:40:54 +0000 Subject: [PATCH 40/44] chore(coderd/notifications): fix golden file test --- .../TemplateWorkspaceDeleted.golden.html | 66 ------------------- coderd/notifications/notifications_test.go | 13 +++- 2 files changed, 10 insertions(+), 69 deletions(-) delete mode 100644 coderd/notifications/dispatch/testdata/rendered-templates/TemplateWorkspaceDeleted.golden.html diff --git a/coderd/notifications/dispatch/testdata/rendered-templates/TemplateWorkspaceDeleted.golden.html b/coderd/notifications/dispatch/testdata/rendered-templates/TemplateWorkspaceDeleted.golden.html deleted file mode 100644 index 8e5e065539039..0000000000000 --- a/coderd/notifications/dispatch/testdata/rendered-templates/TemplateWorkspaceDeleted.golden.html +++ /dev/null @@ -1,66 +0,0 @@ -From: system@coder.com -To: bobby@coder.com -Subject: Workspace bobby-workspace has been deleted -Message-Id: 74472365-4868-463c-8325-1a0c99d12ac0@blush-whale-48 -Date: Thu, 10 Oct 2024 10:42:15 +0000 -Content-Type: multipart/alternative; boundary=32122c97f1062aa05b08887844a8756eb74e6b2de42c5bdcab2584aed1fb -MIME-Version: 1.0 - ---32122c97f1062aa05b08887844a8756eb74e6b2de42c5bdcab2584aed1fb -Content-Transfer-Encoding: quoted-printable -Content-Type: text/plain; charset=UTF-8 - -Workspace bobby-workspace has been deleted due to dormancy by autobuild. - - ---32122c97f1062aa05b08887844a8756eb74e6b2de42c5bdcab2584aed1fb -Content-Transfer-Encoding: quoted-printable -Content-Type: text/html; charset=UTF-8 - - - - - - - Codestin Search App - - -
-
- 3D"Cod= -
-

- Workspace bobby-workspace has been deleted -

-
-

Workspace bobby-workspace has been deleted due to dormancy by au= -tobuild.

-
-
- =20 -
- -
- - - ---32122c97f1062aa05b08887844a8756eb74e6b2de42c5bdcab2584aed1fb-- diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index ee02b842842e4..3b26ff2e840c4 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -1111,9 +1111,11 @@ func TestNotificationTemplates_Golden(t *testing.T) { var msg *mocksmtp.Message require.Eventually(t, func() bool { msg = backend.LastMessage() - return msg != nil + return msg != nil && len(msg.Contents) > 0 }, testutil.WaitShort, testutil.IntervalFast) - require.NotNil(t, msg, "want a message to be sent") + + // require.NotNil(t, msg, "want a message to be sent") + // require.NotEmpty(t, msg.Contents, "want a non-empty message") body := normalizeGoldenEmail([]byte(msg.Contents)) @@ -1225,7 +1227,12 @@ func normalizeGoldenEmail(content []byte) []byte { dateRegex := regexp.MustCompile(`Date: .+`) messageIDRegex := regexp.MustCompile(`Message-Id: .+`) boundaryRegex := regexp.MustCompile(`boundary=([0-9a-zA-Z]+)`) - boundary := boundaryRegex.FindSubmatch(content)[1] + submatches := boundaryRegex.FindSubmatch(content) + if len(submatches) == 0 { + return content + } + + boundary := submatches[1] content = dateRegex.ReplaceAll(content, []byte("Date: "+constantDate)) content = messageIDRegex.ReplaceAll(content, []byte("Message-Id: "+constantMessageID)) From 4991c33420c37fe56981387cad87bf4fe84aa76d Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Mon, 14 Oct 2024 06:45:14 +0000 Subject: [PATCH 41/44] chore(coderd/notifications): remove defunct test sleep --- coderd/notifications/notifications_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 3b26ff2e840c4..e33f380dbc96d 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -1083,7 +1083,6 @@ func TestNotificationTemplates_Golden(t *testing.T) { require.NoError(t, err) smtpManager.Run(ctx) - time.Sleep(time.Second) notificationCfg := defaultNotificationsConfig(database.NotificationMethodSmtp) From 464b24454b021cf111566e13562f038f09ea4927 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Mon, 14 Oct 2024 06:48:35 +0000 Subject: [PATCH 42/44] chore(coderd/notifications): rename a test package --- coderd/notifications/dispatch/smtp_test.go | 24 +++++++++---------- .../{mocksmtp => smtptest}/fixtures/ca.conf | 0 .../{mocksmtp => smtptest}/fixtures/ca.crt | 0 .../{mocksmtp => smtptest}/fixtures/ca.key | 0 .../{mocksmtp => smtptest}/fixtures/ca.srl | 0 .../fixtures/generate.sh | 0 .../fixtures/password.txt | 0 .../fixtures/server.conf | 0 .../fixtures/server.crt | 0 .../fixtures/server.csr | 0 .../fixtures/server.key | 0 .../fixtures/v3_ext.conf | 0 .../dispatch/{mocksmtp => smtptest}/server.go | 2 +- coderd/notifications/notifications_test.go | 10 ++++---- 14 files changed, 18 insertions(+), 18 deletions(-) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/ca.conf (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/ca.crt (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/ca.key (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/ca.srl (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/generate.sh (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/password.txt (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/server.conf (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/server.crt (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/server.csr (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/server.key (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/fixtures/v3_ext.conf (100%) rename coderd/notifications/dispatch/{mocksmtp => smtptest}/server.go (99%) diff --git a/coderd/notifications/dispatch/smtp_test.go b/coderd/notifications/dispatch/smtp_test.go index d504896689c70..2687e0d82bb26 100644 --- a/coderd/notifications/dispatch/smtp_test.go +++ b/coderd/notifications/dispatch/smtp_test.go @@ -19,7 +19,7 @@ import ( "github.com/coder/serpent" "github.com/coder/coder/v2/coderd/notifications/dispatch" - "github.com/coder/coder/v2/coderd/notifications/dispatch/mocksmtp" + "github.com/coder/coder/v2/coderd/notifications/dispatch/smtptest" "github.com/coder/coder/v2/coderd/notifications/types" "github.com/coder/coder/v2/codersdk" "github.com/coder/coder/v2/testutil" @@ -45,9 +45,9 @@ func TestSMTP(t *testing.T) { subject = "This is the subject" body = "This is the body" - caFile = "mocksmtp/fixtures/ca.crt" - certFile = "mocksmtp/fixtures/server.crt" - keyFile = "mocksmtp/fixtures/server.key" + caFile = "smtptest/fixtures/ca.crt" + certFile = "smtptest/fixtures/server.crt" + keyFile = "smtptest/fixtures/server.key" ) logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true, IgnoredErrorIs: []error{}}).Leveled(slog.LevelDebug) @@ -123,7 +123,7 @@ func TestSMTP(t *testing.T) { Auth: codersdk.NotificationsEmailAuthConfig{ Username: username, - PasswordFile: "mocksmtp/fixtures/password.txt", + PasswordFile: "smtptest/fixtures/password.txt", }, }, toAddrs: []string{to}, @@ -339,14 +339,14 @@ func TestSMTP(t *testing.T) { cfg: codersdk.NotificationsEmailConfig{ TLS: codersdk.NotificationsEmailTLSConfig{ CAFile: caFile, - CertFile: "mocksmtp/fixtures/nope.cert", + CertFile: "smtptest/fixtures/nope.cert", KeyFile: keyFile, }, }, // not using full error message here since it differs on *nix and Windows: // *nix: no such file or directory // Windows: The system cannot find the file specified. - expectedErr: "open mocksmtp/fixtures/nope.cert:", + expectedErr: "open smtptest/fixtures/nope.cert:", retryable: true, }, { @@ -356,13 +356,13 @@ func TestSMTP(t *testing.T) { TLS: codersdk.NotificationsEmailTLSConfig{ CAFile: caFile, CertFile: certFile, - KeyFile: "mocksmtp/fixtures/nope.key", + KeyFile: "smtptest/fixtures/nope.key", }, }, // not using full error message here since it differs on *nix and Windows: // *nix: no such file or directory // Windows: The system cannot find the file specified. - expectedErr: "open mocksmtp/fixtures/nope.key:", + expectedErr: "open smtptest/fixtures/nope.key:", retryable: true, }, /** @@ -415,7 +415,7 @@ func TestSMTP(t *testing.T) { tc.cfg.ForceTLS = serpent.Bool(tc.useTLS) - backend := mocksmtp.NewBackend(mocksmtp.Config{ + backend := smtptest.NewBackend(smtptest.Config{ AuthMechanisms: tc.authMechs, AcceptedIdentity: tc.cfg.Auth.Identity.String(), @@ -426,7 +426,7 @@ func TestSMTP(t *testing.T) { }) // Create a mock SMTP server which conditionally listens for plain or TLS connections. - srv, listen, err := mocksmtp.CreateMockSMTPServer(backend, tc.useTLS) + srv, listen, err := smtptest.CreateMockSMTPServer(backend, tc.useTLS) require.NoError(t, err) t.Cleanup(func() { // We expect that the server has already been closed in the test @@ -458,7 +458,7 @@ func TestSMTP(t *testing.T) { // Wait for the server to become pingable. require.Eventually(t, func() bool { - cl, err := mocksmtp.PingClient(listen, tc.useTLS, tc.cfg.TLS.StartTLS.Value()) + cl, err := smtptest.PingClient(listen, tc.useTLS, tc.cfg.TLS.StartTLS.Value()) if err != nil { t.Logf("smtp not yet dialable: %s", err) return false diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/ca.conf b/coderd/notifications/dispatch/smtptest/fixtures/ca.conf similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/ca.conf rename to coderd/notifications/dispatch/smtptest/fixtures/ca.conf diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/ca.crt b/coderd/notifications/dispatch/smtptest/fixtures/ca.crt similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/ca.crt rename to coderd/notifications/dispatch/smtptest/fixtures/ca.crt diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/ca.key b/coderd/notifications/dispatch/smtptest/fixtures/ca.key similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/ca.key rename to coderd/notifications/dispatch/smtptest/fixtures/ca.key diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/ca.srl b/coderd/notifications/dispatch/smtptest/fixtures/ca.srl similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/ca.srl rename to coderd/notifications/dispatch/smtptest/fixtures/ca.srl diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/generate.sh b/coderd/notifications/dispatch/smtptest/fixtures/generate.sh similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/generate.sh rename to coderd/notifications/dispatch/smtptest/fixtures/generate.sh diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/password.txt b/coderd/notifications/dispatch/smtptest/fixtures/password.txt similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/password.txt rename to coderd/notifications/dispatch/smtptest/fixtures/password.txt diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/server.conf b/coderd/notifications/dispatch/smtptest/fixtures/server.conf similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/server.conf rename to coderd/notifications/dispatch/smtptest/fixtures/server.conf diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/server.crt b/coderd/notifications/dispatch/smtptest/fixtures/server.crt similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/server.crt rename to coderd/notifications/dispatch/smtptest/fixtures/server.crt diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/server.csr b/coderd/notifications/dispatch/smtptest/fixtures/server.csr similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/server.csr rename to coderd/notifications/dispatch/smtptest/fixtures/server.csr diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/server.key b/coderd/notifications/dispatch/smtptest/fixtures/server.key similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/server.key rename to coderd/notifications/dispatch/smtptest/fixtures/server.key diff --git a/coderd/notifications/dispatch/mocksmtp/fixtures/v3_ext.conf b/coderd/notifications/dispatch/smtptest/fixtures/v3_ext.conf similarity index 100% rename from coderd/notifications/dispatch/mocksmtp/fixtures/v3_ext.conf rename to coderd/notifications/dispatch/smtptest/fixtures/v3_ext.conf diff --git a/coderd/notifications/dispatch/mocksmtp/server.go b/coderd/notifications/dispatch/smtptest/server.go similarity index 99% rename from coderd/notifications/dispatch/mocksmtp/server.go rename to coderd/notifications/dispatch/smtptest/server.go index 14be7c567c0a3..689b4d384036d 100644 --- a/coderd/notifications/dispatch/mocksmtp/server.go +++ b/coderd/notifications/dispatch/smtptest/server.go @@ -1,4 +1,4 @@ -package mocksmtp +package smtptest import ( "crypto/tls" diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index e33f380dbc96d..27161782e2183 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -48,7 +48,7 @@ import ( "github.com/coder/coder/v2/coderd/database/dbtestutil" "github.com/coder/coder/v2/coderd/notifications" "github.com/coder/coder/v2/coderd/notifications/dispatch" - "github.com/coder/coder/v2/coderd/notifications/dispatch/mocksmtp" + "github.com/coder/coder/v2/coderd/notifications/dispatch/smtptest" "github.com/coder/coder/v2/coderd/notifications/types" "github.com/coder/coder/v2/coderd/rbac" "github.com/coder/coder/v2/coderd/util/syncmap" @@ -1021,7 +1021,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { } // Spin up the mock SMTP server - backend := mocksmtp.NewBackend(mocksmtp.Config{ + backend := smtptest.NewBackend(smtptest.Config{ AuthMechanisms: []string{sasl.Login}, AcceptedIdentity: smtpConfig.Auth.Identity.String(), @@ -1030,7 +1030,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { }) // Create a mock SMTP server which conditionally listens for plain or TLS connections. - srv, listen, err := mocksmtp.CreateMockSMTPServer(backend, false) + srv, listen, err := smtptest.CreateMockSMTPServer(backend, false) require.NoError(t, err) t.Cleanup(func() { err := srv.Shutdown(ctx) @@ -1051,7 +1051,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { // Wait for the server to become pingable. require.Eventually(t, func() bool { - cl, err := mocksmtp.PingClient(listen, false, smtpConfig.TLS.StartTLS.Value()) + cl, err := smtptest.PingClient(listen, false, smtpConfig.TLS.StartTLS.Value()) if err != nil { t.Logf("smtp not yet dialable: %s", err) return false @@ -1107,7 +1107,7 @@ func TestNotificationTemplates_Golden(t *testing.T) { require.NoError(t, err) // Wait for the message to be fetched - var msg *mocksmtp.Message + var msg *smtptest.Message require.Eventually(t, func() bool { msg = backend.LastMessage() return msg != nil && len(msg.Contents) > 0 From 3eb9c1e2a4093199a78319f718571a112dbb5b11 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Mon, 14 Oct 2024 08:44:50 +0000 Subject: [PATCH 43/44] chore(coderd/notifications): handle test assertions in the correct goroutine --- coderd/notifications/notifications_test.go | 122 ++++++++++++++------- 1 file changed, 80 insertions(+), 42 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index 27161782e2183..b31084fa49277 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -33,6 +33,7 @@ import ( "github.com/coder/quartz" + "github.com/google/go-cmp/cmp" "github.com/google/uuid" smtpmock "github.com/mocktools/go-smtp-mock/v2" "github.com/stretchr/testify/assert" @@ -985,27 +986,29 @@ func TestNotificationTemplates_Golden(t *testing.T) { t.Run(tc.name, func(t *testing.T) { t.Parallel() - // Spin up the DB - db, logger, user := func() (*database.Store, *slog.Logger, *codersdk.User) { - adminClient, _, api := coderdtest.NewWithAPI(t, nil) - db := api.Database - firstUser := coderdtest.CreateFirstUser(t, adminClient) - - _, user := coderdtest.CreateAnotherUserMutators( - t, - adminClient, - firstUser.OrganizationID, - []rbac.RoleIdentifier{rbac.RoleUserAdmin()}, - func(r *codersdk.CreateUserRequestWithOrgs) { - r.Username = tc.payload.UserUsername - r.Email = tc.payload.UserEmail - r.Name = tc.payload.UserName - }, - ) - return &db, &api.Logger, &user - }() t.Run("smtp", func(t *testing.T) { t.Parallel() + + // Spin up the DB + db, logger, user := func() (*database.Store, *slog.Logger, *codersdk.User) { + adminClient, _, api := coderdtest.NewWithAPI(t, nil) + db := api.Database + firstUser := coderdtest.CreateFirstUser(t, adminClient) + + _, user := coderdtest.CreateAnotherUserMutators( + t, + adminClient, + firstUser.OrganizationID, + []rbac.RoleIdentifier{rbac.RoleUserAdmin()}, + func(r *codersdk.CreateUserRequestWithOrgs) { + r.Username = tc.payload.UserUsername + r.Email = tc.payload.UserEmail + r.Name = tc.payload.UserName + }, + ) + return &db, &api.Logger, &user + }() + // nolint:gocritic // Unit test. ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong)) @@ -1133,39 +1136,48 @@ func TestNotificationTemplates_Golden(t *testing.T) { wantBody, err := os.ReadFile(goldenFile) require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) - require.Equal(t, string(wantBody), string(body), fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint)) + require.Empty( + t, + cmp.Diff(wantBody, body), + fmt.Sprintf("golden file mismatch: %s. If this is expected, %s. (-want +got). ", goldenFile, hint), + ) }) t.Run("webhook", func(t *testing.T) { t.Parallel() + + // Spin up the DB + db, logger, user := func() (*database.Store, *slog.Logger, *codersdk.User) { + adminClient, _, api := coderdtest.NewWithAPI(t, nil) + db := api.Database + firstUser := coderdtest.CreateFirstUser(t, adminClient) + + _, user := coderdtest.CreateAnotherUserMutators( + t, + adminClient, + firstUser.OrganizationID, + []rbac.RoleIdentifier{rbac.RoleUserAdmin()}, + func(r *codersdk.CreateUserRequestWithOrgs) { + r.Username = tc.payload.UserUsername + r.Email = tc.payload.UserEmail + r.Name = tc.payload.UserName + }, + ) + return &db, &api.Logger, &user + }() + // nolint:gocritic // Unit test. ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong)) // Spin up the mock webhook server + var body []byte + var readErr error + var webhookReceived bool server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) - body, err := io.ReadAll(r.Body) - require.NoError(t, err) - var prettyJSON bytes.Buffer - err = json.Indent(&prettyJSON, body, "", " ") - require.NoError(t, err) - - content := normalizeGoldenWebhook(prettyJSON.Bytes()) - - partialName := strings.Split(t.Name(), "/")[1] - goldenFile := filepath.Join("testdata", "rendered-templates", "webhook", partialName+".json.golden") - if *updateGoldenFiles { - err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) - require.NoError(t, err, "want no error creating golden file directory") - err = os.WriteFile(goldenFile, content, 0o600) - require.NoError(t, err, "want no error writing body golden file") - return - } - - wantBody, err := os.ReadFile(goldenFile) - require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) - require.Equal(t, wantBody, content, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint)) + body, readErr = io.ReadAll(r.Body) + webhookReceived = true })) t.Cleanup(server.Close) @@ -1209,8 +1221,34 @@ func TestNotificationTemplates_Golden(t *testing.T) { ) require.NoError(t, err) - err = webhookManager.Stop(ctx) + require.Eventually(t, func() bool { + return webhookReceived + }, testutil.WaitShort, testutil.IntervalFast) + require.NoError(t, err) + + // Handle the body that was read in the http server here. + // We need to do it here because we can't call require.* in a separate goroutine, such as the http server handler + require.NoError(t, readErr) + var prettyJSON bytes.Buffer + err = json.Indent(&prettyJSON, body, "", " ") + require.NoError(t, err) + + content := normalizeGoldenWebhook(prettyJSON.Bytes()) + + partialName := strings.Split(t.Name(), "/")[1] + goldenFile := filepath.Join("testdata", "rendered-templates", "webhook", partialName+".json.golden") + if *updateGoldenFiles { + err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) + require.NoError(t, err, "want no error creating golden file directory") + err = os.WriteFile(goldenFile, content, 0o600) + require.NoError(t, err, "want no error writing body golden file") + return + } + + wantBody, err := os.ReadFile(goldenFile) + require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) + require.Equal(t, wantBody, content, fmt.Sprintf("smtp notification does not match golden file. If this is expected, %s", hint)) }) }) } From f049c05efd20e3abb93e3dacd42d143e379a2bd1 Mon Sep 17 00:00:00 2001 From: Sas Swart Date: Mon, 14 Oct 2024 12:22:52 +0000 Subject: [PATCH 44/44] chore(coderd/notifications): reformat imports and remove dead code --- coderd/notifications/notifications_test.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go index b31084fa49277..d6eb480f75c9b 100644 --- a/coderd/notifications/notifications_test.go +++ b/coderd/notifications/notifications_test.go @@ -25,23 +25,16 @@ import ( "testing" "time" - "golang.org/x/xerrors" - - "cdr.dev/slog" - "github.com/emersion/go-sasl" - - "github.com/coder/quartz" - "github.com/google/go-cmp/cmp" "github.com/google/uuid" smtpmock "github.com/mocktools/go-smtp-mock/v2" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/goleak" + "golang.org/x/xerrors" - "github.com/coder/serpent" - + "cdr.dev/slog" "github.com/coder/coder/v2/coderd/coderdtest" "github.com/coder/coder/v2/coderd/database" "github.com/coder/coder/v2/coderd/database/dbauthz" @@ -55,6 +48,8 @@ import ( "github.com/coder/coder/v2/coderd/util/syncmap" "github.com/coder/coder/v2/codersdk" "github.com/coder/coder/v2/testutil" + "github.com/coder/quartz" + "github.com/coder/serpent" ) // updateGoldenFiles is a flag that can be set to update golden files. @@ -1116,9 +1111,6 @@ func TestNotificationTemplates_Golden(t *testing.T) { return msg != nil && len(msg.Contents) > 0 }, testutil.WaitShort, testutil.IntervalFast) - // require.NotNil(t, msg, "want a message to be sent") - // require.NotEmpty(t, msg.Contents, "want a non-empty message") - body := normalizeGoldenEmail([]byte(msg.Contents)) err = smtpManager.Stop(ctx)