fabaccess-bffh/bffhd/capnp/permissionsystem.rs

49 lines
1.3 KiB
Rust
Raw Normal View History

use crate::Roles;
use api::permissionsystem_capnp::permission_system::info::{
GetRoleListParams, GetRoleListResults, Server as PermissionSystem,
};
use capnp::capability::Promise;
use capnp::Error;
2022-06-24 13:57:47 +02:00
use tracing::Span;
2022-03-15 20:00:43 +01:00
2022-03-12 17:31:53 +01:00
use crate::session::SessionHandle;
2022-06-24 13:57:47 +02:00
const TARGET: &str = "bffh::api::permissionsystem";
pub struct Permissions {
2022-06-24 13:57:47 +02:00
span: Span,
roles: Roles,
}
2022-03-12 17:31:53 +01:00
impl Permissions {
pub fn new(session: SessionHandle) -> Self {
2022-06-24 13:57:47 +02:00
let span = tracing::info_span!(target: TARGET, "PermissionSystem",);
Self {
2022-06-24 13:57:47 +02:00
span,
roles: session.roles,
}
2022-03-12 17:31:53 +01:00
}
}
impl PermissionSystem for Permissions {
fn get_role_list(
&mut self,
_: GetRoleListParams,
mut results: GetRoleListResults,
) -> Promise<(), Error> {
2022-06-24 13:57:47 +02:00
let _guard = self.span.enter();
let _span = tracing::trace_span!(target: TARGET, "getRoleList",).entered();
tracing::trace!("method call");
let roles = self.roles.list().collect::<Vec<&String>>();
2024-12-13 08:18:25 +01:00
let builder = results.get();
let mut b = builder.init_role_list(roles.len() as u32);
for (i, role) in roles.into_iter().enumerate() {
let mut role_builder = b.reborrow().get(i as u32);
role_builder.set_name(role);
}
2022-06-24 13:57:47 +02:00
tracing::trace!("method return");
Promise::ok(())
}
}