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

Commit4960a1e

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 allnotifications that are not read for the authenticated user.Also adds the DB logic.
1 parentd8d4b9b commit4960a1e

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 aboutcustomizing 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 aboutcustomizing 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
returnq.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+
iferr:=q.authorizeContext(ctx,policy.ActionUpdate,resource);err!=nil {
3561+
returnerr
3562+
}
3563+
3564+
returnq.db.MarkAllInboxNotificationsAsRead(ctx,arg)
3565+
}
3566+
35573567
func (q*querier)OIDCClaimFieldValues(ctx context.Context,args database.OIDCClaimFieldValuesParams) ([]string,error) {
35583568
resource:=rbac.ResourceIdpsyncSettings
35593569
ifargs.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
returnshares,nil
95019501
}
95029502

9503+
func (q*FakeQuerier)MarkAllInboxNotificationsAsRead(_ context.Context,arg database.MarkAllInboxNotificationsAsReadParams)error {
9504+
err:=validateDatabaseType(arg)
9505+
iferr!=nil {
9506+
returnerr
9507+
}
9508+
9509+
foridx,notif:=rangeq.inboxNotifications {
9510+
ifnotif.UserID==arg.UserID&&!notif.ReadAt.Valid {
9511+
q.inboxNotifications[idx].ReadAt=arg.ReadAt
9512+
}
9513+
}
9514+
9515+
returnnil
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 aboutcustomizing 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 aboutcustomizing 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 aboutcustomizing 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 aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp