fix: nullable server id in activity log and fix preset logging
This commit is contained in:
@@ -160,7 +160,7 @@ func (as *ConfigService) UpdateAllConfigs(ctx *fiber.Ctx, req *model.Configurati
|
||||
if details := BuildConfigDetails(entry.fileName, oldDataUTF8, newData); details != "" {
|
||||
go func(details string) {
|
||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: serverUUID,
|
||||
ServerID: &serverUUID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionConfigUpdate,
|
||||
@@ -285,7 +285,7 @@ func (as *ConfigService) updateConfigInternal(ctx context.Context, serverID stri
|
||||
if details := BuildConfigDetails(configFile, oldDataUTF8, newData); details != "" {
|
||||
go func() {
|
||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: serverUUID,
|
||||
ServerID: &serverUUID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionConfigUpdate,
|
||||
|
||||
@@ -12,9 +12,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
presetMaxNameLen = 100
|
||||
presetMaxDescLen = 500
|
||||
presetMaxSectionBytes = 64 * 1024 // 64 KB per config section
|
||||
presetMaxNameLen = 100
|
||||
presetMaxDescLen = 500
|
||||
presetMaxSectionBytes = 64 * 1024 // 64 KB per config section
|
||||
)
|
||||
|
||||
type ConfigPresetService struct {
|
||||
@@ -46,7 +46,7 @@ func (s *ConfigPresetService) GetPreset(ctx context.Context, id uuid.UUID) (*mod
|
||||
return preset, nil
|
||||
}
|
||||
|
||||
func (s *ConfigPresetService) CreatePreset(ctx context.Context, req *model.ConfigPresetCreateRequest) (*model.ConfigPreset, error) {
|
||||
func (s *ConfigPresetService) CreatePreset(ctx context.Context, req *model.ConfigPresetCreateRequest, actorID, actorUsername string) (*model.ConfigPreset, error) {
|
||||
if req.Name == "" {
|
||||
return nil, fmt.Errorf("preset name is required")
|
||||
}
|
||||
@@ -70,7 +70,18 @@ func (s *ConfigPresetService) CreatePreset(ctx context.Context, req *model.Confi
|
||||
return nil, err
|
||||
}
|
||||
|
||||
logging.Info("Preset created: id=%s name=%q", preset.ID, preset.Name)
|
||||
details := fmt.Sprintf(`{"preset_id":%q,"preset_name":%q}`, preset.ID, preset.Name)
|
||||
go func() {
|
||||
if logErr := s.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionPresetCreate,
|
||||
Details: details,
|
||||
}); logErr != nil {
|
||||
logging.Error("Failed to log preset create: %v", logErr)
|
||||
}
|
||||
}()
|
||||
|
||||
return preset, nil
|
||||
}
|
||||
|
||||
@@ -154,7 +165,7 @@ func (s *ConfigPresetService) ApplyPreset(ctx context.Context, serverID string,
|
||||
details := fmt.Sprintf(`{"preset_id":%q,"preset_name":%q,"sections_applied":%d}`, presetID, preset.Name, len(results))
|
||||
go func() {
|
||||
if logErr := s.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: serverUUID,
|
||||
ServerID: &serverUUID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionPresetApply,
|
||||
|
||||
@@ -45,7 +45,7 @@ func (s *LeaderboardService) Update(ctx context.Context, serverID uuid.UUID, lb
|
||||
details := fmt.Sprintf(`{"driver_count":%d,"race_count":%d}`, driverCount, raceCount)
|
||||
go func() {
|
||||
if logErr := s.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: serverID,
|
||||
ServerID: &serverID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionLeaderboardUpdate,
|
||||
|
||||
@@ -110,7 +110,7 @@ func (as *ServiceControlService) ServiceControlStartServer(ctx *fiber.Ctx) (stri
|
||||
actorID, actorUsername := extractActor(ctx)
|
||||
go func() {
|
||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: server.ID,
|
||||
ServerID: &server.ID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionServerStart,
|
||||
@@ -147,7 +147,7 @@ func (as *ServiceControlService) ServiceControlStopServer(ctx *fiber.Ctx) (strin
|
||||
actorID, actorUsername := extractActor(ctx)
|
||||
go func() {
|
||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: server.ID,
|
||||
ServerID: &server.ID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionServerStop,
|
||||
@@ -184,7 +184,7 @@ func (as *ServiceControlService) ServiceControlRestartServer(ctx *fiber.Ctx) (st
|
||||
actorID, actorUsername := extractActor(ctx)
|
||||
go func() {
|
||||
_ = as.activityLog.Log(context.Background(), &model.ActivityLog{
|
||||
ServerID: server.ID,
|
||||
ServerID: &server.ID,
|
||||
UserID: actorID,
|
||||
Username: actorUsername,
|
||||
Action: model.ActionServerRestart,
|
||||
|
||||
Reference in New Issue
Block a user