fabaccess-bffh/bffhd/capnp/session.rs
2022-11-04 17:25:17 +01:00

31 lines
896 B
Rust

use crate::authorization::permissions::Permission;
use api::auth_capnp::response::successful::Builder;
use crate::capnp::machinesystem::Machines;
use crate::capnp::permissionsystem::Permissions;
use crate::capnp::user_system::Users;
use crate::session::SessionHandle;
#[derive(Debug, Clone)]
pub struct APISession;
impl APISession {
pub fn new() -> Self {
Self
}
pub fn build(session: SessionHandle, builder: Builder) {
let mut builder = builder.init_session();
builder.reborrow().set_resources(capnp_rpc::new_client(Machines::new(session.clone())));
if session.has_perm(Permission::new("bffh.users.manage"))
{
let u = Users::new(session.clone());
builder.reborrow().set_users(capnp_rpc::new_client(u.clone()));
}
builder.set_permissions(capnp_rpc::new_client(Permissions::new(session)));
}
}