feat: add audit and app log services
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type AppConfigService struct {
|
||||
@@ -39,6 +40,7 @@ func (r *AppConfigService) GetAppConfig(key string) (string, error) {
|
||||
|
||||
// 设置或更新配置项
|
||||
func (r *AppConfigService) SetAppConfig(key, value string) error {
|
||||
oldValue, _ := r.GetAppConfig(key)
|
||||
configType := "user"
|
||||
description := ""
|
||||
if definition, ok := settingDefinitionByKey(key); ok {
|
||||
@@ -59,6 +61,10 @@ func (r *AppConfigService) SetAppConfig(key, value string) error {
|
||||
value=excluded.value,
|
||||
description=excluded.description
|
||||
`, key, configType, value, description)
|
||||
if err == nil && oldValue != value && shouldAuditConfigChange(key) {
|
||||
detail := fmt.Sprintf("%s: %q -> %q", key, oldValue, value)
|
||||
_ = recordAuditLog(r.store, currentAuditActor(r.store), auditActionSettingsUpdate, "appconfig", key, detail)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -148,3 +154,19 @@ func validateSettingValue(definition models.AppSettingDefinition, value string)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func shouldAuditConfigChange(key string) bool {
|
||||
if strings.HasPrefix(key, "window.") || strings.HasPrefix(key, "auth.local.") {
|
||||
return false
|
||||
}
|
||||
definition, ok := settingDefinitionByKey(key)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
switch definition.Category {
|
||||
case "appearance", "data", "logs", "auth":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user