feat: add audit logs and system configs

This commit is contained in:
2026-01-15 20:07:36 +08:00
parent 914df9edf2
commit b3fc226bbe
25 changed files with 3325 additions and 108 deletions

View File

@@ -3,18 +3,38 @@ package services
import (
"context"
"quyun/v2/database/models"
"github.com/sirupsen/logrus"
)
// @provider
type audit struct{}
func (s *audit) Log(ctx context.Context, operatorID int64, action, targetID, detail string) {
func (s *audit) Log(ctx context.Context, tenantID, operatorID int64, action, targetID, detail string) {
logrus.WithFields(logrus.Fields{
"audit": true,
"tenant": tenantID,
"operator": operatorID,
"action": action,
"target": targetID,
"detail": detail,
}).Info("Audit Log")
entry := &models.AuditLog{
TenantID: tenantID,
OperatorID: operatorID,
Action: action,
TargetID: targetID,
Detail: detail,
}
if err := models.AuditLogQuery.WithContext(ctx).Create(entry); err != nil {
logrus.WithFields(logrus.Fields{
"audit": true,
"tenant": tenantID,
"operator": operatorID,
"action": action,
"target": targetID,
}).WithError(err).Warn("Audit log persist failed")
}
}