feat: turn off notification via email (#14520)

This commit is contained in:
Joobi S B
2024-09-11 11:10:24 -03:00
committed by GitHub
parent 5bd19f8ba3
commit 3301212972
9 changed files with 153 additions and 14 deletions
+10 -7
View File
@@ -3499,6 +3499,7 @@ func (q *sqlQuerier) EnqueueNotificationMessage(ctx context.Context, arg Enqueue
const fetchNewMessageMetadata = `-- name: FetchNewMessageMetadata :one
SELECT nt.name AS notification_name,
nt.id AS notification_template_id,
nt.actions AS actions,
nt.method AS custom_method,
u.id AS user_id,
@@ -3517,13 +3518,14 @@ type FetchNewMessageMetadataParams struct {
}
type FetchNewMessageMetadataRow struct {
NotificationName string `db:"notification_name" json:"notification_name"`
Actions []byte `db:"actions" json:"actions"`
CustomMethod NullNotificationMethod `db:"custom_method" json:"custom_method"`
UserID uuid.UUID `db:"user_id" json:"user_id"`
UserEmail string `db:"user_email" json:"user_email"`
UserName string `db:"user_name" json:"user_name"`
UserUsername string `db:"user_username" json:"user_username"`
NotificationName string `db:"notification_name" json:"notification_name"`
NotificationTemplateID uuid.UUID `db:"notification_template_id" json:"notification_template_id"`
Actions []byte `db:"actions" json:"actions"`
CustomMethod NullNotificationMethod `db:"custom_method" json:"custom_method"`
UserID uuid.UUID `db:"user_id" json:"user_id"`
UserEmail string `db:"user_email" json:"user_email"`
UserName string `db:"user_name" json:"user_name"`
UserUsername string `db:"user_username" json:"user_username"`
}
// This is used to build up the notification_message's JSON payload.
@@ -3532,6 +3534,7 @@ func (q *sqlQuerier) FetchNewMessageMetadata(ctx context.Context, arg FetchNewMe
var i FetchNewMessageMetadataRow
err := row.Scan(
&i.NotificationName,
&i.NotificationTemplateID,
&i.Actions,
&i.CustomMethod,
&i.UserID,
@@ -1,6 +1,7 @@
-- name: FetchNewMessageMetadata :one
-- This is used to build up the notification_message's JSON payload.
SELECT nt.name AS notification_name,
nt.id AS notification_template_id,
nt.actions AS actions,
nt.method AS custom_method,
u.id AS user_id,
@@ -26,6 +26,7 @@
<div style="border-top: 1px solid #e2e8f0; color: #475569; font-size: 12px; margin-top: 64px; padding-top: 24px; line-height: 1.6;">
<p>&copy;&nbsp;{{ current_year }}&nbsp;Coder. All rights reserved&nbsp;-&nbsp;<a href="{{ base_url }}" style="color: #2563eb; text-decoration: none;">{{ base_url }}</a></p>
<p><a href="{{ base_url }}/settings/notifications" style="color: #2563eb; text-decoration: none;">Click here to manage your notification settings</a></p>
<p><a href="{{ base_url }}/settings/notifications?disabled={{ .NotificationTemplateID }}" style="color: #2563eb; text-decoration: none;">Stop receiving emails like this</a></p>
</div>
</div>
</body>
+3 -2
View File
@@ -121,9 +121,10 @@ func (s *StoreEnqueuer) Enqueue(ctx context.Context, userID, templateID uuid.UUI
// actions which can be taken by the recipient.
func (s *StoreEnqueuer) buildPayload(metadata database.FetchNewMessageMetadataRow, labels map[string]string) (*types.MessagePayload, error) {
payload := types.MessagePayload{
Version: "1.0",
Version: "1.1",
NotificationName: metadata.NotificationName,
NotificationName: metadata.NotificationName,
NotificationTemplateID: metadata.NotificationTemplateID.String(),
UserID: metadata.UserID.String(),
UserEmail: metadata.UserEmail,
@@ -56,6 +56,15 @@ func TestGoTemplate(t *testing.T) {
"url": "https://mocked-server-address/@johndoe/my-workspace"
}]`,
},
{
name: "render notification template ID",
in: `{{ .NotificationTemplateID }}`,
payload: types.MessagePayload{
NotificationTemplateID: "4e19c0ac-94e1-4532-9515-d1801aa283b2",
},
expectedOutput: "4e19c0ac-94e1-4532-9515-d1801aa283b2",
expectedErr: nil,
},
}
for _, tc := range tests {
+2 -1
View File
@@ -7,7 +7,8 @@ package types
type MessagePayload struct {
Version string `json:"_version"`
NotificationName string `json:"notification_name"`
NotificationName string `json:"notification_name"`
NotificationTemplateID string `json:"notification_template_id"`
UserID string `json:"user_id"`
UserEmail string `json:"user_email"`