8000 audit · coder/coder@6d413d5 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 6d413d5

Browse files
committed
audit
1 parent 201fe07 commit 6d413d5

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

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/database/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ type HealthSettings struct {
3030
DismissedHealthchecks []healthsdk.HealthSection `db:"dismissed_healthchecks" json:"dismissed_healthchecks"`
3131
}
3232

33+
type NotificationsSettings struct {
34+
ID uuid.UUID `db:"id" json:"id"`
35+
NotifierPaused bool `db:"notifier_paused" json:"notifier_paused"`
36+
}
37+
3338
type Actions []policy.Action
3439

3540
func (a *Actions) Scan(src interface{}) error {

coderd/notifications.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/coder/coder/v2/coderd/rbac"
1111
"github.com/coder/coder/v2/coderd/rbac/policy"
1212
"github.com/coder/coder/v2/codersdk"
13+
"github.com/google/uuid"
1314
)
1415

1516
// @Summary Get notifications settings
@@ -67,7 +68,8 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
6768
return
6869
}
6970

70-
settingsJSON, err := json.Marshal(&settings)
71+
/*settingsJSON*/
72+
_, err := json.Marshal(&settings)
7173
if err != nil {
7274
httpapi.Write(r.Context(), rw, http.StatusInternalServerError, codersdk.Response{
7375
Message: "Failed to marshal notifications settings.",
@@ -77,12 +79,18 @@ func (api *API) putNotificationsSettings(rw http.ResponseWriter, r *http.Request
7779
}
7880

7981
auditor := api.Auditor.Load()
80-
aReq, commitAudit := audit.InitRequest[database.HealthSettings](rw, &audit.RequestParams{
82+
aReq, commitAudit := audit.InitRequest[database.NotificationsSettings](rw, &audit.RequestParams{
8183
Audit: *auditor,
8284
Log: api.Logger,
8385
Request: r,
8486
Action: database.AuditActionWrite,
8587
})
8688
defer commitAudit()
8789

90+
aReq.New = database.NotificationsSettings{
91+
ID: uuid.New(),
92+
NotifierPaused: settings.NotifierPaused,
93+
}
94+
95+
// TODO
8896
}

enterprise/audit/table.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ var auditableResourcesTypes = map[any]map[string]Action{
213213
"id": ActionIgnore,
214214
"dismissed_healthchecks": ActionTrack,
215215
},
216+
&database.NotificationsSettings{}: {
217+
"id": ActionIgnore,
218+
"notifier_paused": ActionTrack,
219+
},
216220
// TODO: track an ID here when the below ticket is completed:
217221
// https://github.com/coder/coder/pull/6012
218222
&database.License{}: {

0 commit comments

Comments
 (0)
0