Skip to content

Updates #1412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Updates #1412

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/handlers/http/alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,15 @@ pub async fn update_notification_state(
(Utc::now() + duration).to_rfc3339()
} else if let Ok(timestamp) = DateTime::<Utc>::from_str(&new_notification_state.state) {
// must be datetime utc then
if timestamp < Utc::now() {
return Err(AlertError::InvalidStateChange(
"Invalid notification state change request. Provided time is < Now".into(),
));
}
timestamp.to_rfc3339()
} else {
return Err(AlertError::InvalidStateChange(format!(
"Invalid notification state change request. Expected `notify` or human-time or UTC datetime. Got `{}`",
"Invalid notification state change request. Expected `notify`, `indefinite` or human-time or UTC datetime. Got `{}`",
&new_notification_state.state
)));
};
Expand Down Expand Up @@ -474,11 +479,16 @@ pub async fn modify_alert(
let alert_bytes = serde_json::to_vec(&new_alert.to_alert_config())?;
store.put_object(&path, Bytes::from(alert_bytes)).await?;

let is_disabled = new_alert.get_state().eq(&AlertState::Disabled);
// Now perform the atomic operations
alerts.delete_task(alert_id).await?;
alerts.delete(alert_id).await?;
alerts.update(&*new_alert).await;
alerts.start_task(new_alert.clone_box()).await?;

// only restart the task if the state was not set to disabled
if !is_disabled {
alerts.start_task(new_alert.clone_box()).await?;
}

let config = new_alert.to_alert_config().to_response();
Ok(web::Json(config))
Expand Down
Loading