2022-04-21 23:02:58 +02:00
|
|
|
use crate::authorization::permissions::Permission;
|
2022-05-05 15:50:44 +02:00
|
|
|
use api::authenticationsystem_capnp::response::successful::Builder;
|
2022-03-15 20:00:43 +01:00
|
|
|
|
2022-03-11 22:13:54 +01:00
|
|
|
use crate::capnp::machinesystem::Machines;
|
2022-03-12 17:31:53 +01:00
|
|
|
use crate::capnp::permissionsystem::Permissions;
|
2022-03-11 22:13:54 +01:00
|
|
|
use crate::capnp::user_system::Users;
|
2022-05-05 15:50:44 +02:00
|
|
|
use crate::session::SessionHandle;
|
2021-12-06 21:53:42 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
2022-03-12 17:31:53 +01:00
|
|
|
pub struct APISession;
|
2021-12-06 21:53:42 +01:00
|
|
|
|
2022-03-12 17:31:53 +01:00
|
|
|
impl APISession {
|
2021-12-06 21:53:42 +01:00
|
|
|
pub fn new() -> Self {
|
2022-03-12 17:31:53 +01:00
|
|
|
Self
|
|
|
|
}
|
|
|
|
|
2022-03-15 20:00:43 +01:00
|
|
|
pub fn build(session: SessionHandle, builder: Builder) {
|
2022-03-12 17:31:53 +01:00
|
|
|
let mut builder = builder.init_session();
|
2022-04-21 23:02:58 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
let mut b = builder.reborrow().init_machine_system();
|
|
|
|
b.set_info(capnp_rpc::new_client(Machines::new(session.clone())));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let mut b = builder.reborrow().init_user_system();
|
|
|
|
let u = Users::new(session.clone());
|
|
|
|
if session.has_perm(Permission::new("bffh.users.manage")) {
|
|
|
|
b.set_manage(capnp_rpc::new_client(u.clone()));
|
2022-04-28 20:35:06 +02:00
|
|
|
b.set_search(capnp_rpc::new_client(u.clone()));
|
2022-04-21 23:02:58 +02:00
|
|
|
}
|
|
|
|
b.set_info(capnp_rpc::new_client(u));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let mut b = builder.init_permission_system();
|
|
|
|
b.set_info(capnp_rpc::new_client(Permissions::new(session)));
|
|
|
|
}
|
2021-12-06 21:53:42 +01:00
|
|
|
}
|
2022-05-05 15:50:44 +02:00
|
|
|
}
|