From 58f40d98ed3c4f97ac0f274bbdc63765b5f5a958 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Mon, 20 Jun 2022 15:19:25 +0200 Subject: [PATCH] Implement PermissionSystem::getRoleList() Closes: #62 --- bffhd/authorization/roles.rs | 4 ++++ bffhd/capnp/permissionsystem.rs | 35 ++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/bffhd/authorization/roles.rs b/bffhd/authorization/roles.rs index 0885eca..ef9cb38 100644 --- a/bffhd/authorization/roles.rs +++ b/bffhd/authorization/roles.rs @@ -27,6 +27,10 @@ impl Roles { self.roles.get(roleid) } + pub fn list(&self) -> impl Iterator { + self.roles.keys() + } + /// Tally a role dependency tree into a set /// /// A Default implementation exists which adapter may overwrite with more efficient diff --git a/bffhd/capnp/permissionsystem.rs b/bffhd/capnp/permissionsystem.rs index bad3582..199e5c0 100644 --- a/bffhd/capnp/permissionsystem.rs +++ b/bffhd/capnp/permissionsystem.rs @@ -1,13 +1,38 @@ -use api::permissionsystem_capnp::permission_system::info::Server as PermissionSystem; +use crate::authorization::roles::Role; +use crate::Roles; +use api::permissionsystem_capnp::permission_system::info::{ + GetRoleListParams, GetRoleListResults, Server as PermissionSystem, +}; +use capnp::capability::Promise; +use capnp::Error; use crate::session::SessionHandle; -pub struct Permissions; +pub struct Permissions { + roles: Roles, +} impl Permissions { - pub fn new(_session: SessionHandle) -> Self { - Self + pub fn new(session: SessionHandle) -> Self { + Self { + roles: session.roles, + } } } -impl PermissionSystem for Permissions {} +impl PermissionSystem for Permissions { + fn get_role_list( + &mut self, + _: GetRoleListParams, + mut results: GetRoleListResults, + ) -> Promise<(), Error> { + let roles = self.roles.list().collect::>(); + let mut 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); + } + Promise::ok(()) + } +}