mirror of
git://git.proxmox.com/git/proxmox-backup.git
synced 2025-01-06 13:18:00 +03:00
api: sync direction: extract match check into impl fn
In case we add another direction or another call site, doing it without a wildcard match arm seems cleaner and more future-proof. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Reviewed-by: Dominik Csapak <d.csapak@proxmox.com> Tested-by: Dominik Csapak <d.csapak@proxmox.com> [ TL: adapt subject/message slightly ] Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
parent
e9dfb83131
commit
b3f16f6227
@ -47,6 +47,16 @@ impl From<SyncDirection> 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) {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user