-
Notifications
You must be signed in to change notification settings - Fork 982
feat(coderd): add company logo when available for email notifications #14935
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
Changes from 1 commit
a42f108
1fa1271
2def52e
1b1a4c4
779260e
1e6899f
b552267
73e07e9
70e23ae
2f620c9
fdcdf7b
9c6c105
0c131a5
34d6611
0a9a66a
bf558cb
a420f37
51d8d33
d492d09
0c9c485
a6d4a0c
4c5cb3d
e419431
a7fec66
8b766f6
157e086
790ff33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…tifications
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ package notifications | |
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"encoding/json" | ||
"errors" | ||
"sync" | ||
"text/template" | ||
|
||
|
@@ -22,6 +24,10 @@ import ( | |
"github.com/coder/coder/v2/coderd/database" | ||
) | ||
|
||
const ( | ||
notificationsDefaultLogoURL = "https://coder.com/coder-logo-horizontal.png" | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
// notifier is a consumer of the notifications_messages queue. It dequeues messages from that table and processes them | ||
// through a pipeline of fetch -> prepare -> render -> acquire handler -> deliver. | ||
type notifier struct { | ||
|
@@ -223,6 +229,18 @@ func (n *notifier) prepare(ctx context.Context, msg database.AcquireNotification | |
return nil, xerrors.Errorf("failed to resolve handler %q", msg.Method) | ||
} | ||
|
||
logoURL, err := n.store.GetLogoURL(ctx) | ||
if err != nil && !errors.Is(err, sql.ErrNoRows) { | ||
n.log.Error(ctx, "failed fetching logo url", slog.Error(err)) | ||
dannykopping marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an interesting use case. Some customers prefer to use their company logos instead of Coder default one. I think we should rather fail fast the notifier flow than default to Coder logo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @mtojek @mafredri as you both raised this one. In case of errors I can :
As this situation means that we had a failure fetching data from the db, I don't know what is the preferred solution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be an option to make it less awkward: #14935 (comment) ... and just retry. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Errors in retrieving the data from the db will cause the notification to fail, and it'll be automatically retried later. |
||
} | ||
|
||
if logoURL == "" { | ||
//nolint:ineffassign // define to default value if unable to fetch one from db | ||
defelmnq marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logoURL = notificationsDefaultLogoURL | ||
} | ||
|
||
payload.Labels["_logo_url"] = logoURL | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking loud: Logo URL does not seem to be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @mtojek here. I don't think this should go into the payload. It's going to be the same for every notification, and if it's in the payload then we'll be storing the same URL for every notification. Have a look at // templateHelpers builds a set of functions which can be called in templates.
// We build them here to avoid an import cycle by using coderd.Options in notifications.Manager.
// We can later use this to inject whitelabel fields when app name / logo URL are overridden. <----
func templateHelpers(options *coderd.Options) map[string]any {
return map[string]any{
"base_url": func() string { return options.AccessURL.String() },
"current_year": func() string { return strconv.Itoa(time.Now().Year()) },
}
} We should create a new helper which retrieves the logo instead, I think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, indeed it makes complete sense 🙏 I modified the approach to have both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super 👍 |
||
|
||
var title, body string | ||
if title, err = render.GoTemplate(msg.TitleTemplate, payload, n.helpers); err != nil { | ||
return nil, xerrors.Errorf("render title: %w", err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we present also the company name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤓 Will add it and present some screenshots so we can iterate with the name.