Skip to content

Commit a17381f

Browse files
committed
Pass extra data to template
1 parent 898014c commit a17381f

File tree

5 files changed

+53
-21
lines changed

5 files changed

+53
-21
lines changed

coderd/notifications/dispatch/smtp/html.gotmpl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
.logo {
2828
width: 60px;
29+
display: block;
30+
margin: auto;
2931
}
3032

3133
.title {
@@ -82,9 +84,16 @@
8284

8385
<div class="footer">
8486
<!-- TODO: dynamic copyright -->
85-
<p>&copy; 2024 Coder. All rights reserved.</p>
8687
<p>
87-
<a href="" class="link"
88+
&copy; {{ .Labels._year }} Coder. All rights reserved -
89+
<a
90+
href="{{ .Labels._accessURL }}"
91+
class="link"
92+
>{{ .Labels._accessURL }}</a
93+
>
94+
</p>
95+
<p>
96+
<a href="{{ .Labels._accessURL }}/settings/notifications" class="link"
8897
>Click here to manage your notification settings</a
8998
>
9099
</p>

coderd/notifications/dispatch/smtp_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,9 @@ func TestSMTP(t *testing.T) {
416416
var hp serpent.HostPort
417417
require.NoError(t, hp.Set(listen.Addr().String()))
418418
tc.cfg.Smarthost = hp
419+
accessURL := "http://localhost:8080"
419420

420-
handler := dispatch.NewSMTPHandler(tc.cfg, logger.Named("smtp"))
421+
handler := dispatch.NewSMTPHandler(tc.cfg, accessURL, logger.Named("smtp"))
421422

422423
// Start mock SMTP server in the background.
423424
var wg sync.WaitGroup

coderd/notifications/manager_test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ func TestBufferedUpdates(t *testing.T) {
3434
cfg.StoreSyncInterval = serpent.Duration(time.Hour) // Ensure we don't sync the store automatically.
3535

3636
// GIVEN: a manager which will pass or fail notifications based on their "nice" labels
37-
mgr, err := notifications.NewManager(cfg, interceptor, createMetrics(), logger.Named("notifications-manager"))
37+
accessURL := "http://localhost:8080"
38+
mgr, err := notifications.NewManager(cfg, interceptor, accessURL, createMetrics(), logger.Named("notifications-manager"))
3839
require.NoError(t, err)
3940
mgr.WithHandlers(map[database.NotificationMethod]notifications.Handler{
4041
database.NotificationMethodSmtp: santa,
@@ -150,7 +151,14 @@ func TestStopBeforeRun(t *testing.T) {
150151
ctx, logger, db := setupInMemory(t)
151152

152153
// GIVEN: a standard manager
153-
mgr, err := notifications.NewManager(defaultNotificationsConfig(database.NotificationMethodSmtp), db, createMetrics(), logger.Named("notifications-manager"))
154+
accessURL := "http://localhost:8080"
155+
mgr, err := notifications.NewManager(
156+
defaultNotificationsConfig(database.NotificationMethodSmtp),
157+
db,
158+
accessURL,
159+
createMetrics(),
160+
logger.Named("notifications-manager"),
161+
)
154162
require.NoError(t, err)
155163

156164
// THEN: validate that the manager can be stopped safely without Run() having been called yet

coderd/notifications/metrics_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ func TestMetrics(t *testing.T) {
5151
cfg.RetryInterval = serpent.Duration(time.Millisecond * 50)
5252
cfg.StoreSyncInterval = serpent.Duration(time.Millisecond * 100) // Twice as long as fetch interval to ensure we catch pending updates.
5353

54-
mgr, err := notifications.NewManager(cfg, store, metrics, logger.Named("manager"))
54+
accessURL := "http://localhost:8080"
55+
mgr, err := notifications.NewManager(cfg, store, accessURL, metrics, logger.Named("manager"))
5556
require.NoError(t, err)
5657
t.Cleanup(func() {
5758
assert.NoError(t, mgr.Stop(ctx))
@@ -218,7 +219,8 @@ func TestPendingUpdatesMetric(t *testing.T) {
218219

219220
syncer := &syncInterceptor{Store: store}
220221
interceptor := newUpdateSignallingInterceptor(syncer)
221-
mgr, err := notifications.NewManager(cfg, interceptor, metrics, logger.Named("manager"))
222+
accessURL := "http://localhost:8080"
223+
mgr, err := notifications.NewManager(cfg, interceptor, accessURL, metrics, logger.Named("manager"))
222224
require.NoError(t, err)
223225
t.Cleanup(func() {
224226
assert.NoError(t, mgr.Stop(ctx))
@@ -292,7 +294,8 @@ func TestInflightDispatchesMetric(t *testing.T) {
292294
cfg.RetryInterval = serpent.Duration(time.Hour) // Delay retries so they don't interfere.
293295
cfg.StoreSyncInterval = serpent.Duration(time.Millisecond * 100)
294296

295-
mgr, err := notifications.NewManager(cfg, store, metrics, logger.Named("manager"))
297+
accessURL := "http://localhost:8080"
298+
mgr, err := notifications.NewManager(cfg, store, accessURL, metrics, logger.Named("manager"))
296299
require.NoError(t, err)
297300
t.Cleanup(func() {
298301
assert.NoError(t, mgr.Stop(ctx))
@@ -371,7 +374,8 @@ func TestCustomMethodMetricCollection(t *testing.T) {
371374

372375
// WHEN: two notifications (each with different templates) are enqueued.
373376
cfg := defaultNotificationsConfig(defaultMethod)
374-
mgr, err := notifications.NewManager(cfg, store, metrics, logger.Named("manager"))
377+
accessURL := "http://localhost:8080"
378+
mgr, err := notifications.NewManager(cfg, store, accessURL, metrics, logger.Named("manager"))
375379
require.NoError(t, err)
376380
t.Cleanup(func() {
377381
assert.NoError(t, mgr.Stop(ctx))

coderd/notifications/notifications_test.go

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ func TestBasicNotificationRoundtrip(t *testing.T) {
6565
interceptor := &syncInterceptor{Store: db}
6666
cfg := defaultNotificationsConfig(method)
6767
cfg.RetryInterval = serpent.Duration(time.Hour) // Ensure retries don't interfere with the test
68-
mgr, err := notifications.NewManager(cfg, interceptor, createMetrics(), logger.Named("manager"))
68+
accessURL := "http://localhost:8080"
69+
mgr, err := notifications.NewManager(cfg, interceptor, accessURL, createMetrics(), logger.Named("manager"))
6970
require.NoError(t, err)
7071
mgr.WithHandlers(map[database.NotificationMethod]notifications.Handler{method: handler})
7172
t.Cleanup(func() {
@@ -138,8 +139,9 @@ func TestSMTPDispatch(t *testing.T) {
138139
Smarthost: serpent.HostPort{Host: "localhost", Port: fmt.Sprintf("%d", mockSMTPSrv.PortNumber())},
139140
Hello: "localhost",
140141
}
141-
handler := newDispatchInterceptor(dispatch.NewSMTPHandler(cfg.SMTP, logger.Named("smtp")))
142-
mgr, err := notifications.NewManager(cfg, db, createMetrics(), logger.Named("manager"))
142+
accessURL := "http://localhost:8080"
143+
handler := newDispatchInterceptor(dispatch.NewSMTPHandler(cfg.SMTP, accessURL, logger.Named("smtp")))
144+
mgr, err := notifications.NewManager(cfg, db, accessURL, createMetrics(), logger.Named("manager"))
143145
require.NoError(t, err)
144146
mgr.WithHandlers(map[database.NotificationMethod]notifications.Handler{method: handler})
145147
t.Cleanup(func() {
@@ -200,7 +202,8 @@ func TestWebhookDispatch(t *testing.T) {
200202
cfg.Webhook = codersdk.NotificationsWebhookConfig{
201203
Endpoint: *serpent.URLOf(endpoint),
202204
}
203-
mgr, err := notifications.NewManager(cfg, db, createMetrics(), logger.Named("manager"))
205+
accessURL := "http://localhost:8080"
206+
mgr, err := notifications.NewManager(cfg, db, accessURL, createMetrics(), logger.Named("manager"))
204207
require.NoError(t, err)
205208
t.Cleanup(func() {
206209
assert.NoError(t, mgr.Stop(ctx))
@@ -298,7 +301,8 @@ func TestBackpressure(t *testing.T) {
298301
storeInterceptor := &syncInterceptor{Store: db}
299302

300303
// GIVEN: a notification manager whose updates will be intercepted
301-
mgr, err := notifications.NewManager(cfg, storeInterceptor, createMetrics(), logger.Named("manager"))
304+
accessURL := "http://localhost:8080"
305+
mgr, err := notifications.NewManager(cfg, storeInterceptor, accessURL, createMetrics(), logger.Named("manager"))
302306
require.NoError(t, err)
303307
mgr.WithHandlers(map[database.NotificationMethod]notifications.Handler{method: handler})
304308
enq, err := notifications.NewStoreEnqueuer(cfg, db, defaultHelpers(), logger.Named("enqueuer"))
@@ -393,7 +397,8 @@ func TestRetries(t *testing.T) {
393397
// Intercept calls to submit the buffered updates to the store.
394398
storeInterceptor := &syncInterceptor{Store: db}
395399

396-
mgr, err := notifications.NewManager(cfg, storeInterceptor, createMetrics(), logger.Named("manager"))
400+
accessURL := "http://localhost:8080"
401+
mgr, err := notifications.NewManager(cfg, storeInterceptor, accessURL, createMetrics(), logger.Named("manager"))
397402
require.NoError(t, err)
398403
t.Cleanup(func() {
399404
assert.NoError(t, mgr.Stop(ctx))
@@ -454,7 +459,8 @@ func TestExpiredLeaseIsRequeued(t *testing.T) {
454459
mgrCtx, cancelManagerCtx := context.WithCancel(context.Background())
455460
t.Cleanup(cancelManagerCtx)
456461

457-
mgr, err := notifications.NewManager(cfg, noopInterceptor, createMetrics(), logger.Named("manager"))
462+
accessURL := "http://localhost:8080"
463+
mgr, err := notifications.NewManager(cfg, noopInterceptor, accessURL, createMetrics(), logger.Named("manager"))
458464
require.NoError(t, err)
459465
enq, err := notifications.NewStoreEnqueuer(cfg, db, defaultHelpers(), logger.Named("enqueuer"))
460466
require.NoError(t, err)
@@ -501,7 +507,7 @@ func TestExpiredLeaseIsRequeued(t *testing.T) {
501507
// Intercept calls to submit the buffered updates to the store.
502508
storeInterceptor := &syncInterceptor{Store: db}
503509
handler := newDispatchInterceptor(&fakeHandler{})
504-
mgr, err = notifications.NewManager(cfg, storeInterceptor, createMetrics(), logger.Named("manager"))
510+
mgr, err = notifications.NewManager(cfg, storeInterceptor, accessURL, createMetrics(), logger.Named("manager"))
505511
require.NoError(t, err)
506512
mgr.WithHandlers(map[database.NotificationMethod]notifications.Handler{method: handler})
507513

@@ -542,7 +548,8 @@ func TestInvalidConfig(t *testing.T) {
542548
cfg.DispatchTimeout = serpent.Duration(leasePeriod)
543549

544550
// WHEN: the manager is created with invalid config
545-
_, err := notifications.NewManager(cfg, db, createMetrics(), logger.Named("manager"))
551+
accessURL := "http://localhost:8080"
552+
_, err := notifications.NewManager(cfg, db, accessURL, createMetrics(), logger.Named("manager"))
546553

547554
// THEN: the manager will fail to be created, citing invalid config as error
548555
require.ErrorIs(t, err, notifications.ErrInvalidDispatchTimeout)
@@ -560,7 +567,8 @@ func TestNotifierPaused(t *testing.T) {
560567
user := createSampleUser(t, db)
561568

562569
cfg := defaultNotificationsConfig(method)
563-
mgr, err := notifications.NewManager(cfg, db, createMetrics(), logger.Named("manager"))
570+
accessURL := "http://localhost:8080"
571+
mgr, err := notifications.NewManager(cfg, db, accessURL, createMetrics(), logger.Named("manager"))
564572
require.NoError(t, err)
565573
mgr.WithHandlers(map[database.NotificationMethod]notifications.Handler{method: handler})
566574
t.Cleanup(func() {
@@ -830,8 +838,9 @@ func TestDisabledAfterEnqueue(t *testing.T) {
830838

831839
method := database.NotificationMethodSmtp
832840
cfg := defaultNotificationsConfig(method)
841+
accessURL := "http://localhost:8080"
833842

834-
mgr, err := notifications.NewManager(cfg, db, createMetrics(), logger.Named("manager"))
843+
mgr, err := notifications.NewManager(cfg, db, accessURL, createMetrics(), logger.Named("manager"))
835844
require.NoError(t, err)
836845
t.Cleanup(func() {
837846
assert.NoError(t, mgr.Stop(ctx))
@@ -937,7 +946,8 @@ func TestCustomNotificationMethod(t *testing.T) {
937946
Endpoint: *serpent.URLOf(endpoint),
938947
}
939948

940-
mgr, err := notifications.NewManager(cfg, db, createMetrics(), logger.Named("manager"))
949+
accessURL := "http://localhost:8080"
950+
mgr, err := notifications.NewManager(cfg, db, accessURL, createMetrics(), logger.Named("manager"))
941951
require.NoError(t, err)
942952
t.Cleanup(func() {
943953
_ = mgr.Stop(ctx)

0 commit comments

Comments
 (0)