Skip to content

Commit a42f108

Browse files
committed
feat(notifications): add company logo url when available for email notifications
1 parent 416d67b commit a42f108

File tree

6 files changed

+24
-4
lines changed

6 files changed

+24
-4
lines changed

coderd/database/models.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/notifications/dispatch/smtp/html.gotmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<body style="margin: 0; padding: 0; font-family: -apple-system, system-ui, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; color: #020617; background: #f8fafc;">
99
<div style="max-width: 600px; margin: 20px auto; padding: 60px; border: 1px solid #e2e8f0; border-radius: 8px; background-color: #fff; text-align: left; font-size: 14px; line-height: 1.5;">
1010
<div style="text-align: center;">
11-
<img src="https://coder.com/coder-logo-horizontal.png" alt="Coder Logo" style="height: 40px;" />
11+
<img src="{{ .Labels._logo_url }}" alt="Company Logo" style="height: 40px;" />
1212
</div>
1313
<h1 style="text-align: center; font-size: 24px; font-weight: 400; margin: 8px 0 32px; line-height: 1.5;">
1414
{{ .Labels._subject }}

coderd/notifications/notifier.go

+18
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package notifications
22

33
import (
44
"context"
5+
"database/sql"
56
"encoding/json"
7+
"errors"
68
"sync"
79
"text/template"
810

@@ -22,6 +24,10 @@ import (
2224
"github.com/coder/coder/v2/coderd/database"
2325
)
2426

27+
const (
28+
notificationsDefaultLogoURL = "https://coder.com/coder-logo-horizontal.png"
29+
)
30+
2531
// notifier is a consumer of the notifications_messages queue. It dequeues messages from that table and processes them
2632
// through a pipeline of fetch -> prepare -> render -> acquire handler -> deliver.
2733
type notifier struct {
@@ -223,6 +229,18 @@ func (n *notifier) prepare(ctx context.Context, msg database.AcquireNotification
223229
return nil, xerrors.Errorf("failed to resolve handler %q", msg.Method)
224230
}
225231

232+
logoURL, err := n.store.GetLogoURL(ctx)
233+
if err != nil && !errors.Is(err, sql.ErrNoRows) {
234+
n.log.Error(ctx, "failed fetching logo url", slog.Error(err))
235+
}
236+
237+
if logoURL == "" {
238+
//nolint:ineffassign // define to default value if unable to fetch one from db
239+
logoURL = notificationsDefaultLogoURL
240+
}
241+
242+
payload.Labels["_logo_url"] = logoURL
243+
226244
var title, body string
227245
if title, err = render.GoTemplate(msg.TitleTemplate, payload, n.helpers); err != nil {
228246
return nil, xerrors.Errorf("render title: %w", err)

coderd/notifications/spec.go

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type Store interface {
2222
FetchNewMessageMetadata(ctx context.Context, arg database.FetchNewMessageMetadataParams) (database.FetchNewMessageMetadataRow, error)
2323
GetNotificationMessagesByStatus(ctx context.Context, arg database.GetNotificationMessagesByStatusParams) ([]database.NotificationMessage, error)
2424
GetNotificationsSettings(ctx context.Context) (string, error)
25+
26+
GetLogoURL(ctx context.Context) (string, error)
2527
}
2628

2729
// Handler is responsible for preparing and delivering a notification by a given method.

0 commit comments

Comments
 (0)