Only return caps the user can have

This commit is contained in:
Nadja Reitzenstein 2021-09-20 15:10:20 +02:00
parent 27791ed19b
commit f4fead00e6

View File

@ -79,20 +79,29 @@ impl machines::Server for Machines {
builder.set_description(desc); builder.set_description(desc);
} }
let s = match machine.get_status().await { let machineapi = Machine::new(user.clone(), perms, machine.clone());
let state = machine.get_status().await;
let s = match state {
Status::Free => MachineState::Free, Status::Free => MachineState::Free,
Status::Disabled => MachineState::Disabled, Status::Disabled => MachineState::Disabled,
Status::Blocked(_) => MachineState::Blocked, Status::Blocked(_) => MachineState::Blocked,
Status::InUse(_) => MachineState::InUse, Status::InUse(ref u) => {
if let Some(owner) = u.as_ref() {
if owner == user {
builder.set_inuse(capnp_rpc::new_client(machineapi.clone()));
}
}
MachineState::InUse
},
Status::Reserved(_) => MachineState::Reserved, Status::Reserved(_) => MachineState::Reserved,
Status::ToCheck(_) => MachineState::ToCheck, Status::ToCheck(_) => MachineState::ToCheck,
}; };
builder.set_state(s); builder.set_state(s);
let machineapi = Machine::new(user.clone(), perms, machine.clone()); if perms.write && state == Status::Free {
if perms.write {
builder.set_use(capnp_rpc::new_client(machineapi.clone())); builder.set_use(capnp_rpc::new_client(machineapi.clone()));
builder.set_inuse(capnp_rpc::new_client(machineapi.clone()));
} }
if perms.manage { if perms.manage {
builder.set_transfer(capnp_rpc::new_client(machineapi.clone())); builder.set_transfer(capnp_rpc::new_client(machineapi.clone()));