diff --git a/src/handlers/http/modal/server.rs b/src/handlers/http/modal/server.rs index 615af1d8e..f9795c705 100644 --- a/src/handlers/http/modal/server.rs +++ b/src/handlers/http/modal/server.rs @@ -307,13 +307,6 @@ impl Server { .authorize(Action::ListDashboard), ), ) - .service( - web::resource("/list_by_tag/{tag}").route( - web::get() - .to(dashboards::list_dashboards_by_tag) - .authorize(Action::ListDashboard), - ), - ) .service( web::scope("/{dashboard_id}") .service( diff --git a/src/handlers/http/users/dashboards.rs b/src/handlers/http/users/dashboards.rs index c3a774462..f0b0f66ef 100644 --- a/src/handlers/http/users/dashboards.rs +++ b/src/handlers/http/users/dashboards.rs @@ -44,6 +44,23 @@ pub async fn list_dashboards(req: HttpRequest) -> Result = tags + .split(',') + .map(|s| s.trim().to_string()) + .filter(|s| !s.is_empty()) + .collect(); + if tags.is_empty() { + return Err(DashboardError::Metadata("Tags cannot be empty")); + } + let dashboards = DASHBOARDS.list_dashboards_by_tags(tags).await; + let dashboard_summaries = dashboards + .iter() + .map(|dashboard| dashboard.to_summary()) + .collect::>(); + return Ok((web::Json(dashboard_summaries), StatusCode::OK)); + } } let dashboards = DASHBOARDS.list_dashboards(dashboard_limit).await; let dashboard_summaries = dashboards @@ -215,21 +232,6 @@ pub async fn list_tags() -> Result { Ok((web::Json(tags), StatusCode::OK)) } -pub async fn list_dashboards_by_tag(tag: Path) -> Result { - let tag = tag.into_inner(); - if tag.is_empty() { - return Err(DashboardError::Metadata("Tag cannot be empty")); - } - - let dashboards = DASHBOARDS.list_dashboards_by_tag(&tag).await; - let dashboard_summaries = dashboards - .iter() - .map(|dashboard| dashboard.to_summary()) - .collect::>(); - - Ok((web::Json(dashboard_summaries), StatusCode::OK)) -} - #[derive(Debug, thiserror::Error)] pub enum DashboardError { #[error("Failed to connect to storage: {0}")] diff --git a/src/users/dashboards.rs b/src/users/dashboards.rs index 30a567efe..c67c0e1e7 100644 --- a/src/users/dashboards.rs +++ b/src/users/dashboards.rs @@ -375,15 +375,20 @@ impl Dashboards { } /// List dashboards by tag - /// This function returns a list of dashboards that have the specified tag - pub async fn list_dashboards_by_tag(&self, tag: &str) -> Vec { + /// This function returns a list of dashboards that match any of the provided tags + /// If no tags are provided, it returns an empty list + pub async fn list_dashboards_by_tags(&self, tags: Vec) -> Vec { let dashboards = self.0.read().await; dashboards .iter() .filter(|d| { - d.tags - .as_ref() - .is_some_and(|tags| tags.contains(&tag.to_string())) + if let Some(dashboard_tags) = &d.tags { + dashboard_tags + .iter() + .any(|dashboard_tag| tags.contains(dashboard_tag)) + } else { + false + } }) .cloned() .collect()