From 5c8da81107680ec64d68368548e14ab5a0818aab Mon Sep 17 00:00:00 2001
From: defelmnq
Date: Mon, 24 Mar 2025 23:23:13 +0000
Subject: [PATCH 1/5] fix notifications actions url
---
coderd/workspacebuilds.go | 11 ++++++-----
coderd/workspaces.go | 7 ++++---
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/coderd/workspacebuilds.go b/coderd/workspacebuilds.go
index 735d6025dd16f..23a65228eed6f 100644
--- a/coderd/workspacebuilds.go
+++ b/coderd/workspacebuilds.go
@@ -517,11 +517,12 @@ func (api *API) notifyWorkspaceUpdated(
receiverID,
notifications.TemplateWorkspaceManuallyUpdated,
map[string]string{
- "organization": template.OrganizationName,
- "initiator": initiator.Name,
- "workspace": workspace.Name,
- "template": template.Name,
- "version": version.Name,
+ "organization": template.OrganizationName,
+ "initiator": initiator.Name,
+ "workspace": workspace.Name,
+ "template": template.Name,
+ "version": version.Name,
+ "workspace_owner_username": owner.Username,
},
map[string]any{
"workspace": map[string]any{"id": workspace.ID, "name": workspace.Name},
diff --git a/coderd/workspaces.go b/coderd/workspaces.go
index 7a64648033c79..7022938062c64 100644
--- a/coderd/workspaces.go
+++ b/coderd/workspaces.go
@@ -801,9 +801,10 @@ func (api *API) notifyWorkspaceCreated(
receiverID,
notifications.TemplateWorkspaceCreated,
map[string]string{
- "workspace": workspace.Name,
- "template": template.Name,
- "version": version.Name,
+ "workspace": workspace.Name,
+ "template": template.Name,
+ "version": version.Name,
+ "workspace_owner_username": owner.Username,
},
map[string]any{
"workspace": map[string]any{"id": workspace.ID, "name": workspace.Name},
From 7e4b164051b865f203f47b8bbfbbff63ece185d0 Mon Sep 17 00:00:00 2001
From: defelmnq
Date: Mon, 24 Mar 2025 23:39:26 +0000
Subject: [PATCH 2/5] add migration files
---
...307_fix_notifications_actions_url.down.sql | 22 +++++++++++++++++++
...00307_fix_notifications_actions_url.up.sql | 22 +++++++++++++++++++
2 files changed, 44 insertions(+)
create mode 100644 coderd/database/migrations/000307_fix_notifications_actions_url.down.sql
create mode 100644 coderd/database/migrations/000307_fix_notifications_actions_url.up.sql
diff --git a/coderd/database/migrations/000307_fix_notifications_actions_url.down.sql b/coderd/database/migrations/000307_fix_notifications_actions_url.down.sql
new file mode 100644
index 0000000000000..c6f382d276cab
--- /dev/null
+++ b/coderd/database/migrations/000307_fix_notifications_actions_url.down.sql
@@ -0,0 +1,22 @@
+UPDATE notification_templates
+SET
+ actions = '[
+ {
+ "label": "View workspace",
+ "url": "{{base_url}}/@{{.UserUsername}}/{{.Labels.workspace}}"
+ }
+ ]'::jsonb
+WHERE id = '281fdf73-c6d6-4cbb-8ff5-888baf8a2fff';
+
+UPDATE notification_templates
+SET
+ actions = '[
+ {
+ "label": "View workspace",
+ "url": "{{base_url}}/@{{.UserUsername}}/{{.Labels.workspace}}"
+ },
+ {
+ "label": "View template version",
+ "url": "{{base_url}}/templates/{{.Labels.organization}}/{{.Labels.template}}/versions/{{.Labels.version}}"
+ }
+ ]'::jsonb WHERE id = 'd089fe7b-d5c5-4c0c-aaf5-689859f7d392';
diff --git a/coderd/database/migrations/000307_fix_notifications_actions_url.up.sql b/coderd/database/migrations/000307_fix_notifications_actions_url.up.sql
new file mode 100644
index 0000000000000..e342340d2eb0e
--- /dev/null
+++ b/coderd/database/migrations/000307_fix_notifications_actions_url.up.sql
@@ -0,0 +1,22 @@
+UPDATE notification_templates
+SET
+ actions = '[
+ {
+ "label": "View workspace",
+ "url": "{{base_url}}/@{{.Labels.workspace_owner_username}}/{{.Labels.workspace}}"
+ }
+ ]'::jsonb
+WHERE id = '281fdf73-c6d6-4cbb-8ff5-888baf8a2fff';
+
+UPDATE notification_templates
+SET
+ actions = '[
+ {
+ "label": "View workspace",
+ "url": "{{base_url}}/@{{.Labels.workspace_owner_username}}/{{.Labels.workspace}}"
+ },
+ {
+ "label": "View template version",
+ "url": "{{base_url}}/templates/{{.Labels.organization}}/{{.Labels.template}}/versions/{{.Labels.version}}"
+ }
+ ]'::jsonb WHERE id = 'd089fe7b-d5c5-4c0c-aaf5-689859f7d392';
From 95396d37e46768860ac6b8485c34775d19622a4c Mon Sep 17 00:00:00 2001
From: defelmnq
Date: Mon, 24 Mar 2025 23:40:11 +0000
Subject: [PATCH 3/5] lint migration files
---
.../migrations/000307_fix_notifications_actions_url.down.sql | 3 ++-
.../migrations/000307_fix_notifications_actions_url.up.sql | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/coderd/database/migrations/000307_fix_notifications_actions_url.down.sql b/coderd/database/migrations/000307_fix_notifications_actions_url.down.sql
index c6f382d276cab..51a0e361dcb8b 100644
--- a/coderd/database/migrations/000307_fix_notifications_actions_url.down.sql
+++ b/coderd/database/migrations/000307_fix_notifications_actions_url.down.sql
@@ -19,4 +19,5 @@ SET
"label": "View template version",
"url": "{{base_url}}/templates/{{.Labels.organization}}/{{.Labels.template}}/versions/{{.Labels.version}}"
}
- ]'::jsonb WHERE id = 'd089fe7b-d5c5-4c0c-aaf5-689859f7d392';
+ ]'::jsonb
+WHERE id = 'd089fe7b-d5c5-4c0c-aaf5-689859f7d392';
diff --git a/coderd/database/migrations/000307_fix_notifications_actions_url.up.sql b/coderd/database/migrations/000307_fix_notifications_actions_url.up.sql
index e342340d2eb0e..f0a14739341b0 100644
--- a/coderd/database/migrations/000307_fix_notifications_actions_url.up.sql
+++ b/coderd/database/migrations/000307_fix_notifications_actions_url.up.sql
@@ -19,4 +19,5 @@ SET
"label": "View template version",
"url": "{{base_url}}/templates/{{.Labels.organization}}/{{.Labels.template}}/versions/{{.Labels.version}}"
}
- ]'::jsonb WHERE id = 'd089fe7b-d5c5-4c0c-aaf5-689859f7d392';
+ ]'::jsonb
+WHERE id = 'd089fe7b-d5c5-4c0c-aaf5-689859f7d392';
From 0b992da8e917779b05668de945c0ebe7442f4ddb Mon Sep 17 00:00:00 2001
From: defelmnq
Date: Mon, 24 Mar 2025 23:56:14 +0000
Subject: [PATCH 4/5] regen golden files
---
coderd/notifications/notifications_test.go | 18 ++++++++++--------
.../smtp/TemplateWorkspaceCreated.html.golden | 4 ++--
...emplateWorkspaceManuallyUpdated.html.golden | 4 ++--
.../TemplateWorkspaceCreated.json.golden | 5 +++--
...emplateWorkspaceManuallyUpdated.json.golden | 5 +++--
5 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go
index d48394771fd8a..b487324490045 100644
--- a/coderd/notifications/notifications_test.go
+++ b/coderd/notifications/notifications_test.go
@@ -1074,9 +1074,10 @@ func TestNotificationTemplates_Golden(t *testing.T) {
UserEmail: "bobby@coder.com",
UserUsername: "bobby",
Labels: map[string]string{
- "workspace": "bobby-workspace",
- "template": "bobby-template",
- "version": "alpha",
+ "workspace": "bobby-workspace",
+ "template": "bobby-template",
+ "version": "alpha",
+ "workspace_owner_username": "Bobby",
},
},
},
@@ -1088,11 +1089,12 @@ func TestNotificationTemplates_Golden(t *testing.T) {
UserEmail: "bobby@coder.com",
UserUsername: "bobby",
Labels: map[string]string{
- "organization": "bobby-organization",
- "initiator": "bobby",
- "workspace": "bobby-workspace",
- "template": "bobby-template",
- "version": "alpha",
+ "organization": "bobby-organization",
+ "initiator": "bobby",
+ "workspace": "bobby-workspace",
+ "template": "bobby-template",
+ "version": "alpha",
+ "workspace_owner_username": "Bobby",
},
},
},
diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceCreated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceCreated.html.golden
index 62ce413e782cc..a2ebbc4e392ba 100644
--- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceCreated.html.golden
+++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceCreated.html.golden
@@ -16,7 +16,7 @@ The workspace bobby-workspace has been created from the template bobby-temp=
late using version alpha.
-View workspace: http://test.com/@bobby/bobby-workspace
+View workspace: http://test.com/@Bobby/bobby-workspace
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
Content-Transfer-Encoding: quoted-printable
@@ -53,7 +53,7 @@ ha.
=20
-
View workspace
diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceCreated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceCreated.json.golden
index 344bafc8150ae..00fb8ebf38586 100644
--- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceCreated.json.golden
+++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceCreated.json.golden
@@ -12,13 +12,14 @@
"actions": [
{
"label": "View workspace",
- "url": "http://test.com/@bobby/bobby-workspace"
+ "url": "http://test.com/@Bobby/bobby-workspace"
}
],
"labels": {
"template": "bobby-template",
"version": "alpha",
- "workspace": "bobby-workspace"
+ "workspace": "bobby-workspace",
+ "workspace_owner_username": "Bobby"
},
"data": null,
"targets": null
diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManuallyUpdated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManuallyUpdated.json.golden
index 0eeeec41dd84f..8ca4acaabc347 100644
--- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManuallyUpdated.json.golden
+++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManuallyUpdated.json.golden
@@ -12,7 +12,7 @@
"actions": [
{
"label": "View workspace",
- "url": "http://test.com/@bobby/bobby-workspace"
+ "url": "http://test.com/@Bobby/bobby-workspace"
},
{
"label": "View template version",
@@ -24,7 +24,8 @@
"organization": "bobby-organization",
"template": "bobby-template",
"version": "alpha",
- "workspace": "bobby-workspace"
+ "workspace": "bobby-workspace",
+ "workspace_owner_username": "Bobby"
},
"data": null,
"targets": null
From ae733968dd98f83f1e52cb56893c14973a16674d Mon Sep 17 00:00:00 2001
From: defelmnq
Date: Tue, 25 Mar 2025 00:07:26 +0000
Subject: [PATCH 5/5] change workspace_owner_username for consisteny
---
coderd/notifications/notifications_test.go | 4 ++--
.../smtp/TemplateWorkspaceCreated.html.golden | 8 ++++----
.../smtp/TemplateWorkspaceManuallyUpdated.html.golden | 8 ++++----
.../webhook/TemplateWorkspaceCreated.json.golden | 4 ++--
.../webhook/TemplateWorkspaceManuallyUpdated.json.golden | 4 ++--
5 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/coderd/notifications/notifications_test.go b/coderd/notifications/notifications_test.go
index b487324490045..57618ceb89d7a 100644
--- a/coderd/notifications/notifications_test.go
+++ b/coderd/notifications/notifications_test.go
@@ -1077,7 +1077,7 @@ func TestNotificationTemplates_Golden(t *testing.T) {
"workspace": "bobby-workspace",
"template": "bobby-template",
"version": "alpha",
- "workspace_owner_username": "Bobby",
+ "workspace_owner_username": "mrbobby",
},
},
},
@@ -1094,7 +1094,7 @@ func TestNotificationTemplates_Golden(t *testing.T) {
"workspace": "bobby-workspace",
"template": "bobby-template",
"version": "alpha",
- "workspace_owner_username": "Bobby",
+ "workspace_owner_username": "mrbobby",
},
},
},
diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceCreated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceCreated.html.golden
index a2ebbc4e392ba..9fccba0b1f239 100644
--- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceCreated.html.golden
+++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceCreated.html.golden
@@ -16,7 +16,7 @@ The workspace bobby-workspace has been created from the template bobby-temp=
late using version alpha.
-View workspace: http://test.com/@Bobby/bobby-workspace
+View workspace: http://test.com/@mrbobby/bobby-workspace
--bbe61b741255b6098bb6b3c1f41b885773df633cb18d2a3002b68e4bc9c4
Content-Transfer-Encoding: quoted-printable
@@ -53,9 +53,9 @@ ha.
=20
-
+
View workspace
=20
diff --git a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManuallyUpdated.html.golden b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManuallyUpdated.html.golden
index a9957ae801db2..0e70293b09065 100644
--- a/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManuallyUpdated.html.golden
+++ b/coderd/notifications/testdata/rendered-templates/smtp/TemplateWorkspaceManuallyUpdated.html.golden
@@ -16,7 +16,7 @@ A new workspace build has been manually created for your workspace bobby-wo=
rkspace by bobby to update it to version alpha of template bobby-template.
-View workspace: http://test.com/@Bobby/bobby-workspace
+View workspace: http://test.com/@mrbobby/bobby-workspace
View template version: http://test.com/templates/bobby-organization/bobby-t=
emplate/versions/alpha
@@ -57,9 +57,9 @@ g>.
=20
-
+
View workspace
=20
diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceCreated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceCreated.json.golden
index 00fb8ebf38586..cbe256fc9c6ea 100644
--- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceCreated.json.golden
+++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceCreated.json.golden
@@ -12,14 +12,14 @@
"actions": [
{
"label": "View workspace",
- "url": "http://test.com/@Bobby/bobby-workspace"
+ "url": "http://test.com/@mrbobby/bobby-workspace"
}
],
"labels": {
"template": "bobby-template",
"version": "alpha",
"workspace": "bobby-workspace",
- "workspace_owner_username": "Bobby"
+ "workspace_owner_username": "mrbobby"
},
"data": null,
"targets": null
diff --git a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManuallyUpdated.json.golden b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManuallyUpdated.json.golden
index 8ca4acaabc347..599ee3c1761c8 100644
--- a/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManuallyUpdated.json.golden
+++ b/coderd/notifications/testdata/rendered-templates/webhook/TemplateWorkspaceManuallyUpdated.json.golden
@@ -12,7 +12,7 @@
"actions": [
{
"label": "View workspace",
- "url": "http://test.com/@Bobby/bobby-workspace"
+ "url": "http://test.com/@mrbobby/bobby-workspace"
},
{
"label": "View template version",
@@ -25,7 +25,7 @@
"template": "bobby-template",
"version": "alpha",
"workspace": "bobby-workspace",
- "workspace_owner_username": "Bobby"
+ "workspace_owner_username": "mrbobby"
},
"data": null,
"targets": null