feat: add audit and app log services

This commit is contained in:
QiuSW
2026-07-09 00:55:46 +08:00
parent 3bd05b316e
commit 769c861eb0
20 changed files with 804 additions and 30 deletions
+22
View File
@@ -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
}
}