@@ -20,7 +20,7 @@ use std::{collections::HashMap, str::FromStr};
2020
2121use crate :: {
2222 alerts:: {
23- ALERTS , AlertError , AlertState , Severity ,
23+ ALERTS , AlertError , AlertState , Severity , user_auth_for_alert_config ,
2424 alert_enums:: { AlertType , NotificationState } ,
2525 alert_structs:: { AlertConfig , AlertRequest , AlertStateEntry , NotificationStateRequest } ,
2626 alert_traits:: AlertTrait ,
@@ -29,7 +29,7 @@ use crate::{
2929 } ,
3030 metastore:: metastore_traits:: MetastoreObject ,
3131 parseable:: PARSEABLE ,
32- utils:: { actix:: extract_session_key_from_req, get_tenant_id_from_request, user_auth_for_query } ,
32+ utils:: { actix:: extract_session_key_from_req, get_tenant_id_from_request} ,
3333} ;
3434use actix_web:: {
3535 HttpRequest , Responder ,
@@ -343,7 +343,7 @@ pub async fn get(req: HttpRequest, alert_id: Path<Ulid>) -> Result<impl Responde
343343
344344 let alert = alerts. get_alert_by_id ( alert_id, & tenant_id) . await ?;
345345 // validate that the user has access to the tables mentioned in the query
346- user_auth_for_query ( & session_key, alert. get_query ( ) ) . await ?;
346+ user_auth_for_alert_config ( & session_key, & alert. to_alert_config ( ) ) . await ?;
347347
348348 Ok ( web:: Json ( alert. to_alert_config ( ) . to_response ( ) ) )
349349}
@@ -364,7 +364,7 @@ pub async fn delete(req: HttpRequest, alert_id: Path<Ulid>) -> Result<impl Respo
364364 let alert = alerts. get_alert_by_id ( alert_id, & tenant_id) . await ?;
365365
366366 // validate that the user has access to the tables mentioned in the query
367- user_auth_for_query ( & session_key, alert. get_query ( ) ) . await ?;
367+ user_auth_for_alert_config ( & session_key, & alert. to_alert_config ( ) ) . await ?;
368368
369369 PARSEABLE
370370 . metastore
@@ -436,7 +436,7 @@ pub async fn update_notification_state(
436436 // check if alert id exists in map
437437 let alert = alerts. get_alert_by_id ( alert_id, & tenant_id) . await ?;
438438 // validate that the user has access to the tables mentioned in the query
439- user_auth_for_query ( & session_key, alert. get_query ( ) ) . await ?;
439+ user_auth_for_alert_config ( & session_key, & alert. to_alert_config ( ) ) . await ?;
440440
441441 alerts
442442 . update_notification_state ( alert_id, new_notification_state, & tenant_id)
@@ -466,7 +466,7 @@ pub async fn disable_alert(
466466 // check if alert id exists in map
467467 let alert = alerts. get_alert_by_id ( alert_id, & tenant_id) . await ?;
468468 // validate that the user has access to the tables mentioned in the query
469- user_auth_for_query ( & session_key, alert. get_query ( ) ) . await ?;
469+ user_auth_for_alert_config ( & session_key, & alert. to_alert_config ( ) ) . await ?;
470470
471471 alerts
472472 . update_state ( alert_id, AlertState :: Disabled , Some ( "" . into ( ) ) , & tenant_id)
@@ -504,7 +504,7 @@ pub async fn enable_alert(
504504 }
505505
506506 // validate that the user has access to the tables mentioned in the query
507- user_auth_for_query ( & session_key, alert. get_query ( ) ) . await ?;
507+ user_auth_for_alert_config ( & session_key, & alert. to_alert_config ( ) ) . await ?;
508508
509509 alerts
510510 . update_state (
@@ -542,14 +542,14 @@ pub async fn modify_alert(
542542
543543 // Validate and prepare the new alert
544544 let alert = alerts. get_alert_by_id ( alert_id, & tenant_id) . await ?;
545- user_auth_for_query ( & session_key, alert. get_query ( ) ) . await ?;
545+ user_auth_for_alert_config ( & session_key, & alert. to_alert_config ( ) ) . await ?;
546546
547547 let mut new_config = alert_request. into ( tenant_id. clone ( ) ) . await ?;
548548 if & new_config. alert_type != alert. get_alert_type ( ) {
549549 return Err ( AlertError :: InvalidAlertModifyRequest ) ;
550550 }
551551
552- user_auth_for_query ( & session_key, & new_config. query ) . await ?;
552+ user_auth_for_alert_config ( & session_key, & new_config) . await ?;
553553
554554 // Calculate notification config
555555 let eval_freq = new_config. get_eval_frequency ( ) ;
@@ -568,6 +568,7 @@ pub async fn modify_alert(
568568 old_config. eval_config = new_config. eval_config ;
569569 old_config. notification_config = new_config. notification_config ;
570570 old_config. query = new_config. query ;
571+ old_config. query_type = new_config. query_type ;
571572 old_config. severity = new_config. severity ;
572573 old_config. tags = new_config. tags ;
573574 old_config. targets = new_config. targets ;
@@ -623,7 +624,7 @@ pub async fn evaluate_alert(
623624
624625 let alert = alerts. get_alert_by_id ( alert_id, & tenant_id) . await ?;
625626
626- user_auth_for_query ( & session_key, alert. get_query ( ) ) . await ?;
627+ user_auth_for_alert_config ( & session_key, & alert. to_alert_config ( ) ) . await ?;
627628
628629 let config = alert. to_alert_config ( ) . to_response ( ) ;
629630
0 commit comments