server: Fix implementation of attribute present filter

Instead of just doing a schema check, this actually looks for users that have a value for this attribute.
This commit is contained in:
Valentin Tolmer
2024-08-16 23:48:15 +02:00
committed by nitnelave
parent ee7f9c9f41
commit 09c5d9f925
6 changed files with 72 additions and 18 deletions
@@ -175,7 +175,9 @@ impl SqlBackendHandler {
mod tests {
use super::*;
use crate::domain::{
handler::AttributeList, sql_backend_handler::tests::*, types::AttributeType,
handler::{AttributeList, UpdateUserRequest, UserBackendHandler, UserRequestFilter},
sql_backend_handler::tests::*,
types::{AttributeType, AttributeValue, Serialized},
};
use pretty_assertions::assert_eq;
@@ -268,6 +270,43 @@ mod tests {
.contains(&expected_value));
}
#[tokio::test]
async fn test_user_attribute_present_filter() {
let fixture = TestFixture::new().await;
let new_attribute = CreateAttributeRequest {
name: "new_attribute".into(),
attribute_type: AttributeType::Integer,
is_list: true,
is_visible: false,
is_editable: false,
};
fixture
.handler
.add_user_attribute(new_attribute)
.await
.unwrap();
fixture
.handler
.update_user(UpdateUserRequest {
user_id: "bob".into(),
insert_attributes: vec![AttributeValue {
name: "new_attribute".into(),
value: Serialized::from(&3),
}],
..Default::default()
})
.await
.unwrap();
let users = get_user_names(
&fixture.handler,
Some(UserRequestFilter::CustomAttributePresent(
"new_attribute".into(),
)),
)
.await;
assert_eq!(users, vec!["bob"]);
}
#[tokio::test]
async fn test_group_attribute_add_and_delete() {
let fixture = TestFixture::new().await;