@@ -303,10 +303,15 @@ pub async fn update_notification_state(
303
303
( Utc :: now ( ) + duration) . to_rfc3339 ( )
304
304
} else if let Ok ( timestamp) = DateTime :: < Utc > :: from_str ( & new_notification_state. state ) {
305
305
// 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
+ }
306
311
timestamp. to_rfc3339 ( )
307
312
} else {
308
313
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 `{}`" ,
310
315
& new_notification_state. state
311
316
) ) ) ;
312
317
} ;
@@ -474,11 +479,16 @@ pub async fn modify_alert(
474
479
let alert_bytes = serde_json:: to_vec ( & new_alert. to_alert_config ( ) ) ?;
475
480
store. put_object ( & path, Bytes :: from ( alert_bytes) ) . await ?;
476
481
482
+ let is_disabled = new_alert. get_state ( ) . eq ( & AlertState :: Disabled ) ;
477
483
// Now perform the atomic operations
478
484
alerts. delete_task ( alert_id) . await ?;
479
485
alerts. delete ( alert_id) . await ?;
480
486
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
+ }
482
492
483
493
let config = new_alert. to_alert_config ( ) . to_response ( ) ;
484
494
Ok ( web:: Json ( config) )
0 commit comments