fix security
This commit is contained in:
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user