Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5695d2c

Browse files
committed
feat(notification): move logo_url and app_name logic to helpers functions
1 parent2b76b30 commit5695d2c

File tree

6 files changed

+35
-18
lines changed

6 files changed

+35
-18
lines changed

‎cli/server.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,6 +1309,30 @@ func templateHelpers(options *coderd.Options) map[string]any {
13091309
returnmap[string]any{
13101310
"base_url":func()string {returnoptions.AccessURL.String() },
13111311
"current_year":func()string {returnstrconv.Itoa(time.Now().Year()) },
1312+
"logo_url":func()string {
1313+
logoURL,err:=options.Database.GetLogoURL(context.Background())
1314+
iferr!=nil {
1315+
iferrors.Is(err,sql.ErrNoRows) {
1316+
returnnotifications.NotificationsDefaultLogoURL
1317+
}
1318+
1319+
return""
1320+
}
1321+
1322+
returnlogoURL
1323+
},
1324+
"app_name":func()string {
1325+
appName,err:=options.Database.GetApplicationName(context.Background())
1326+
iferr!=nil {
1327+
iferrors.Is(err,sql.ErrNoRows) {
1328+
returnnotifications.NotificationsDefaultAppName
1329+
}
1330+
1331+
return""
1332+
}
1333+
1334+
returnappName
1335+
},
13121336
}
13131337
}
13141338

‎coderd/notifications/dispatch/smtp/html.gotmpl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
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="{{ .Labels._logo_url }}" alt="Company Logo" style="height: 40px;" />
11+
<img src="{{ logo_url }}" alt="Company Logo" style="height: 40px;" />
12+
<h1 style="text-align: center; font-size: 36px; font-weight: 400; margin: 8px 0 32px; line-height: 1.5;">
13+
{{ app_name }}
14+
</h1>
1215
</div>
1316
<h1 style="text-align: center; font-size: 24px; font-weight: 400; margin: 8px 0 32px; line-height: 1.5;">
1417
{{ .Labels._subject }}

‎coderd/notifications/dispatch/smtp_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ func TestSMTP(t *testing.T) {
447447
helpers:=map[string]any{
448448
"base_url":func()string {return"http://test.com" },
449449
"current_year":func()string {return"2024" },
450+
"logo_url":func()string {return"https://logo.company" },
451+
"app_name":func()string {return"TestCompany" },
450452
}
451453
handler:=dispatch.NewSMTPHandler(tc.cfg,helpers,logger.Named("smtp"))
452454

‎coderd/notifications/notifications_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,8 @@ func TestWebhookDispatch(t *testing.T) {
239239

240240
// WHEN: a notification is enqueued (including arbitrary labels)
241241
input:=map[string]string{
242-
"a":"b",
243-
"c":"d",
244-
"_logo_url":notifications.NotificationsDefaultLogoURL,
242+
"a":"b",
243+
"c":"d",
245244
}
246245
msgID,err:=enq.Enqueue(ctx,user.ID,notifications.TemplateWorkspaceDeleted,input,"test")
247246
require.NoError(t,err)

‎coderd/notifications/notifier.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package notifications
22

33
import (
44
"context"
5-
"database/sql"
65
"encoding/json"
7-
"errors"
86
"sync"
97
"text/template"
108

@@ -26,6 +24,7 @@ import (
2624

2725
const (
2826
NotificationsDefaultLogoURL="https://coder.com/coder-logo-horizontal.png"
27+
NotificationsDefaultAppName="Coder"
2928
)
3029

3130
// notifier is a consumer of the notifications_messages queue. It dequeues messages from that table and processes them
@@ -229,18 +228,6 @@ func (n *notifier) prepare(ctx context.Context, msg database.AcquireNotification
229228
returnnil,xerrors.Errorf("failed to resolve handler %q",msg.Method)
230229
}
231230

232-
logoURL,err:=n.store.GetLogoURL(ctx)
233-
iferr!=nil&&!errors.Is(err,sql.ErrNoRows) {
234-
n.log.Error(ctx,"failed fetching logo url",slog.Error(err))
235-
}
236-
237-
iflogoURL=="" {
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-
244231
vartitle,bodystring
245232
iftitle,err=render.GoTemplate(msg.TitleTemplate,payload,n.helpers);err!=nil {
246233
returnnil,xerrors.Errorf("render title: %w",err)

‎coderd/notifications/utils_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ func defaultHelpers() map[string]any {
3939
returnmap[string]any{
4040
"base_url":func()string {return"http://test.com" },
4141
"current_year":func()string {return"2024" },
42+
"logo_url":func()string {return"https://logo.company" },
43+
"app_name":func()string {return"TestCompany" },
4244
}
4345
}
4446

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp