mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-23 15:17:57 +01:00
49 lines
1.4 KiB
Rust
49 lines
1.4 KiB
Rust
use api::user_capnp::user;
|
|
use api::users_capnp::users;
|
|
use capnp::capability::Promise;
|
|
use capnp_rpc::pry;
|
|
use tracing::Span;
|
|
|
|
use crate::capnp::user::User;
|
|
|
|
use crate::session::SessionHandle;
|
|
use crate::users::{db, UserRef};
|
|
|
|
const TARGET: &str = "bffh::api::usersystem";
|
|
|
|
#[derive(Clone)]
|
|
pub struct Users {
|
|
span: Span,
|
|
session: SessionHandle,
|
|
}
|
|
|
|
impl Users {
|
|
pub fn new(session: SessionHandle) -> Self {
|
|
let span = tracing::info_span!(target: TARGET, "UserSystem",);
|
|
Self { span, session }
|
|
}
|
|
}
|
|
|
|
impl users::Server for Users {
|
|
fn list(&mut self, _: users::ListParams<>, mut result: users::ListResults<>) -> Promise<(), capnp::Error> {
|
|
let _guard = self.span.enter();
|
|
let _span = tracing::trace_span!(target: TARGET, "list",).entered();
|
|
tracing::trace!("method call");
|
|
|
|
let userdb = self.session.users.into_inner();
|
|
let users = pry!(userdb
|
|
.get_all()
|
|
.map_err(|e| capnp::Error::failed(format!("UserDB error: {:?}", e))));
|
|
let mut builder = result.get().init_users(users.len() as u32);
|
|
for (i, (id, userdata)) in users.into_iter().enumerate() {
|
|
let user = User::new(self.session.clone(), UserRef::new(id));
|
|
let client: user::Client = capnp_rpc::new_client(user);
|
|
builder.reborrow().set(i as u32, client.client.hook);
|
|
}
|
|
|
|
tracing::trace!("method return");
|
|
Promise::ok(())
|
|
|
|
}
|
|
}
|