- Notifications
You must be signed in to change notification settings - Fork1k
feat: implement thin vertical slice of system-generated notifications#13537
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
Changes from1 commit
53c9cbb
4856aed
cda6efb
86f937a
e8f1af2
a056f54
8c64d30
ac149ec
884fadf
4e362e7
8097290
1b841ad
61f5bd6
3c8e33b
757327c
6f909ae
36698c5
c5701a6
9d4c312
9380d8e
4b7214d
6679ef1
337997d
ba5f7c6
0f29293
7c6c486
c6e75c2
aff9e6c
613e074
faea7fc
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
Signed-off-by: Danny Kopping <danny@coder.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -125,3 +125,6 @@ WHERE id IN | ||
FROM notification_messages AS nested | ||
WHERE nested.updated_at < NOW() - INTERVAL '7 days'); | ||
-- name: GetNotificationMessagesByStatus :many | ||
SELECT * FROM notification_messages WHERE status = @status LIMIT sqlc.arg('limit')::int; | ||
mtojek marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
dannykopping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -13,7 +13,6 @@ import ( | ||
"cdr.dev/slog" | ||
"github.com/coder/coder/v2/coderd/notifications/types" | ||
markdown "github.com/coder/coder/v2/coderd/render" | ||
"github.com/coder/coder/v2/codersdk" | ||
@@ -40,11 +39,6 @@ func NewWebhookHandler(cfg codersdk.NotificationsWebhookConfig, log slog.Logger) | ||
return &WebhookHandler{cfg: cfg, log: log, cl: &http.Client{}} | ||
dannykopping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
func (w *WebhookHandler) Dispatcher(payload types.MessagePayload, titleTmpl, bodyTmpl string) (DeliveryFunc, error) { | ||
if w.cfg.Endpoint.String() == "" { | ||
return nil, xerrors.New("webhook endpoint not defined") | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -5,7 +5,6 @@ import ( | ||
"encoding/json" | ||
"sync/atomic" | ||
"testing" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
@@ -15,8 +14,8 @@ import ( | ||
"cdr.dev/slog" | ||
"cdr.dev/slog/sloggers/slogtest" | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/database/dbgen" | ||
"github.com/coder/coder/v2/coderd/database/dbmem" | ||
"github.com/coder/coder/v2/coderd/database/dbtestutil" | ||
"github.com/coder/coder/v2/coderd/notifications" | ||
@@ -32,7 +31,7 @@ func TestBufferedUpdates(t *testing.T) { | ||
if !dbtestutil.WillUsePostgres() { | ||
t.Skip("This test requires postgres") | ||
spikecurtis marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
} | ||
ctx, logger, db := setup(t) | ||
interceptor := &bulkUpdateInterceptor{Store: db} | ||
santa := &santaHandler{} | ||
@@ -45,19 +44,15 @@ func TestBufferedUpdates(t *testing.T) { | ||
enq, err := notifications.NewStoreEnqueuer(cfg, interceptor, defaultHelpers(), logger.Named("notifications-enqueuer")) | ||
require.NoError(t, err) | ||
user := dbgen.User(t, db, database.User{}) | ||
// given | ||
_, err = enq.Enqueue(ctx, user.ID, notifications.TemplateWorkspaceDeleted, map[string]string{"nice": "true"}, "") | ||
require.NoError(t, err) | ||
_, err = enq.Enqueue(ctx, user.ID, notifications.TemplateWorkspaceDeleted, map[string]string{"nice": "true"}, "") | ||
require.NoError(t, err) | ||
_, err = enq.Enqueue(ctx, user.ID, notifications.TemplateWorkspaceDeleted, map[string]string{"nice": "false"}, "") | ||
require.NoError(t, err) | ||
// when | ||
mgr.Run(ctx) | ||
@@ -94,7 +89,6 @@ func TestBuildPayload(t *testing.T) { | ||
"my_url": func() string { return url }, | ||
} | ||
db := dbmem.New() | ||
interceptor := newEnqueueInterceptor(db, | ||
// Inject custom message metadata to influence the payload construction. | ||
@@ -107,7 +101,7 @@ func TestBuildPayload(t *testing.T) { | ||
}, | ||
} | ||
out, err := json.Marshal(actions) | ||
assert.NoError(t, err) | ||
return database.FetchNewMessageMetadataRow{ | ||
NotificationName: "My Notification", | ||
@@ -122,19 +116,17 @@ func TestBuildPayload(t *testing.T) { | ||
enq, err := notifications.NewStoreEnqueuer(defaultNotificationsConfig(database.NotificationMethodSmtp), interceptor, helpers, logger.Named("notifications-enqueuer")) | ||
require.NoError(t, err) | ||
ctx := testutil.Context(t, testutil.WaitShort) | ||
// when | ||
_, err = enq.Enqueue(ctx, uuid.New(), notifications.TemplateWorkspaceDeleted, nil, "test") | ||
require.NoError(t, err) | ||
// then | ||
payload := testutil.RequireRecvCtx(ctx, t, interceptor.payload) | ||
require.Len(t, payload.Actions, 1) | ||
require.Equal(t, label, payload.Actions[0].Label) | ||
require.Equal(t, url, payload.Actions[0].URL) | ||
} | ||
func TestStopBeforeRun(t *testing.T) { | ||
@@ -184,10 +176,6 @@ type santaHandler struct { | ||
nice atomic.Int32 | ||
} | ||
func (s *santaHandler) Dispatcher(payload types.MessagePayload, _, _ string) (dispatch.DeliveryFunc, error) { | ||
return func(ctx context.Context, msgID uuid.UUID) (retryable bool, err error) { | ||
if payload.Labels["nice"] != "true" { | ||
Uh oh!
There was an error while loading.Please reload this page.