server: Introduce True/False for filters

This should help clean up the filter debug representations
This commit is contained in:
Valentin Tolmer
2025-04-25 15:10:19 +09:00
committed by nitnelave
parent 4018a6933c
commit b4f636ded9
4 changed files with 42 additions and 43 deletions

View File

@@ -39,23 +39,27 @@ fn attribute_condition(name: AttributeName, value: Option<Serialized>) -> Cond {
fn get_group_filter_expr(filter: GroupRequestFilter) -> Cond {
use GroupRequestFilter::*;
let group_table = Alias::new("groups");
fn bool_to_expr(b: bool) -> Cond {
SimpleExpr::Value(b.into()).into_condition()
}
fn get_repeated_filter(
fs: Vec<GroupRequestFilter>,
condition: Cond,
default_value: bool,
) -> Cond {
if fs.is_empty() {
bool_to_expr(default_value)
} else {
fs.into_iter()
.map(get_group_filter_expr)
.fold(condition, Cond::add)
}
}
match filter {
And(fs) => {
if fs.is_empty() {
SimpleExpr::Value(true.into()).into_condition()
} else {
fs.into_iter()
.fold(Cond::all(), |c, f| c.add(get_group_filter_expr(f)))
}
}
Or(fs) => {
if fs.is_empty() {
SimpleExpr::Value(false.into()).into_condition()
} else {
fs.into_iter()
.fold(Cond::any(), |c, f| c.add(get_group_filter_expr(f)))
}
}
True => bool_to_expr(true),
False => bool_to_expr(false),
And(fs) => get_repeated_filter(fs, Cond::all(), true),
Or(fs) => get_repeated_filter(fs, Cond::any(), false),
Not(f) => get_group_filter_expr(*f).not(),
DisplayName(name) => GroupColumn::LowercaseDisplayName
.eq(name.as_str().to_lowercase())