mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add notification preferences database & audit support (#14100)
This commit is contained in:
@@ -25,7 +25,8 @@ type Auditable interface {
|
||||
database.OAuth2ProviderAppSecret |
|
||||
database.CustomRole |
|
||||
database.AuditableOrganizationMember |
|
||||
database.Organization
|
||||
database.Organization |
|
||||
database.NotificationTemplate
|
||||
}
|
||||
|
||||
// Map is a map of changed fields in an audited resource. It maps field names to
|
||||
|
||||
@@ -16,6 +16,7 @@ import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"cdr.dev/slog"
|
||||
|
||||
"github.com/coder/coder/v2/coderd/database"
|
||||
"github.com/coder/coder/v2/coderd/database/dbtime"
|
||||
"github.com/coder/coder/v2/coderd/httpmw"
|
||||
@@ -117,6 +118,8 @@ func ResourceTarget[T Auditable](tgt T) string {
|
||||
return typed.Username
|
||||
case database.Organization:
|
||||
return typed.Name
|
||||
case database.NotificationTemplate:
|
||||
return typed.Name
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown resource %T for ResourceTarget", tgt))
|
||||
}
|
||||
@@ -163,6 +166,8 @@ func ResourceID[T Auditable](tgt T) uuid.UUID {
|
||||
return typed.UserID
|
||||
case database.Organization:
|
||||
return typed.ID
|
||||
case database.NotificationTemplate:
|
||||
return typed.ID
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown resource %T for ResourceID", tgt))
|
||||
}
|
||||
@@ -206,6 +211,8 @@ func ResourceType[T Auditable](tgt T) database.ResourceType {
|
||||
return database.ResourceTypeOrganizationMember
|
||||
case database.Organization:
|
||||
return database.ResourceTypeOrganization
|
||||
case database.NotificationTemplate:
|
||||
return database.ResourceTypeNotificationTemplate
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown resource %T for ResourceType", typed))
|
||||
}
|
||||
@@ -251,6 +258,8 @@ func ResourceRequiresOrgID[T Auditable]() bool {
|
||||
return true
|
||||
case database.Organization:
|
||||
return true
|
||||
case database.NotificationTemplate:
|
||||
return false
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown resource %T for ResourceRequiresOrgID", tgt))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user