Skip to content

Commit 44bd8db

Browse files
feat: save promql queries in filters (#1830)
1 parent a5976d2 commit 44bd8db

1 file changed

Lines changed: 21 additions & 16 deletions

File tree

‎src/users/filters.rs‎

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ pub enum FilterType {
7878
Filter,
7979
SQL,
8080
Search,
81+
Promql,
8182
}
8283

8384
impl FilterType {
@@ -86,6 +87,7 @@ impl FilterType {
8687
FilterType::Filter => "filter",
8788
FilterType::SQL => "sql",
8889
FilterType::Search => "search",
90+
FilterType::Promql => "promql",
8991
}
9092
}
9193
}
@@ -179,23 +181,26 @@ impl Filters {
179181
let query: &str = f.query.filter_query.as_deref().unwrap_or("");
180182
let filter_type = &f.query.filter_type;
181183

182-
// if filter type is SQL, check if the user has access to the dataset based on the query string
183-
// if filter type is search or filter, check if the user has access to the dataset based on the dataset name
184-
if *filter_type == FilterType::SQL {
185-
if (user_auth_for_query(key, query).await).is_ok() {
186-
_filters.push(f.clone())
184+
match filter_type {
185+
// SQL queries can reference multiple datasets, so authorize the query itself.
186+
FilterType::SQL => {
187+
if (user_auth_for_query(key, query).await).is_ok() {
188+
_filters.push(f.clone())
189+
}
187190
}
188-
} else if *filter_type == FilterType::Search || *filter_type == FilterType::Filter {
189-
let dataset_name = &f.stream_name;
190-
if user_auth_for_datasets(
191-
&permissions,
192-
std::slice::from_ref(dataset_name),
193-
&tenant_id,
194-
)
195-
.await
196-
.is_ok()
197-
{
198-
_filters.push(f.clone())
191+
// Other filter types are scoped by the saved filter's dataset.
192+
FilterType::Search | FilterType::Filter | FilterType::Promql => {
193+
let dataset_name = &f.stream_name;
194+
if user_auth_for_datasets(
195+
&permissions,
196+
std::slice::from_ref(dataset_name),
197+
&tenant_id,
198+
)
199+
.await
200+
.is_ok()
201+
{
202+
_filters.push(f.clone())
203+
}
199204
}
200205
}
201206
}

0 commit comments

Comments
 (0)