2022-11-07 11:58:38 +01:00
|
|
|
use capnp_rpc::CapabilityServerSet;
|
2022-04-21 23:02:58 +02:00
|
|
|
use crate::authorization::permissions::Permission;
|
2022-11-04 17:25:17 +01:00
|
|
|
use api::auth_capnp::response::successful::Builder;
|
2022-11-07 11:58:38 +01:00
|
|
|
use api::role_capnp;
|
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-11-07 11:58:38 +01:00
|
|
|
use crate::capnp::role::Role;
|
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
|
|
|
|
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
|
|
|
|
2022-11-04 17:25:17 +01:00
|
|
|
builder.reborrow().set_resources(capnp_rpc::new_client(Machines::new(session.clone())));
|
2022-04-21 23:02:58 +02:00
|
|
|
|
2022-11-04 17:25:17 +01:00
|
|
|
if session.has_perm(Permission::new("bffh.users.manage"))
|
2022-04-21 23:02:58 +02:00
|
|
|
{
|
|
|
|
let u = Users::new(session.clone());
|
2022-11-04 17:25:17 +01:00
|
|
|
builder.reborrow().set_users(capnp_rpc::new_client(u.clone()));
|
2022-04-21 23:02:58 +02:00
|
|
|
}
|
|
|
|
|
2022-11-04 17:25:17 +01:00
|
|
|
builder.set_permissions(capnp_rpc::new_client(Permissions::new(session)));
|
2021-12-06 21:53:42 +01:00
|
|
|
}
|
2022-05-05 15:50:44 +02:00
|
|
|
}
|