- Notifications
You must be signed in to change notification settings - Fork929
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 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
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1414,7 +1414,7 @@ | ||
// GIVEN: a notification template which has a method explicitly set | ||
var ( | ||
template = notifications.TemplateWorkspaceDormant | ||
defaultMethod = database.NotificationMethodSmtp | ||
customMethod = database.NotificationMethodWebhook | ||
) | ||
@@ -1562,7 +1562,7 @@ | ||
succeeded, failed []string | ||
} | ||
func (f *fakeHandler) Dispatcher(helpers template.FuncMap, payload types.MessagePayload, _, _ string) (dispatch.DeliveryFunc, error) { | ||
return func(_ context.Context, msgID uuid.UUID) (retryable bool, err error) { | ||
f.mu.Lock() | ||
defer f.mu.Unlock() | ||
@@ -1612,7 +1612,7 @@ | ||
return messages, err | ||
} | ||
funcTestNotificationTemplates_GoldenWithCustomAppearance(t *testing.T) { | ||
t.Parallel() | ||
if !dbtestutil.WillUsePostgres() { | ||
@@ -1629,205 +1629,167 @@ | ||
hint = "run \"DB=ci make update-golden-files\" and commit the changes" | ||
) | ||
var ( | ||
payload = types.MessagePayload{ | ||
Labels: map[string]string{ | ||
"name": "bobby-workspace", | ||
"reason": "autodeleted due to dormancy", | ||
"initiator": "autobuild", | ||
}, | ||
} | ||
) | ||
// Spin up the DB | ||
db, logger, user := func() (database.Store, *slog.Logger, *codersdk.User) { | ||
adminClient, _, api := coderdtest.NewWithAPI(t, nil) | ||
firstUser:=coderdtest.CreateFirstUser(t, adminClient) | ||
_, user := coderdtest.CreateAnotherUserMutators( | ||
t, | ||
adminClient, | ||
firstUser.OrganizationID, | ||
[]rbac.RoleIdentifier{rbac.RoleUserAdmin()}, | ||
func(r *codersdk.CreateUserRequestWithOrgs) { | ||
r.Username = "bobby" | ||
r.Email = "bobby@coder.com" | ||
r.Name = "Bobby" | ||
}, | ||
) | ||
return api.Database, &api.Logger, &user | ||
}() | ||
defelmnq marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
// nolint:gocritic // Unit test. | ||
ctx := dbauthz.AsSystemRestricted(testutil.Context(t, testutil.WaitSuperLong)) | ||
err := db.UpsertApplicationName(ctx, "CustomApplication") | ||
defelmnq marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
require.NoError(t,err) | ||
err = db.UpsertLogoURL(ctx, "https://custom.application") | ||
defelmnq marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
require.NoError(t, err) | ||
// smtp config shared between client and server | ||
smtpConfig := codersdk.NotificationsEmailConfig{ | ||
Hello: hello, | ||
From: from, | ||
Auth: codersdk.NotificationsEmailAuthConfig{ | ||
Username: username, | ||
Password: password, | ||
}, | ||
} | ||
// Spin up the mock SMTP server | ||
backend := smtptest.NewBackend(smtptest.Config{ | ||
AuthMechanisms: []string{sasl.Login}, | ||
AcceptedIdentity: smtpConfig.Auth.Identity.String(), | ||
AcceptedUsername: username, | ||
AcceptedPassword: password, | ||
}) | ||
// Create a mock SMTP server which conditionally listens for plain or TLS connections. | ||
srv, listen, err := smtptest.CreateMockSMTPServer(backend, false) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { | ||
err := srv.Shutdown(ctx) | ||
require.NoError(t, err) | ||
}) | ||
var hp serpent.HostPort | ||
require.NoError(t, hp.Set(listen.Addr().String())) | ||
smtpConfig.Smarthost = hp | ||
// Start mock SMTP server in the background. | ||
var wg sync.WaitGroup | ||
wg.Add(1) | ||
go func() { | ||
defer wg.Done() | ||
assert.NoError(t, srv.Serve(listen)) | ||
}() | ||
// Wait for the server to become pingable. | ||
require.Eventually(t, func() bool { | ||
cl, err := smtptest.PingClient(listen, false, smtpConfig.TLS.StartTLS.Value()) | ||
if err != nil { | ||
t.Logf("smtp not yet dialable: %s", err) | ||
return false | ||
} | ||
if err = cl.Noop(); err != nil { | ||
t.Logf("smtp not yet noopable: %s", err) | ||
return false | ||
} | ||
if err = cl.Close(); err != nil { | ||
t.Logf("smtp didn't close properly: %s", err) | ||
return false | ||
} | ||
return true | ||
}, testutil.WaitShort, testutil.IntervalFast) | ||
smtpCfg := defaultNotificationsConfig(database.NotificationMethodSmtp) | ||
smtpCfg.SMTP = smtpConfig | ||
smtpManager, err := notifications.NewManager( | ||
smtpCfg, | ||
db, | ||
defaultHelpers(), | ||
createMetrics(), | ||
logger.Named("manager"), | ||
) | ||
require.NoError(t, err) | ||
smtpManager.Run(ctx) | ||
notificationCfg := defaultNotificationsConfig(database.NotificationMethodSmtp) | ||
smtpEnqueuer, err := notifications.NewStoreEnqueuer( | ||
notificationCfg, | ||
db, | ||
defaultHelpers(), | ||
logger.Named("enqueuer"), | ||
quartz.NewReal(), | ||
) | ||
require.NoError(t, err) | ||
_, err = smtpEnqueuer.EnqueueWithData( | ||
ctx, | ||
user.ID, | ||
notifications.TemplateWorkspaceDeleted, | ||
payload.Labels, | ||
payload.Data, | ||
user.Username, | ||
user.ID, | ||
) | ||
require.NoError(t, err) | ||
// Wait for the message to be fetched | ||
var msg *smtptest.Message | ||
require.Eventually(t, func() bool { | ||
msg = backend.LastMessage() | ||
return msg != nil && len(msg.Contents) > 0 | ||
}, testutil.WaitShort, testutil.IntervalFast) | ||
body := normalizeGoldenEmail([]byte(msg.Contents)) | ||
err = smtpManager.Stop(ctx) | ||
require.NoError(t, err) | ||
goldenFile := filepath.Join("testdata", "rendered-templates", "smtp", "TemplateWorkspaceDeleted_WithCustomAppearance.html.golden") | ||
defelmnq marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if *updateGoldenFiles { | ||
err = os.MkdirAll(filepath.Dir(goldenFile), 0o755) | ||
require.NoError(t, err, "want no error creating golden file directory") | ||
err = os.WriteFile(goldenFile, body, 0o600) | ||
require.NoError(t, err, "want no error writing body golden file") | ||
} | ||
wantBody, err := os.ReadFile(goldenFile) | ||
require.NoError(t, err, fmt.Sprintf("missing golden notification body file. %s", hint)) | ||
require.Empty( | ||
t, | ||
cmp.Diff(wantBody, body), | ||
fmt.Sprintf("golden file mismatch: %s. If this is expected, %s. (-want +got). ", goldenFile, hint), | ||
) | ||
} |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.