Skip to content

Commit 3acc0da

Browse files
committed
Updates
- respect alert state during modification - validation for notification snooze time
1 parent 0e35b07 commit 3acc0da

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/handlers/http/alerts.rs

Lines changed: 17 additions & 3 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,20 @@ 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
478-
alerts.delete_task(alert_id).await?;
484+
// if alert is disabled, do not remove from task list
485+
if !is_disabled {
486+
alerts.delete_task(alert_id).await?;
487+
};
488+
479489
alerts.delete(alert_id).await?;
480490
alerts.update(&*new_alert).await;
481-
alerts.start_task(new_alert.clone_box()).await?;
491+
492+
// only restart the task if the state was not set to disabled
493+
if !is_disabled {
494+
alerts.start_task(new_alert.clone_box()).await?;
495+
}
482496

483497
let config = new_alert.to_alert_config().to_response();
484498
Ok(web::Json(config))

0 commit comments

Comments
 (0)