Skip to content

Commit 735d0ef

Browse files
committed
feat: add killswitch for notifications
1 parent ac6db5e commit 735d0ef

32 files changed

+783
-22
lines changed

coderd/apidoc/docs.go

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

coderd/audit/diff.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type Auditable interface {
2020
database.WorkspaceProxy |
2121
database.AuditOAuthConvertState |
2222
database.HealthSettings |
23+
database.NotificationsSettings |
2324
database.OAuth2ProviderApp |
2425
database.OAuth2ProviderAppSecret |
2526
database.CustomRole |

coderd/audit/request.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ func ResourceTarget[T Auditable](tgt T) string {
9999
return string(typed.ToLoginType)
100100
case database.HealthSettings:
101101
return "" // no target?
102+
case database.NotificationsSettings:
103+
return "" // no target?
102104
case database.OAuth2ProviderApp:
103105
return typed.Name
104106
case database.OAuth2ProviderAppSecret:
@@ -142,6 +144,9 @@ func ResourceID[T Auditable](tgt T) uuid.UUID {
142144
case database.HealthSettings:
143145
// Artificial ID for auditing purposes
144146
return typed.ID
147+
case database.NotificationsSettings:
148+
// Artificial ID for auditing purposes
149+
return typed.ID
145150
case database.OAuth2ProviderApp:
146151
return typed.ID
147152
case database.OAuth2ProviderAppSecret:
@@ -183,6 +188,8 @@ func ResourceType[T Auditable](tgt T) database.ResourceType {
183188
return database.ResourceTypeConvertLogin
184189
case database.HealthSettings:
185190
return database.ResourceTypeHealthSettings
191+
case database.NotificationsSettings:
192+
return database.ResourceTypeNotificationsSettings
186193
case database.OAuth2ProviderApp:
187194
return database.ResourceTypeOauth2ProviderApp
188195
case database.OAuth2ProviderAppSecret:
@@ -225,6 +232,9 @@ func ResourceRequiresOrgID[T Auditable]() bool {
225232
case database.HealthSettings:
226233
// Artificial ID for auditing purposes
227234
return false
235+
case database.NotificationsSettings:
236+
// Artificial ID for auditing purposes
237+
return false
228238
case database.OAuth2ProviderApp:
229239
return false
230240
case database.OAuth2ProviderAppSecret:

coderd/coderd.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,6 +1242,11 @@ func New(options *Options) *API {
12421242
})
12431243
})
12441244
})
1245+
r.Route("/notifications", func(r chi.Router) {
1246+
r.Use(apiKeyMiddleware)
1247+
r.Get("/settings", api.notificationsSettings)
1248+
r.Put("/settings", api.putNotificationsSettings)
1249+
})
12451250
})
12461251

12471252
if options.SwaggerEndpoint {

coderd/database/dbauthz/dbauthz.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,11 @@ func (q *querier) GetNotificationMessagesByStatus(ctx context.Context, arg datab
14791479
return q.db.GetNotificationMessagesByStatus(ctx, arg)
14801480
}
14811481

1482+
func (q *querier) GetNotificationsSettings(ctx context.Context) (string, error) {
1483+
// No authz checks
1484+
return q.db.GetNotificationsSettings(ctx)
1485+
}
1486+
14821487
func (q *querier) GetOAuth2ProviderAppByID(ctx context.Context, id uuid.UUID) (database.OAuth2ProviderApp, error) {
14831488
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceOauth2App); err != nil {
14841489
return database.OAuth2ProviderApp{}, err
@@ -3687,6 +3692,13 @@ func (q *querier) UpsertLogoURL(ctx context.Context, value string) error {
36873692
return q.db.UpsertLogoURL(ctx, value)
36883693
}
36893694

3695+
func (q *querier) UpsertNotificationsSettings(ctx context.Context, value string) error {
3696+
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceDeploymentConfig); err != nil {
3697+
return err
3698+
}
3699+
return q.db.UpsertNotificationsSettings(ctx, value)
3700+
}
3701+
36903702
func (q *querier) UpsertOAuthSigningKey(ctx context.Context, value string) error {
36913703
if err := q.authorizeContext(ctx, policy.ActionUpdate, rbac.ResourceSystem); err != nil {
36923704
return err

coderd/database/dbauthz/dbauthz_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,12 @@ func (s *MethodTestSuite) TestSystemFunctions() {
23502350
s.Run("UpsertHealthSettings", s.Subtest(func(db database.Store, check *expects) {
23512351
check.Args("foo").Asserts(rbac.ResourceDeploymentConfig, policy.ActionUpdate)
23522352
}))
2353+
s.Run("GetNotificationsSettings", s.Subtest(func(db database.Store, check *expects) {
2354+
check.Args().Asserts()
2355+
}))
2356+
s.Run("UpsertNotificationsSettings", s.Subtest(func(db database.Store, check *expects) {
2357+
check.Args("foo").Asserts(rbac.ResourceDeploymentConfig, policy.ActionUpdate)
2358+
}))
23532359
s.Run("GetDeploymentWorkspaceAgentStats", s.Subtest(func(db database.Store, check *expects) {
23542360
check.Args(time.Time{}).Asserts()
23552361
}))

coderd/database/dbmem/dbmem.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ type data struct {
199199
lastUpdateCheck []byte
200200
announcementBanners []byte
201201
healthSettings []byte
202+
notificationsSettings []byte
202203
applicationName string
203204
logoURL string
204205
appSecurityKey string
@@ -2760,6 +2761,17 @@ func (q *FakeQuerier) GetNotificationMessagesByStatus(_ context.Context, arg dat
27602761
return out, nil
27612762
}
27622763

2764+
func (q *FakeQuerier) GetNotificationsSettings(_ context.Context) (string, error) {
2765+
q.mutex.RLock()
2766+
defer q.mutex.RUnlock()
2767+
2768+
if q.notificationsSettings == nil {
2769+
return "{}", nil
2770+
}
2771+
2772+
return string(q.notificationsSettings), nil
2773+
}
2774+
27632775
func (q *FakeQuerier) GetOAuth2ProviderAppByID(_ context.Context, id uuid.UUID) (database.OAuth2ProviderApp, error) {
27642776
q.mutex.Lock()
27652777
defer q.mutex.Unlock()
@@ -8713,6 +8725,14 @@ func (q *FakeQuerier) UpsertLogoURL(_ context.Context, data string) error {
87138725
return nil
87148726
}
87158727

8728+
func (q *FakeQuerier) UpsertNotificationsSettings(_ context.Context, data string) error {
8729+
q.mutex.RLock()
8730+
defer q.mutex.RUnlock()
8731+
8732+
q.notificationsSettings = []byte(data)
8733+
return nil
8734+
}
8735+
87168736
func (q *FakeQuerier) UpsertOAuthSigningKey(_ context.Context, value string) error {
87178737
q.mutex.Lock()
87188738
defer q.mutex.Unlock()

coderd/database/dbmetrics/dbmetrics.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: 29 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