Add owner and device type filters to device list

Owner filter uses a server-side substring match (LIKE '%VALUE%');
device type filter matches the stored value exactly, sending an
empty string for unknown/unclassified devices. Both filters combine
with the existing registration status chip via AND logic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
rzuasti
2026-05-27 19:46:19 -04:00
co-authored by Claude Sonnet 4.6
parent bf74cbb38e
commit e7d075ec29
3 changed files with 135 additions and 30 deletions
+23 -2
View File
@@ -54,8 +54,8 @@ pub fn list_devices(
};
if let Some(owner) = owner {
debug!("Adding filter owner={}", owner);
sql_statement.push_str("AND owner=? ");
params.push(owner.into());
sql_statement.push_str("AND owner LIKE ? ");
params.push(format!("%{}%", owner).into());
};
if let Some(device_type) = device_type {
debug!("Adding filter device_type={}", device_type);
@@ -241,6 +241,27 @@ mod tests {
"Vendor 2".to_string(),
);
// Filter by owner substring - "oh" matches "John" but not "Sarah"
let devices: Vec<Device> =
list_devices(None, None, None, Some("oh".to_string()), None, None).unwrap();
assert!(
devices.len() >= 1,
"There should be at least one device matching owner 'oh'"
);
assert!(
devices
.iter()
.any(|item| item.mac_address == "bb:bb:bb:bb:bb:bb"),
"Device bb:bb:bb:bb:bb:bb (John) should be present"
);
assert!(
!devices
.iter()
.any(|item| item.mac_address == "cc:cc:cc:cc:cc:cc"),
"Device cc:cc:cc:cc:cc:cc (Sarah) should not be present"
);
// List devices seen in a time period - 2026-02-03 13:14:15
let devices = list_devices(
None,