fix: ensure targets are propagated to inbox (#16985)

Currently the `targets` column in `inbox_notifications` doesn't get
filled. This PR fixes that. Rather than give targets special treatment,
we should put it in the payload like everything else. This correctly
propagates notification targets to the inbox table without much code
change.
This commit is contained in:
Danielle Maywood
2025-03-19 09:51:49 +00:00
committed by GitHub
parent 995e9402b4
commit ef62e626c8
27 changed files with 38 additions and 36 deletions

View File

@ -3804,7 +3804,6 @@ SELECT
nm.method,
nm.attempt_count::int AS attempt_count,
nm.queued_seconds::float AS queued_seconds,
nm.targets,
-- template
nt.id AS template_id,
nt.title_template,
@ -3830,7 +3829,6 @@ type AcquireNotificationMessagesRow struct {
Method NotificationMethod `db:"method" json:"method"`
AttemptCount int32 `db:"attempt_count" json:"attempt_count"`
QueuedSeconds float64 `db:"queued_seconds" json:"queued_seconds"`
Targets []uuid.UUID `db:"targets" json:"targets"`
TemplateID uuid.UUID `db:"template_id" json:"template_id"`
TitleTemplate string `db:"title_template" json:"title_template"`
BodyTemplate string `db:"body_template" json:"body_template"`
@ -3867,7 +3865,6 @@ func (q *sqlQuerier) AcquireNotificationMessages(ctx context.Context, arg Acquir
&i.Method,
&i.AttemptCount,
&i.QueuedSeconds,
pq.Array(&i.Targets),
&i.TemplateID,
&i.TitleTemplate,
&i.BodyTemplate,

View File

@ -84,7 +84,6 @@ SELECT
nm.method,
nm.attempt_count::int AS attempt_count,
nm.queued_seconds::float AS queued_seconds,
nm.targets,
-- template
nt.id AS template_id,
nt.title_template,

View File

@ -74,7 +74,7 @@ func (s *StoreEnqueuer) EnqueueWithData(ctx context.Context, userID, templateID
dispatchMethod = metadata.CustomMethod.NotificationMethod
}
payload, err := s.buildPayload(metadata, labels, data)
payload, err := s.buildPayload(metadata, labels, data, targets)
if err != nil {
s.log.Warn(ctx, "failed to build payload", slog.F("template_id", templateID), slog.F("user_id", userID), slog.Error(err))
return nil, xerrors.Errorf("enqueue notification (payload build): %w", err)
@ -132,9 +132,9 @@ func (s *StoreEnqueuer) EnqueueWithData(ctx context.Context, userID, templateID
// buildPayload creates the payload that the notification will for variable substitution and/or routing.
// The payload contains information about the recipient, the event that triggered the notification, and any subsequent
// actions which can be taken by the recipient.
func (s *StoreEnqueuer) buildPayload(metadata database.FetchNewMessageMetadataRow, labels map[string]string, data map[string]any) (*types.MessagePayload, error) {
func (s *StoreEnqueuer) buildPayload(metadata database.FetchNewMessageMetadataRow, labels map[string]string, data map[string]any, targets []uuid.UUID) (*types.MessagePayload, error) {
payload := types.MessagePayload{
Version: "1.1",
Version: "1.2",
NotificationName: metadata.NotificationName,
NotificationTemplateID: metadata.NotificationTemplateID.String(),
@ -144,8 +144,9 @@ func (s *StoreEnqueuer) buildPayload(metadata database.FetchNewMessageMetadataRo
UserName: metadata.UserName,
UserUsername: metadata.UserUsername,
Labels: labels,
Data: data,
Labels: labels,
Data: data,
Targets: targets,
// No actions yet
}

View File

@ -1333,7 +1333,6 @@ func TestNotificationTemplates_Golden(t *testing.T) {
)
require.NoError(t, err)
tc.payload.Targets = append(tc.payload.Targets, user.ID)
_, err = smtpEnqueuer.EnqueueWithData(
ctx,
user.ID,
@ -1466,7 +1465,7 @@ func TestNotificationTemplates_Golden(t *testing.T) {
tc.payload.Labels,
tc.payload.Data,
user.Username,
user.ID,
tc.payload.Targets...,
)
require.NoError(t, err)

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Template Deleted",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Template Deprecated",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Test Notification",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "User account activated",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "User account created",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "User account deleted",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "User account suspended",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "One-Time Passcode",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Updated Automatically",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Autobuild Failed",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",
@ -20,7 +20,10 @@
"reason": "autostart"
},
"data": null,
"targets": null
"targets": [
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000"
]
},
"title": "Workspace \"bobby-workspace\" autobuild failed",
"title_markdown": "Workspace \"bobby-workspace\" autobuild failed",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Report: Workspace Builds Failed For Template",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Created",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Deleted",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",
@ -25,7 +25,10 @@
"reason": "autodeleted due to dormancy"
},
"data": null,
"targets": null
"targets": [
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000"
]
},
"title": "Workspace \"bobby-workspace\" deleted",
"title_markdown": "Workspace \"bobby-workspace\" deleted",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Deleted",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Marked as Dormant",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Manual Build Failed",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Manually Updated",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Marked for Deletion",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Out Of Disk",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Out Of Disk",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Workspace Out Of Memory",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Your account has been activated",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",

View File

@ -2,7 +2,7 @@
"_version": "1.1",
"msg_id": "00000000-0000-0000-0000-000000000000",
"payload": {
"_version": "1.1",
"_version": "1.2",
"notification_name": "Your account has been suspended",
"notification_template_id": "00000000-0000-0000-0000-000000000000",
"user_id": "00000000-0000-0000-0000-000000000000",