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

Commitc131d01

Browse files
chore: disallow inbox as default method (#17093)
Disallow setting `inbox` as the default notifications method.
1 parentcf10d98 commitc131d01

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

‎coderd/notifications/enqueuer.go‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package notifications
33
import (
44
"context"
55
"encoding/json"
6+
"fmt"
67
"slices"
78
"strings"
89
"text/template"
@@ -25,6 +26,14 @@ var (
2526
ErrDuplicate=xerrors.New("duplicate notification")
2627
)
2728

29+
typeInvalidDefaultNotificationMethodErrorstruct {
30+
Methodstring
31+
}
32+
33+
func (eInvalidDefaultNotificationMethodError)Error()string {
34+
returnfmt.Sprintf("given default notification method %q is invalid",e.Method)
35+
}
36+
2837
typeStoreEnqueuerstruct {
2938
storeStore
3039
log slog.Logger
@@ -43,8 +52,13 @@ type StoreEnqueuer struct {
4352
// NewStoreEnqueuer creates an Enqueuer implementation which can persist notification messages in the store.
4453
funcNewStoreEnqueuer(cfg codersdk.NotificationsConfig,storeStore,helpers template.FuncMap,log slog.Logger,clock quartz.Clock) (*StoreEnqueuer,error) {
4554
varmethod database.NotificationMethod
46-
iferr:=method.Scan(cfg.Method.String());err!=nil {
47-
returnnil,xerrors.Errorf("given notification method %q is invalid",cfg.Method)
55+
// TODO(DanielleMaywood):
56+
// Currently we do not want to allow setting `inbox` as the default notification method.
57+
// As of 2025-03-25, setting this to `inbox` would cause a crash on the deployment
58+
// notification settings page. Until we make a future decision on this we want to disallow
59+
// setting it.
60+
iferr:=method.Scan(cfg.Method.String());err!=nil||method==database.NotificationMethodInbox {
61+
returnnil,InvalidDefaultNotificationMethodError{Method:cfg.Method.String()}
4862
}
4963

5064
return&StoreEnqueuer{

‎coderd/notifications/notifications_test.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,18 @@ func TestNotificationDuplicates(t *testing.T) {
18561856
require.NoError(t,err)
18571857
}
18581858

1859+
funcTestNotificationMethodCannotDefaultToInbox(t*testing.T) {
1860+
t.Parallel()
1861+
1862+
store,_:=dbtestutil.NewDB(t)
1863+
logger:=testutil.Logger(t)
1864+
1865+
cfg:=defaultNotificationsConfig(database.NotificationMethodInbox)
1866+
1867+
_,err:=notifications.NewStoreEnqueuer(cfg,store,defaultHelpers(),logger.Named("enqueuer"),quartz.NewMock(t))
1868+
require.ErrorIs(t,err, notifications.InvalidDefaultNotificationMethodError{Method:string(database.NotificationMethodInbox)})
1869+
}
1870+
18591871
funcTestNotificationTargetMatrix(t*testing.T) {
18601872
t.Parallel()
18611873

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp