Skip to content

Commit e205049

Browse files
committed
work on dbauthz
1 parent 90c7b64 commit e205049

File tree

17 files changed

+113
-7
lines changed

17 files changed

+113
-7
lines changed

coderd/apidoc/docs.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.

coderd/apidoc/swagger.json

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

coderd/database/dbauthz/dbauthz.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,11 +1418,11 @@ func (q *querier) FavoriteWorkspace(ctx context.Context, id uuid.UUID) error {
14181418
}
14191419

14201420
func (q *querier) FetchInboxNotificationsByUserID(ctx context.Context, userID uuid.UUID) ([]database.NotificationsInbox, error) {
1421-
panic("not implemented")
1421+
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.FetchInboxNotificationsByUserID)(ctx, userID)
14221422
}
14231423

14241424
func (q *querier) FetchInboxNotificationsByUserIDAndTemplateIDAndTargetID(ctx context.Context, arg database.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
1425-
panic("not implemented")
1425+
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.FetchInboxNotificationsByUserIDAndTemplateIDAndTargetID)(ctx, arg)
14261426
}
14271427

14281428
func (q *querier) FetchMemoryResourceMonitorsByAgentID(ctx context.Context, agentID uuid.UUID) (database.WorkspaceAgentMemoryResourceMonitor, error) {
@@ -1447,11 +1447,11 @@ func (q *querier) FetchNewMessageMetadata(ctx context.Context, arg database.Fetc
14471447
}
14481448

14491449
func (q *querier) FetchUnreadInboxNotificationsByUserID(ctx context.Context, userID uuid.UUID) ([]database.NotificationsInbox, error) {
1450-
panic("not implemented")
1450+
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.FetchUnreadInboxNotificationsByUserID)(ctx, userID)
14511451
}
14521452

14531453
func (q *querier) FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetID(ctx context.Context, arg database.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetIDParams) ([]database.NotificationsInbox, error) {
1454-
panic("not implemented")
1454+
return fetchWithPostFilter(q.auth, policy.ActionRead, q.db.FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetID)(ctx, arg)
14551455
}
14561456

14571457
func (q *querier) FetchVolumesResourceMonitorsByAgentID(ctx context.Context, agentID uuid.UUID) ([]database.WorkspaceAgentVolumeResourceMonitor, error) {
@@ -1766,6 +1766,10 @@ func (q *querier) GetHungProvisionerJobs(ctx context.Context, hungSince time.Tim
17661766
return q.db.GetHungProvisionerJobs(ctx, hungSince)
17671767
}
17681768

1769+
func (q *querier) GetInboxNotificationByID(ctx context.Context, id uuid.UUID) (database.NotificationsInbox, error) {
1770+
return fetchWithAction(q.log, q.auth, policy.ActionRead, q.db.GetInboxNotificationByID)(ctx, id)
1771+
}
1772+
17691773
func (q *querier) GetJFrogXrayScanByWorkspaceAndAgentID(ctx context.Context, arg database.GetJFrogXrayScanByWorkspaceAndAgentIDParams) (database.JfrogXrayScan, error) {
17701774
if _, err := fetch(q.log, q.auth, q.db.GetWorkspaceByID)(ctx, arg.WorkspaceID); err != nil {
17711775
return database.JfrogXrayScan{}, err
@@ -3094,7 +3098,7 @@ func (q *querier) InsertGroupMember(ctx context.Context, arg database.InsertGrou
30943098
}
30953099

30963100
func (q *querier) InsertInboxNotification(ctx context.Context, arg database.InsertInboxNotificationParams) (database.NotificationsInbox, error) {
3097-
panic("not implemented")
3101+
return insert(q.log, q.auth, rbac.ResourceNotificationInbox.WithOwner(arg.UserID.String()), q.db.InsertInboxNotification)(ctx, arg)
30983102
}
30993103

31003104
func (q *querier) InsertLicense(ctx context.Context, arg database.InsertLicenseParams) (database.License, error) {
@@ -3585,7 +3589,15 @@ func (q *querier) RevokeDBCryptKey(ctx context.Context, activeKeyDigest string)
35853589
}
35863590

35873591
func (q *querier) SetInboxNotificationAsRead(ctx context.Context, arg database.SetInboxNotificationAsReadParams) error {
3588-
panic("not implemented")
3592+
fetch := func(ctx context.Context, id uuid.UUID) (database.NotificationsInbox, error) {
3593+
return q.db.GetInboxNotificationByID(ctx, id)
3594+
}
3595+
3596+
update := func(ctx context.Context, arg database.SetInboxNotificationAsReadParams) error {
3597+
return q.db.SetInboxNotificationAsRead(ctx, arg)
3598+
}
3599+
3600+
return update(q.log, q.auth, policy.ActionUpdate, fetch, update)(ctx, arg)
35893601
}
35903602

35913603
func (q *querier) TryAcquireLock(ctx context.Context, id int64) (bool, error) {

coderd/database/dbmem/dbmem.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,6 +3358,10 @@ func (q *FakeQuerier) GetHungProvisionerJobs(_ context.Context, hungSince time.T
33583358
return hungJobs, nil
33593359
}
33603360

3361+
func (q *FakeQuerier) GetInboxNotificationByID(ctx context.Context, id uuid.UUID) (database.NotificationsInbox, error) {
3362+
panic("not implemented")
3363+
}
3364+
33613365
func (q *FakeQuerier) GetJFrogXrayScanByWorkspaceAndAgentID(_ context.Context, arg database.GetJFrogXrayScanByWorkspaceAndAgentIDParams) (database.JfrogXrayScan, error) {
33623366
err := validateDatabaseType(arg)
33633367
if err != nil {

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

coderd/database/modelmethods.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ func (TemplateVersion) RBACObject(template Template) rbac.Object {
168168
return template.RBACObject()
169169
}
170170

171+
func (i NotificationsInbox) RBACObject() rbac.Object {
172+
return rbac.ResourceNotificationInbox.
173+
WithID(i.ID).
174+
WithOwner(i.UserID.String())
175+
}
176+
171177
// RBACObjectNoTemplate is for orphaned template versions.
172178
func (v TemplateVersion) RBACObjectNoTemplate() rbac.Object {
173179
return rbac.ResourceTemplate.InOrg(v.OrganizationID)

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

coderd/database/queries/notificationsinbox.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ SELECT * FROM notifications_inbox WHERE user_id = $1 AND template_id = $2 AND ta
1010
-- name: FetchUnreadInboxNotificationsByUserIDAndTemplateIDAndTargetID :many
1111
SELECT * FROM notifications_inbox WHERE user_id = $1 AND template_id = $2 AND target_id = $3 AND read_at IS NULL ORDER BY created_at DESC;
1212

13+
-- name: GetInboxNotificationByID :one
14+
SELECT * FROM notifications_inbox WHERE id = $1;
15+
1316
-- name: InsertInboxNotification :one
1417
INSERT INTO
1518
notifications_inbox (
@@ -32,4 +35,4 @@ UPDATE
3235
SET
3336
read_at = $1
3437
WHERE
35-
id = $2;
38+
id = @id;

coderd/rbac/object_gen.go

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

coderd/rbac/policy/policy.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,13 @@ var RBACPermissions = map[string]PermissionDefinition{
287287
ActionUpdate: actDef("update notification preferences"),
288288
},
289289
},
290+
"notification_inbox": {
291+
Actions: map[Action]ActionDefinition{
292+
ActionCreate: actDef("create notifications inbox"),
293+
ActionRead: actDef("read notifications inbox"),
294+
ActionUpdate: actDef("update notifications inbox"),
295+
},
296+
},
290297
"crypto_key": {
291298
Actions: map[Action]ActionDefinition{
292299
ActionRead: actDef("read crypto keys"),

codersdk/rbacresources_gen.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.

docs/reference/api/members.md

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

docs/reference/api/schemas.md

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

site/src/api/rbacresourcesGenerated.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export const RBACResourceActions: Partial<
7070
delete: "delete license",
7171
read: "read licenses",
7272
},
73+
notification_inbox: {
74+
create: "create notifications inbox",
75+
read: "read notifications inbox",
76+
update: "update notifications inbox",
77+
},
7378
notification_message: {
7479
create: "create notification messages",
7580
delete: "delete notification messages",

site/src/api/typesGenerated.ts

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)