From 3300105082a2abd44ae1f2cf9af8e7b19a50fb68 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Fri, 22 Apr 2022 20:09:34 +0200 Subject: [PATCH] Implement changes from fabaccess-api#24 --- api/schema | 2 +- api/src/schema/machine_capnp.rs | 48 ++++++++++++++++----------------- bffhd/capnp/machine.rs | 4 +-- bffhd/capnp/user.rs | 10 ++++--- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/api/schema b/api/schema index aa00650..aea03aa 160000 --- a/api/schema +++ b/api/schema @@ -1 +1 @@ -Subproject commit aa006507c48ac734fd09d524d0c84736b0147338 +Subproject commit aea03aabe3d1322892c1896ba757ceeedb92ed73 diff --git a/api/src/schema/machine_capnp.rs b/api/src/schema/machine_capnp.rs index 7fb82ab..855ea7b 100644 --- a/api/src/schema/machine_capnp.rs +++ b/api/src/schema/machine_capnp.rs @@ -82,7 +82,7 @@ pub mod machine { ::capnp::traits::FromU16::from_u16(self.reader.get_data_field::(0)) } #[inline] - pub fn get_manager(self) -> ::capnp::Result> { + pub fn get_manager(self) -> ::capnp::Result> { ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(4), ::core::option::Option::None) } pub fn has_manager(&self) -> bool { @@ -256,15 +256,15 @@ pub mod machine { self.builder.set_data_field::(0, value as u16) } #[inline] - pub fn get_manager(self) -> ::capnp::Result> { + pub fn get_manager(self) -> ::capnp::Result> { ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(4), ::core::option::Option::None) } #[inline] - pub fn set_manager(&mut self, value: crate::schema::user_capnp::user::Reader<'_>) -> ::capnp::Result<()> { - ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(4), value, false) + pub fn set_manager(&mut self, value: crate::schema::general_capnp::optional::Reader<'_,crate::schema::user_capnp::user::Owned>) -> ::capnp::Result<()> { + as ::capnp::traits::SetPointerBuilder>::set_pointer_builder(self.builder.get_pointer_field(4), value, false) } #[inline] - pub fn init_manager(self, ) -> crate::schema::user_capnp::user::Builder<'a> { + pub fn init_manager(self, ) -> crate::schema::general_capnp::optional::Builder<'a,crate::schema::user_capnp::user::Owned> { ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(4), 0) } pub fn has_manager(&self) -> bool { @@ -383,7 +383,7 @@ pub mod machine { pub fn get_space(&self) -> crate::schema::space_capnp::space::Pipeline { ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(1)) } - pub fn get_manager(&self) -> crate::schema::user_capnp::user::Pipeline { + pub fn get_manager(&self) -> crate::schema::general_capnp::optional::Pipeline { ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(4)) } pub fn get_info(&self) -> crate::schema::machine_capnp::machine::info::Client { @@ -496,21 +496,21 @@ pub mod machine { self.reader.total_size() } #[inline] - pub fn get_current_user(self) -> ::capnp::Result> { + pub fn get_current_user(self) -> ::capnp::Result> { ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(0), ::core::option::Option::None) } pub fn has_current_user(&self) -> bool { !self.reader.get_pointer_field(0).is_null() } #[inline] - pub fn get_last_user(self) -> ::capnp::Result> { + pub fn get_last_user(self) -> ::capnp::Result> { ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(1), ::core::option::Option::None) } pub fn has_last_user(&self) -> bool { !self.reader.get_pointer_field(1).is_null() } #[inline] - pub fn get_instructor_user(self) -> ::capnp::Result> { + pub fn get_instructor_user(self) -> ::capnp::Result> { ::capnp::traits::FromPointerReader::get_from_pointer(&self.reader.get_pointer_field(2), ::core::option::Option::None) } pub fn has_instructor_user(&self) -> bool { @@ -567,45 +567,45 @@ pub mod machine { self.builder.into_reader().total_size() } #[inline] - pub fn get_current_user(self) -> ::capnp::Result> { + pub fn get_current_user(self) -> ::capnp::Result> { ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None) } #[inline] - pub fn set_current_user(&mut self, value: crate::schema::user_capnp::user::Reader<'_>) -> ::capnp::Result<()> { - ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(0), value, false) + pub fn set_current_user(&mut self, value: crate::schema::general_capnp::optional::Reader<'_,crate::schema::user_capnp::user::Owned>) -> ::capnp::Result<()> { + as ::capnp::traits::SetPointerBuilder>::set_pointer_builder(self.builder.get_pointer_field(0), value, false) } #[inline] - pub fn init_current_user(self, ) -> crate::schema::user_capnp::user::Builder<'a> { + pub fn init_current_user(self, ) -> crate::schema::general_capnp::optional::Builder<'a,crate::schema::user_capnp::user::Owned> { ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(0), 0) } pub fn has_current_user(&self) -> bool { !self.builder.get_pointer_field(0).is_null() } #[inline] - pub fn get_last_user(self) -> ::capnp::Result> { + pub fn get_last_user(self) -> ::capnp::Result> { ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None) } #[inline] - pub fn set_last_user(&mut self, value: crate::schema::user_capnp::user::Reader<'_>) -> ::capnp::Result<()> { - ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(1), value, false) + pub fn set_last_user(&mut self, value: crate::schema::general_capnp::optional::Reader<'_,crate::schema::user_capnp::user::Owned>) -> ::capnp::Result<()> { + as ::capnp::traits::SetPointerBuilder>::set_pointer_builder(self.builder.get_pointer_field(1), value, false) } #[inline] - pub fn init_last_user(self, ) -> crate::schema::user_capnp::user::Builder<'a> { + pub fn init_last_user(self, ) -> crate::schema::general_capnp::optional::Builder<'a,crate::schema::user_capnp::user::Owned> { ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(1), 0) } pub fn has_last_user(&self) -> bool { !self.builder.get_pointer_field(1).is_null() } #[inline] - pub fn get_instructor_user(self) -> ::capnp::Result> { + pub fn get_instructor_user(self) -> ::capnp::Result> { ::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(2), ::core::option::Option::None) } #[inline] - pub fn set_instructor_user(&mut self, value: crate::schema::user_capnp::user::Reader<'_>) -> ::capnp::Result<()> { - ::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.get_pointer_field(2), value, false) + pub fn set_instructor_user(&mut self, value: crate::schema::general_capnp::optional::Reader<'_,crate::schema::user_capnp::user::Owned>) -> ::capnp::Result<()> { + as ::capnp::traits::SetPointerBuilder>::set_pointer_builder(self.builder.get_pointer_field(2), value, false) } #[inline] - pub fn init_instructor_user(self, ) -> crate::schema::user_capnp::user::Builder<'a> { + pub fn init_instructor_user(self, ) -> crate::schema::general_capnp::optional::Builder<'a,crate::schema::user_capnp::user::Owned> { ::capnp::traits::FromPointerBuilder::init_pointer(self.builder.get_pointer_field(2), 0) } pub fn has_instructor_user(&self) -> bool { @@ -620,13 +620,13 @@ pub mod machine { } } impl Pipeline { - pub fn get_current_user(&self) -> crate::schema::user_capnp::user::Pipeline { + pub fn get_current_user(&self) -> crate::schema::general_capnp::optional::Pipeline { ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(0)) } - pub fn get_last_user(&self) -> crate::schema::user_capnp::user::Pipeline { + pub fn get_last_user(&self) -> crate::schema::general_capnp::optional::Pipeline { ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(1)) } - pub fn get_instructor_user(&self) -> crate::schema::user_capnp::user::Pipeline { + pub fn get_instructor_user(&self) -> crate::schema::general_capnp::optional::Pipeline { ::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(2)) } } diff --git a/bffhd/capnp/machine.rs b/bffhd/capnp/machine.rs index b25c231..eb6b693 100644 --- a/bffhd/capnp/machine.rs +++ b/bffhd/capnp/machine.rs @@ -208,8 +208,8 @@ impl ManageServer for Machine { ) -> Promise<(), ::capnp::Error> { let mut builder = result.get(); let user = User::new_self(self.session.clone()); - user.build_else(self.resource.get_current_user(), builder.reborrow().init_current_user()); - user.build_else(self.resource.get_previous_user(), builder.init_last_user()); + user.build_optional(self.resource.get_current_user(), builder.reborrow().init_current_user()); + user.build_optional(self.resource.get_previous_user(), builder.init_last_user()); Promise::ok(()) } fn set_property( diff --git a/bffhd/capnp/user.rs b/bffhd/capnp/user.rs index c72c541..85890a5 100644 --- a/bffhd/capnp/user.rs +++ b/bffhd/capnp/user.rs @@ -1,7 +1,8 @@ use capnp::capability::Promise; use capnp_rpc::pry; use crate::session::SessionHandle; -use api::user_capnp::user::{admin, info, manage, Builder}; +use api::user_capnp::user::{admin, info, manage, self}; +use api::general_capnp::optional; use crate::authorization::permissions::Permission; use crate::users::{db, UserRef}; @@ -21,19 +22,20 @@ impl User { Self::new(session, user) } - pub fn build_else(&self, user: Option, builder: Builder) { + pub fn build_optional(&self, user: Option, builder: optional::Builder) { if let Some(user) = user.and_then(|u| self.session.users.get_user(u.get_username())) { + let mut builder = builder.init_just(); self.fill(user, builder); } } - pub fn build(session: SessionHandle, mut builder: Builder) { + pub fn build(session: SessionHandle, mut builder: user::Builder) { let this = Self::new_self(session); let user = this.session.get_user(); this.fill(user, builder); } - pub fn fill(&self, user: db::User, mut builder: Builder) { + pub fn fill(&self, user: db::User, mut builder: user::Builder) { builder.set_username(user.id.as_str()); let client = Self::new(self.session.clone(), UserRef::new(user.id.clone()));