Skip to content

Commit 1275850

Browse files
authored
fix: alerts (#1412)
This PR adds two fixes for alerts: - respect alert state during modification - validation for notification snooze time
1 parent 0e35b07 commit 1275850

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/handlers/http/alerts.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,15 @@ pub async fn update_notification_state(
303303
(Utc::now() + duration).to_rfc3339()
304304
} else if let Ok(timestamp) = DateTime::<Utc>::from_str(&new_notification_state.state) {
305305
// must be datetime utc then
306+
if timestamp < Utc::now() {
307+
return Err(AlertError::InvalidStateChange(
308+
"Invalid notification state change request. Provided time is < Now".into(),
309+
));
310+
}
306311
timestamp.to_rfc3339()
307312
} else {
308313
return Err(AlertError::InvalidStateChange(format!(
309-
"Invalid notification state change request. Expected `notify` or human-time or UTC datetime. Got `{}`",
314+
"Invalid notification state change request. Expected `notify`, `indefinite` or human-time or UTC datetime. Got `{}`",
310315
&new_notification_state.state
311316
)));
312317
};
@@ -474,11 +479,16 @@ pub async fn modify_alert(
474479
let alert_bytes = serde_json::to_vec(&new_alert.to_alert_config())?;
475480
store.put_object(&path, Bytes::from(alert_bytes)).await?;
476481

482+
let is_disabled = new_alert.get_state().eq(&AlertState::Disabled);
477483
// Now perform the atomic operations
478484
alerts.delete_task(alert_id).await?;
479485
alerts.delete(alert_id).await?;
480486
alerts.update(&*new_alert).await;
481-
alerts.start_task(new_alert.clone_box()).await?;
487+
488+
// only restart the task if the state was not set to disabled
489+
if !is_disabled {
490+
alerts.start_task(new_alert.clone_box()).await?;
491+
}
482492

483493
let config = new_alert.to_alert_config().to_response();
484494
Ok(web::Json(config))

0 commit comments

Comments
 (0)