Skip to content

fix(coderd/notifications): simplify TemplateWorkspaceManualBuildFailed #15067

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(coderd/notifications): improve TemplateDeleted notification wording
  • Loading branch information
SasSwart committed Oct 15, 2024
commit 89bed47afdd05ffba7ab45dbebdcb64c5cfde551
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ SET
E'The workspace build was initiated by **{{.Labels.initiator}}**.'
WHERE
id = '2faeee0f-26cb-4e96-821c-85ccb9f71513';

UPDATE notification_templates
SET
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}}**.'
WHERE
id = '29a09665-2a4c-403f-9648-54301670e7be';
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
UPDATE notification_templates
SET
body_template = E'Hi {{.UserName}},\n\n' ||
-- Revert to a single label for the template name.:
-- Revert to a single label for the template name:
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 = E'Hi {{.UserName}},\n\n' ||
-- Revert to a single label for the template name:
E'The template **{{.Labels.name}}** was deleted by **{{ .Labels.initiator }}**.\n\n'
WHERE
id = '29a09665-2a4c-403f-9648-54301670e7be';
5 changes: 2 additions & 3 deletions coderd/notifications/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,8 @@ func TestNotificationTemplates_Golden(t *testing.T) {
UserEmail: "bobby@coder.com",
UserUsername: "bobby",
Labels: map[string]string{
"name": "bobby-template",
"display_name": "Bobby's Template",
"initiator": "rob",
"name": "Bobby's Template",
"initiator": "rob",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
From: system@coder.com
To: bobby@coder.com
Subject: Template "bobby-template" deleted
Subject: Template "Bobby's 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
Expand All @@ -12,9 +12,7 @@ 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.
The template Bobby's Template was deleted by rob.


View templates: http://test.com/templates
Expand All @@ -29,7 +27,7 @@ Content-Type: text/html; charset=UTF-8
<meta charset=3D"UTF-8" />
<meta name=3D"viewport" content=3D"width=3Ddevice-width, initial-scale=
=3D1.0" />
<title>Template "bobby-template" deleted</title>
<title>Template "Bobby's Template" deleted</title>
</head>
<body style=3D"margin: 0; padding: 0; font-family: -apple-system, system-=
ui, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarel=
Expand All @@ -44,16 +42,13 @@ er Logo" style=3D"height: 40px;" />
</div>
<h1 style=3D"text-align: center; font-size: 24px; font-weight: 400; m=
argin: 8px 0 32px; line-height: 1.5;">
Template "bobby-template" deleted
Template "Bobby's Template" deleted
</h1>
<div style=3D"line-height: 1.5;">
<p>Hi Bobby,</p>

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

<p>The template&rsquo;s display name was <strong>Bobby&rsquo;s Template</st=
rong>.</p>
<p>The template <strong>Bobby&rsquo;s Template</strong> was deleted by <str=
ong>rob</strong>.</p>
</div>
<div style=3D"text-align: center; margin-top: 32px;">
=20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
}
],
"labels": {
"display_name": "Bobby's Template",
"initiator": "rob",
"name": "bobby-template"
"name": "Bobby's 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**."
"title": "Template \"Bobby's Template\" deleted",
"title_markdown": "Template \"Bobby's Template\" deleted",
"body": "Hi Bobby,\n\nThe template Bobby's Template was deleted by rob.",
"body_markdown": "Hi Bobby,\n\nThe template **Bobby's Template** was deleted by **rob**.\n\n"
}
9 changes: 5 additions & 4 deletions coderd/provisionerdserver/provisionerdserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1124,17 +1124,18 @@ func (s *server) notifyWorkspaceManualBuildFailed(ctx context.Context, workspace
}

for _, templateAdmin := range templateAdmins {
templateNameLabel := template.DisplayName
if templateNameLabel == "" {
templateNameLabel = template.Name
}
labels := map[string]string{
"name": workspace.Name,
"template_name": template.DisplayName,
"template_name": templateNameLabel,
"template_version_name": templateVersion.Name,
"initiator": build.InitiatorByUsername,
"workspace_owner_username": workspaceOwner.Username,
"workspace_build_number": strconv.Itoa(int(build.BuildNumber)),
}
if template.DisplayName == "" {
labels["template_name"] = template.Name
}
if _, err := s.NotificationsEnqueuer.Enqueue(ctx, templateAdmin.ID, notifications.TemplateWorkspaceManualBuildFailed,
labels, "provisionerdserver",
// Associate this notification with all the related entities.
Expand Down
10 changes: 7 additions & 3 deletions coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,15 @@ func (api *API) notifyTemplateDeleted(ctx context.Context, template database.Tem
return
}

templateNameLabel := template.DisplayName
if templateNameLabel == "" {
templateNameLabel = template.Name
}

if _, err := api.NotificationsEnqueuer.Enqueue(ctx, receiverID, notifications.TemplateTemplateDeleted,
map[string]string{
"name": template.Name,
"display_name": template.DisplayName,
"initiator": initiator.Username,
"name": templateNameLabel,
"initiator": initiator.Username,
}, "api-templates-delete",
// Associate this notification with all the related entities.
template.ID, template.OrganizationID,
Expand Down
3 changes: 1 addition & 2 deletions coderd/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1456,8 +1456,7 @@ func TestTemplateNotifications(t *testing.T) {
require.Contains(t, notifiedUsers, n.UserID)
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["name"], template.DisplayName)
require.Equal(t, n.Labels["initiator"], coderdtest.FirstUserParams.Username)
}
})
Expand Down