2022-03-16 20:17:59 +01:00
|
|
|
use capnp::capability::Promise;
|
2022-03-11 22:13:54 +01:00
|
|
|
use api::usersystem_capnp::user_system::{
|
2022-03-16 20:17:59 +01:00
|
|
|
info, manage, Server as UserSystem,
|
|
|
|
self as system,
|
2022-03-11 22:13:54 +01:00
|
|
|
};
|
2022-03-16 20:17:59 +01:00
|
|
|
use crate::authorization::permissions::Permission;
|
|
|
|
use crate::capnp::user::User;
|
2022-03-15 20:00:43 +01:00
|
|
|
|
2022-03-12 17:31:53 +01:00
|
|
|
use crate::session::SessionHandle;
|
2022-03-11 22:13:54 +01:00
|
|
|
|
2022-03-15 19:14:04 +01:00
|
|
|
#[derive(Clone)]
|
2022-03-11 22:13:54 +01:00
|
|
|
pub struct Users {
|
2022-03-12 17:31:53 +01:00
|
|
|
session: SessionHandle,
|
2022-03-11 22:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Users {
|
2022-03-12 17:31:53 +01:00
|
|
|
pub fn new(session: SessionHandle) -> Self {
|
2022-03-16 20:17:59 +01:00
|
|
|
Self { session }
|
2022-03-11 22:13:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-16 20:17:59 +01:00
|
|
|
impl system::Server for Users {
|
|
|
|
fn info(
|
|
|
|
&mut self,
|
|
|
|
_: system::InfoParams,
|
|
|
|
mut result: system::InfoResults,
|
|
|
|
) -> Promise<(), ::capnp::Error> {
|
|
|
|
result.get().set_info(capnp_rpc::new_client(self.clone()));
|
|
|
|
Promise::ok(())
|
|
|
|
}
|
|
|
|
fn manage(
|
|
|
|
&mut self,
|
|
|
|
_: system::ManageParams,
|
|
|
|
mut result: system::ManageResults,
|
|
|
|
) -> Promise<(), ::capnp::Error> {
|
|
|
|
if self.session.has_perm(Permission::new("bffh.users.manage")) {
|
|
|
|
result.get().set_manage(capnp_rpc::new_client(self.clone()));
|
|
|
|
}
|
|
|
|
Promise::ok(())
|
|
|
|
}
|
2022-03-11 22:13:54 +01:00
|
|
|
}
|
|
|
|
|
2022-03-16 20:17:59 +01:00
|
|
|
impl info::Server for Users {
|
|
|
|
fn get_user_self(
|
|
|
|
&mut self,
|
|
|
|
_: info::GetUserSelfParams,
|
|
|
|
mut result: info::GetUserSelfResults,
|
|
|
|
) -> Promise<(), ::capnp::Error> {
|
|
|
|
let builder = result.get().init_user();
|
|
|
|
User::build(self.session.clone(), builder);
|
|
|
|
Promise::ok(())
|
|
|
|
}
|
2022-03-11 22:13:54 +01:00
|
|
|
}
|
|
|
|
|
2022-03-16 20:17:59 +01:00
|
|
|
impl manage::Server for Users {
|
|
|
|
fn get_user_list(
|
|
|
|
&mut self,
|
|
|
|
_: manage::GetUserListParams,
|
|
|
|
_: manage::GetUserListResults,
|
|
|
|
) -> Promise<(), ::capnp::Error> {
|
|
|
|
Promise::err(::capnp::Error::unimplemented(
|
|
|
|
"method not implemented".to_string(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
fn add_user(
|
|
|
|
&mut self,
|
|
|
|
_: manage::AddUserParams,
|
|
|
|
_: manage::AddUserResults,
|
|
|
|
) -> Promise<(), ::capnp::Error> {
|
|
|
|
Promise::err(::capnp::Error::unimplemented(
|
|
|
|
"method not implemented".to_string(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
fn remove_user(
|
|
|
|
&mut self,
|
|
|
|
_: manage::RemoveUserParams,
|
|
|
|
_: manage::RemoveUserResults,
|
|
|
|
) -> Promise<(), ::capnp::Error> {
|
|
|
|
Promise::err(::capnp::Error::unimplemented(
|
|
|
|
"method not implemented".to_string(),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
}
|