From 069819bb9a765426ae6b6d236929bd84e1b7e4d5 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Wed, 16 Mar 2022 15:04:32 +0100 Subject: [PATCH] Only return `use` interface if machine is currently free or reserved by me --- src/api/machines.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/api/machines.rs b/src/api/machines.rs index 6635902..a57e662 100644 --- a/src/api/machines.rs +++ b/src/api/machines.rs @@ -216,9 +216,18 @@ async fn fill_machine_builder( builder.set_urn(&format!("urn:fabaccess:resource:{}", id.as_ref())); let machineapi = Machine::new(user.clone(), perms, machine.clone()); - if perms.write { + let state = machine.get_status().await; + + // Only set `use` interf if machine could be used by the user. + if perms.write && match &state { + Status::Free => true, + Status::Reserved(reserver) if reserver == user => true, + _ => false, + } + { builder.set_use(capnp_rpc::new_client(machineapi.clone())); } + if perms.manage { //builder.set_transfer(capnp_rpc::new_client(machineapi.clone())); //builder.set_check(capnp_rpc::new_client(machineapi.clone())); @@ -228,12 +237,11 @@ async fn fill_machine_builder( builder.set_admin(capnp_rpc::new_client(machineapi.clone())); } - - let s = match machine.get_status().await { + let s = match state { Status::Free => MachineState::Free, Status::Disabled => MachineState::Disabled, Status::Blocked(_) => MachineState::Blocked, - Status::InUse(u) => { + Status::InUse(ref u) => { if let Some(owner) = u.as_ref() { if owner == user { builder.set_inuse(capnp_rpc::new_client(machineapi.clone()));