Skip to content

Commit f8d9a80

Browse files
authored
feat: add notification warning alert to Tasks page (#20900)
## Problem Users may not realize that task notifications are disabled by default. To improve awareness, we show a warning alert on the Tasks page when all task notifications are disabled. **Alert visibility logic:** - Shows when **all** task notification templates (Task Working, Task Idle, Task Completed, Task Failed) are disabled - Can be dismissed by the user, which stores the dismissal in the user preferences API - If the user later enables any task notification in Account Settings, the dismissal state is cleared so the alert will show again if they disable all notifications in the future <img width="2980" height="1588" alt="Screenshot 2025-11-25 at 17 48 17" src="/api/flow.js?q=https%3A%2F%2Fgithub.com%2Fcoder%2Fcoder%2Fcommit%2F%253Ca%2520href%3D"https://github.com/user-attachments/assets/316bf097-d9d2-4489-bc16-2987ba45f45c">https://github.com/user-attachments/assets/316bf097-d9d2-4489-bc16-2987ba45f45c" /> ## Changes - Added a warning alert to the Tasks page when all task notifications are disabled - Introduced new `/users/{user}/preferences` endpoint to manage user preferences (stored in `user_configs` table) - Alert is dismissible and stores the dismissal state via the new user preferences API endpoint - Enabling any task notification in Account Settings clears the dismissal state via the preferences API - Added comprehensive Storybook stories for both TasksPage and NotificationsPage to test all alert visibility states and interactions Closes: coder/internal#1089
1 parent a8862be commit f8d9a80

File tree

24 files changed

+1028
-40
lines changed

24 files changed

+1028
-40
lines changed

coderd/apidoc/docs.go

Lines changed: 94 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 84 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,8 @@ func New(options *Options) *API {
13361336
})
13371337
r.Get("/appearance", api.userAppearanceSettings)
13381338
r.Put("/appearance", api.putUserAppearanceSettings)
1339+
r.Get("/preferences", api.userPreferenceSettings)
1340+
r.Put("/preferences", api.putUserPreferenceSettings)
13391341
r.Route("/password", func(r chi.Router) {
13401342
r.Use(httpmw.RateLimit(options.LoginRateLimit, time.Minute))
13411343
r.Put("/", api.putUserPassword)

coderd/database/dbauthz/dbauthz.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,6 +3431,17 @@ func (q *querier) GetUserStatusCounts(ctx context.Context, arg database.GetUserS
34313431
return q.db.GetUserStatusCounts(ctx, arg)
34323432
}
34333433

3434+
func (q *querier) GetUserTaskNotificationAlertDismissed(ctx context.Context, userID uuid.UUID) (bool, error) {
3435+
user, err := q.db.GetUserByID(ctx, userID)
3436+
if err != nil {
3437+
return false, err
3438+
}
3439+
if err := q.authorizeContext(ctx, policy.ActionReadPersonal, user); err != nil {
3440+
return false, err
3441+
}
3442+
return q.db.GetUserTaskNotificationAlertDismissed(ctx, userID)
3443+
}
3444+
34343445
func (q *querier) GetUserTerminalFont(ctx context.Context, userID uuid.UUID) (string, error) {
34353446
u, err := q.db.GetUserByID(ctx, userID)
34363447
if err != nil {
@@ -5464,6 +5475,17 @@ func (q *querier) UpdateUserStatus(ctx context.Context, arg database.UpdateUserS
54645475
return updateWithReturn(q.log, q.auth, fetch, q.db.UpdateUserStatus)(ctx, arg)
54655476
}
54665477

5478+
func (q *querier) UpdateUserTaskNotificationAlertDismissed(ctx context.Context, arg database.UpdateUserTaskNotificationAlertDismissedParams) (bool, error) {
5479+
user, err := q.db.GetUserByID(ctx, arg.UserID)
5480+
if err != nil {
5481+
return false, err
5482+
}
5483+
if err := q.authorizeContext(ctx, policy.ActionUpdatePersonal, user); err != nil {
5484+
return false, err
5485+
}
5486+
return q.db.UpdateUserTaskNotificationAlertDismissed(ctx, arg)
5487+
}
5488+
54675489
func (q *querier) UpdateUserTerminalFont(ctx context.Context, arg database.UpdateUserTerminalFontParams) (database.UserConfig, error) {
54685490
u, err := q.db.GetUserByID(ctx, arg.UserID)
54695491
if err != nil {

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net"
99
"reflect"
10+
"strconv"
1011
"testing"
1112
"time"
1213

@@ -1477,6 +1478,21 @@ func (s *MethodTestSuite) TestUser() {
14771478
dbm.EXPECT().UpdateUserTerminalFont(gomock.Any(), arg).Return(uc, nil).AnyTimes()
14781479
check.Args(arg).Asserts(u, policy.ActionUpdatePersonal).Returns(uc)
14791480
}))
1481+
s.Run("GetUserTaskNotificationAlertDismissed", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
1482+
u := testutil.Fake(s.T(), faker, database.User{})
1483+
dbm.EXPECT().GetUserByID(gomock.Any(), u.ID).Return(u, nil).AnyTimes()
1484+
dbm.EXPECT().GetUserTaskNotificationAlertDismissed(gomock.Any(), u.ID).Return(false, nil).AnyTimes()
1485+
check.Args(u.ID).Asserts(u, policy.ActionReadPersonal).Returns(false)
1486+
}))
1487+
s.Run("UpdateUserTaskNotificationAlertDismissed", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
1488+
user := testutil.Fake(s.T(), faker, database.User{})
1489+
userConfig := database.UserConfig{UserID: user.ID, Key: "task_notification_alert_dismissed", Value: "false"}
1490+
userConfigValue, _ := strconv.ParseBool(userConfig.Value)
1491+
arg := database.UpdateUserTaskNotificationAlertDismissedParams{UserID: user.ID, TaskNotificationAlertDismissed: userConfigValue}
1492+
dbm.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil).AnyTimes()
1493+
dbm.EXPECT().UpdateUserTaskNotificationAlertDismissed(gomock.Any(), arg).Return(false, nil).AnyTimes()
1494+
check.Args(arg).Asserts(user, policy.ActionUpdatePersonal).Returns(userConfigValue)
1495+
}))
14801496
s.Run("UpdateUserStatus", s.Mocked(func(dbm *dbmock.MockStore, faker *gofakeit.Faker, check *expects) {
14811497
u := testutil.Fake(s.T(), faker, database.User{})
14821498
arg := database.UpdateUserStatusParams{ID: u.ID, Status: u.Status, UpdatedAt: u.UpdatedAt}

coderd/database/dbmetrics/querymetrics.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dbmock/dbmock.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/querier.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)