fix security

This commit is contained in:
voltsrage
2026-06-21 19:53:19 +08:00
parent a37fad0e57
commit 7170b6efad
14 changed files with 422 additions and 27 deletions
@@ -112,6 +112,38 @@ public class AlertThresholdService : IAlertThresholdService
return threshold;
}
public async Task DeleteAsync(Guid id)
{
var threshold = await _db.AlertThresholds.FindAsync(id);
if (threshold is null)
throw new NotFoundException("Threshold not found.", "THRESHOLD_NOT_FOUND");
var previous = new
{
threshold.ObservationCode,
threshold.DisplayName,
threshold.Unit,
threshold.CriticalLow,
threshold.WarningLow,
threshold.WarningHigh,
threshold.CriticalHigh,
threshold.SuppressionWindowMinutes
};
var observationCode = threshold.ObservationCode;
_db.AlertThresholds.Remove(threshold);
await _db.SaveChangesAsync();
await _audit.WriteAsync(
AuditAction.ThresholdDeleted,
"AlertThreshold",
id,
previousValue: previous);
await InvalidateCacheAsync(observationCode);
}
private async Task InvalidateCacheAsync(string observationCode)
{
var cache = _redis.GetDatabase();
@@ -4,4 +4,5 @@ public interface IAlertThresholdService
Task<List<AlertThreshold>> ListAsync();
Task<AlertThreshold> GetByIdAsync(Guid id);
Task<AlertThreshold> UpdateAsync(Guid id, AlertThresholdRequest req);
Task DeleteAsync(Guid id);
}