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

chore: disallow inbox as default method#17093

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

Merged
DanielleMaywood merged 4 commits intomainfromdm-disallow-inbox-as-default-method
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletionscoderd/notifications/enqueuer.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ package notifications
import (
"context"
"encoding/json"
"fmt"
"slices"
"strings"
"text/template"
Expand All@@ -25,6 +26,14 @@ var (
ErrDuplicate = xerrors.New("duplicate notification")
)

type InvalidDefaultNotificationMethodError struct {
Method string
}

func (e InvalidDefaultNotificationMethodError) Error() string {
return fmt.Sprintf("given default notification method %q is invalid", e.Method)
}

type StoreEnqueuer struct {
store Store
log slog.Logger
Expand All@@ -43,8 +52,13 @@ type StoreEnqueuer struct {
// NewStoreEnqueuer creates an Enqueuer implementation which can persist notification messages in the store.
func NewStoreEnqueuer(cfg codersdk.NotificationsConfig, store Store, helpers template.FuncMap, log slog.Logger, clock quartz.Clock) (*StoreEnqueuer, error) {
var method database.NotificationMethod
if err := method.Scan(cfg.Method.String()); err != nil {
return nil, xerrors.Errorf("given notification method %q is invalid", cfg.Method)
// TODO(DanielleMaywood):
// Currently we do not want to allow setting `inbox` as the default notification method.
// As of 2025-03-25, setting this to `inbox` would cause a crash on the deployment
// notification settings page. Until we make a future decision on this we want to disallow
// setting it.
if err := method.Scan(cfg.Method.String()); err != nil || method == database.NotificationMethodInbox {
return nil, InvalidDefaultNotificationMethodError{Method: cfg.Method.String()}
}

return &StoreEnqueuer{
Expand Down
12 changes: 12 additions & 0 deletionscoderd/notifications/notifications_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1856,6 +1856,18 @@ func TestNotificationDuplicates(t *testing.T) {
require.NoError(t, err)
}

func TestNotificationMethodCannotDefaultToInbox(t *testing.T) {
t.Parallel()

store, _ := dbtestutil.NewDB(t)
logger := testutil.Logger(t)

cfg := defaultNotificationsConfig(database.NotificationMethodInbox)

_, err := notifications.NewStoreEnqueuer(cfg, store, defaultHelpers(), logger.Named("enqueuer"), quartz.NewMock(t))
require.ErrorIs(t, err, notifications.InvalidDefaultNotificationMethodError{Method: string(database.NotificationMethodInbox)})
}

func TestNotificationTargetMatrix(t *testing.T) {
t.Parallel()

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp