mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-08-11 23:19:41 +00: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(
|
#[api(
|
||||||
input: {
|
input: {
|
||||||
properties: {
|
properties: {
|
||||||
@ -94,10 +104,8 @@ pub fn list_config_sync_jobs(
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
match &sync_direction {
|
if !sync_direction.matches(direction) {
|
||||||
ListSyncDirection::Pull if direction != SyncDirection::Pull => continue,
|
continue;
|
||||||
ListSyncDirection::Push if direction != SyncDirection::Push => continue,
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !check_sync_job_read_access(&user_info, &auth_id, &job) {
|
if !check_sync_job_read_access(&user_info, &auth_id, &job) {
|
||||||
|
@ -15,9 +15,9 @@ use pbs_api_types::{
|
|||||||
};
|
};
|
||||||
use pbs_config::sync;
|
use pbs_config::sync;
|
||||||
|
|
||||||
|
use crate::api2::admin::sync::ListSyncDirection;
|
||||||
use pbs_config::CachedUserInfo;
|
use pbs_config::CachedUserInfo;
|
||||||
use pbs_datastore::check_backup_owner;
|
use pbs_datastore::check_backup_owner;
|
||||||
use crate::api2::admin::sync::ListSyncDirection;
|
|
||||||
|
|
||||||
pub fn check_sync_job_read_access(
|
pub fn check_sync_job_read_access(
|
||||||
user_info: &CachedUserInfo,
|
user_info: &CachedUserInfo,
|
||||||
@ -185,13 +185,8 @@ pub fn list_sync_jobs(
|
|||||||
let list = list
|
let list = list
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|sync_job| {
|
.filter(|sync_job| {
|
||||||
let direction = sync_job.sync_direction.unwrap_or_default();
|
sync_direction.matches(sync_job.sync_direction.unwrap_or_default())
|
||||||
match &sync_direction {
|
&& check_sync_job_read_access(&user_info, &auth_id, sync_job)
|
||||||
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)
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
Ok(list)
|
Ok(list)
|
||||||
|
Loading…
Reference in New Issue
Block a user