diff --git a/src/api2/admin/sync.rs b/src/api2/admin/sync.rs index 965be8d0..089e6f50 100644 --- a/src/api2/admin/sync.rs +++ b/src/api2/admin/sync.rs @@ -47,6 +47,16 @@ impl From for ListSyncDirection { } } +impl ListSyncDirection { + /// Checks whether a `ListSyncDirection` matches a given `SyncDirection` + pub fn matches(&self, other: SyncDirection) -> bool { + if *self == ListSyncDirection::All { + return true; + } + *self == other.into() + } +} + #[api( input: { properties: { @@ -94,10 +104,8 @@ pub fn list_config_sync_jobs( _ => {} } - match &sync_direction { - ListSyncDirection::Pull if direction != SyncDirection::Pull => continue, - ListSyncDirection::Push if direction != SyncDirection::Push => continue, - _ => {} + if !sync_direction.matches(direction) { + continue; } if !check_sync_job_read_access(&user_info, &auth_id, &job) { diff --git a/src/api2/config/sync.rs b/src/api2/config/sync.rs index e8a1ad07..bc012744 100644 --- a/src/api2/config/sync.rs +++ b/src/api2/config/sync.rs @@ -15,9 +15,9 @@ use pbs_api_types::{ }; use pbs_config::sync; +use crate::api2::admin::sync::ListSyncDirection; use pbs_config::CachedUserInfo; use pbs_datastore::check_backup_owner; -use crate::api2::admin::sync::ListSyncDirection; pub fn check_sync_job_read_access( user_info: &CachedUserInfo, @@ -185,13 +185,8 @@ pub fn list_sync_jobs( let list = list .into_iter() .filter(|sync_job| { - let direction = sync_job.sync_direction.unwrap_or_default(); - match &sync_direction { - ListSyncDirection::Pull if direction != SyncDirection::Pull => return false, - ListSyncDirection::Push if direction != SyncDirection::Push => return false, - _ => {} - } - check_sync_job_read_access(&user_info, &auth_id, sync_job) + sync_direction.matches(sync_job.sync_direction.unwrap_or_default()) + && check_sync_job_read_access(&user_info, &auth_id, sync_job) }) .collect(); Ok(list)