Implement changes from fabaccess-api#24

This commit is contained in:
Nadja Reitzenstein 2022-04-22 20:09:34 +02:00
parent 047f7bc1de
commit 3300105082
4 changed files with 33 additions and 31 deletions

@ -1 +1 @@
Subproject commit aa006507c48ac734fd09d524d0c84736b0147338
Subproject commit aea03aabe3d1322892c1896ba757ceeedb92ed73

View File

@ -82,7 +82,7 @@ pub mod machine {
::capnp::traits::FromU16::from_u16(self.reader.get_data_field::<u16>(0))
}
#[inline]
pub fn get_manager(self) -> ::capnp::Result<crate::schema::user_capnp::user::Reader<'a>> {
pub fn get_manager(self) -> ::capnp::Result<crate::schema::general_capnp::optional::Reader<'a,crate::schema::user_capnp::user::Owned>> {
::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::<u16>(0, value as u16)
}
#[inline]
pub fn get_manager(self) -> ::capnp::Result<crate::schema::user_capnp::user::Builder<'a>> {
pub fn get_manager(self) -> ::capnp::Result<crate::schema::general_capnp::optional::Builder<'a,crate::schema::user_capnp::user::Owned>> {
::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<()> {
<crate::schema::general_capnp::optional::Reader<'_,crate::schema::user_capnp::user::Owned> 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<crate::schema::user_capnp::user::Owned> {
::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<crate::schema::user_capnp::user::Reader<'a>> {
pub fn get_current_user(self) -> ::capnp::Result<crate::schema::general_capnp::optional::Reader<'a,crate::schema::user_capnp::user::Owned>> {
::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<crate::schema::user_capnp::user::Reader<'a>> {
pub fn get_last_user(self) -> ::capnp::Result<crate::schema::general_capnp::optional::Reader<'a,crate::schema::user_capnp::user::Owned>> {
::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<crate::schema::user_capnp::user::Reader<'a>> {
pub fn get_instructor_user(self) -> ::capnp::Result<crate::schema::general_capnp::optional::Reader<'a,crate::schema::user_capnp::user::Owned>> {
::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<crate::schema::user_capnp::user::Builder<'a>> {
pub fn get_current_user(self) -> ::capnp::Result<crate::schema::general_capnp::optional::Builder<'a,crate::schema::user_capnp::user::Owned>> {
::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<()> {
<crate::schema::general_capnp::optional::Reader<'_,crate::schema::user_capnp::user::Owned> 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<crate::schema::user_capnp::user::Builder<'a>> {
pub fn get_last_user(self) -> ::capnp::Result<crate::schema::general_capnp::optional::Builder<'a,crate::schema::user_capnp::user::Owned>> {
::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<()> {
<crate::schema::general_capnp::optional::Reader<'_,crate::schema::user_capnp::user::Owned> 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<crate::schema::user_capnp::user::Builder<'a>> {
pub fn get_instructor_user(self) -> ::capnp::Result<crate::schema::general_capnp::optional::Builder<'a,crate::schema::user_capnp::user::Owned>> {
::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<()> {
<crate::schema::general_capnp::optional::Reader<'_,crate::schema::user_capnp::user::Owned> 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<crate::schema::user_capnp::user::Owned> {
::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<crate::schema::user_capnp::user::Owned> {
::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<crate::schema::user_capnp::user::Owned> {
::capnp::capability::FromTypelessPipeline::new(self._typeless.get_pointer_field(2))
}
}

View File

@ -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(

View File

@ -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<UserRef>, builder: Builder) {
pub fn build_optional(&self, user: Option<UserRef>, builder: optional::Builder<user::Owned>) {
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()));