Skip to content

Commit 4960a1e

Browse files
authored
feat(coderd): add mark-all-as-read endpoint for inbox notifications (#16976)
[Resolve this issue](coder/internal#506) Add a mark-all-as-read endpoint which is marking as read all notifications that are not read for the authenticated user. Also adds the DB logic.
1 parent d8d4b9b commit 4960a1e

File tree

15 files changed

+262
-0
lines changed

15 files changed

+262
-0
lines changed

coderd/apidoc/docs.go

Lines changed: 19 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: 17 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,7 @@ func New(options *Options) *API {
13951395
r.Use(apiKeyMiddleware)
13961396
r.Route("/inbox", func(r chi.Router) {
13971397
r.Get("/", api.listInboxNotifications)
1398+
r.Put("/mark-all-as-read", api.markAllInboxNotificationsAsRead)
13981399
r.Get("/watch", api.watchInboxNotifications)
13991400
r.Put("/{id}/read-status", api.updateInboxNotificationReadStatus)
14001401
})

coderd/database/dbauthz/dbauthz.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,6 +3554,16 @@ func (q *querier) ListWorkspaceAgentPortShares(ctx context.Context, workspaceID
35543554
return q.db.ListWorkspaceAgentPortShares(ctx, workspaceID)
35553555
}
35563556

3557+
func (q *querier) MarkAllInboxNotificationsAsRead(ctx context.Context, arg database.MarkAllInboxNotificationsAsReadParams) error {
3558+
resource := rbac.ResourceInboxNotification.WithOwner(arg.UserID.String())
3559+
3560+
if err := q.authorizeContext(ctx, policy.ActionUpdate, resource); err != nil {
3561+
return err
3562+
}
3563+
3564+
return q.db.MarkAllInboxNotificationsAsRead(ctx, arg)
3565+
}
3566+
35573567
func (q *querier) OIDCClaimFieldValues(ctx context.Context, args database.OIDCClaimFieldValuesParams) ([]string, error) {
35583568
resource := rbac.ResourceIdpsyncSettings
35593569
if args.OrganizationID != uuid.Nil {

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4653,6 +4653,15 @@ func (s *MethodTestSuite) TestNotifications() {
46534653
ReadAt: sql.NullTime{Time: readAt, Valid: true},
46544654
}).Asserts(rbac.ResourceInboxNotification.WithID(notifID).WithOwner(u.ID.String()), policy.ActionUpdate)
46554655
}))
4656+
4657+
s.Run("MarkAllInboxNotificationsAsRead", s.Subtest(func(db database.Store, check *expects) {
4658+
u := dbgen.User(s.T(), db, database.User{})
4659+
4660+
check.Args(database.MarkAllInboxNotificationsAsReadParams{
4661+
UserID: u.ID,
4662+
ReadAt: sql.NullTime{Time: dbtestutil.NowInDefaultTimezone(), Valid: true},
4663+
}).Asserts(rbac.ResourceInboxNotification.WithOwner(u.ID.String()), policy.ActionUpdate)
4664+
}))
46564665
}
46574666

46584667
func (s *MethodTestSuite) TestOAuth2ProviderApps() {

coderd/database/dbmem/dbmem.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9500,6 +9500,21 @@ func (q *FakeQuerier) ListWorkspaceAgentPortShares(_ context.Context, workspaceI
95009500
return shares, nil
95019501
}
95029502

9503+
func (q *FakeQuerier) MarkAllInboxNotificationsAsRead(_ context.Context, arg database.MarkAllInboxNotificationsAsReadParams) error {
9504+
err := validateDatabaseType(arg)
9505+
if err != nil {
9506+
return err
9507+
}
9508+
9509+
for idx, notif := range q.inboxNotifications {
9510+
if notif.UserID == arg.UserID && !notif.ReadAt.Valid {
9511+
q.inboxNotifications[idx].ReadAt = arg.ReadAt
9512+
}
9513+
}
9514+
9515+
return nil
9516+
}
9517+
95039518
// nolint:forcetypeassert
95049519
func (q *FakeQuerier) OIDCClaimFieldValues(_ context.Context, args database.OIDCClaimFieldValuesParams) ([]string, error) {
95059520
orgMembers := q.getOrganizationMemberNoLock(args.OrganizationID)

coderd/database/dbmetrics/querymetrics.go

Lines changed: 7 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: 14 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: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 19 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy