bffh/src/api/users.rs

55 lines
1.3 KiB
Rust
Raw Normal View History

2021-09-19 19:47:29 +02:00
use capnp::capability::Promise;
use crate::db::access::{PermRule, Permission};
use crate::schema::usersystem_capnp::user_system;
use crate::schema::usersystem_capnp::user_system::{info, manage};
#[derive(Clone, Debug)]
pub struct Users {
perms: Vec<PermRule>,
}
impl Users {
pub fn new(perms: Vec<PermRule>) -> Self {
Self { perms }
}
}
impl user_system::Server for Users {
fn info(
&mut self,
_: user_system::InfoParams,
2021-09-19 22:53:43 +02:00
mut results: user_system::InfoResults,
2021-09-19 19:47:29 +02:00
) -> Promise<(), capnp::Error> {
2021-09-19 22:53:43 +02:00
results.get().set_info(capnp_rpc::new_client(self.clone()));
2021-09-19 19:47:29 +02:00
Promise::ok(())
}
fn manage(
&mut self,
_: user_system::ManageParams,
mut results: user_system::ManageResults,
) -> Promise<(), capnp::Error> {
let perm: &Permission = Permission::new("bffh.users.manage");
if self.perms.iter().any(|rule| rule.match_perm(perm)) {
2021-09-19 22:53:43 +02:00
results
.get()
.set_manage(capnp_rpc::new_client(self.clone()));
2021-09-19 19:47:29 +02:00
}
Promise::ok(())
}
}
2021-09-19 22:53:43 +02:00
impl info::Server for Users {
fn get_user_self(
&mut self,
_: info::GetUserSelfParams,
mut results: info::GetUserSelfResults,
) -> Promise<(), capnp::Error> {
Promise::ok(())
}
}
2021-09-19 19:47:29 +02:00
impl manage::Server for Users {}