From 9461f6384269db25032813a463429c4dd18180f4 Mon Sep 17 00:00:00 2001 From: Mauro D Date: Thu, 21 Jul 2022 16:53:38 +0000 Subject: [PATCH] ACL enhancements. --- src/email/helpers.rs | 13 +++++++++++++ src/mailbox/get.rs | 4 ++++ src/mailbox/mod.rs | 9 ++++++++- src/mailbox/set.rs | 17 +++++++++++++---- src/principal/mod.rs | 19 +++++++++++++++++++ 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/email/helpers.rs b/src/email/helpers.rs index d200a6d..eb9e6a3 100644 --- a/src/email/helpers.rs +++ b/src/email/helpers.rs @@ -188,6 +188,19 @@ impl Client { request.send_single::().await } + pub async fn email_query_changes( + &self, + since_query_state: impl Into, + filter: Option>>, + ) -> crate::Result { + let mut request = self.build(); + let query_request = request.query_email_changes(since_query_state); + if let Some(filter) = filter { + query_request.filter(filter); + } + request.send_single::().await + } + pub async fn email_parse( &self, blob_id: &str, diff --git a/src/mailbox/get.rs b/src/mailbox/get.rs index 555cbed..197b009 100644 --- a/src/mailbox/get.rs +++ b/src/mailbox/get.rs @@ -56,6 +56,10 @@ impl Mailbox { pub fn acl(&self) -> Option<&HashMap>> { self.acl.as_ref() } + + pub fn take_acl(&mut self) -> Option>> { + self.acl.take() + } } impl MailboxRights { diff --git a/src/mailbox/mod.rs b/src/mailbox/mod.rs index 4bfdbe1..a8280c1 100644 --- a/src/mailbox/mod.rs +++ b/src/mailbox/mod.rs @@ -93,7 +93,14 @@ pub struct Mailbox { #[serde(flatten)] #[serde(skip_deserializing)] #[serde(skip_serializing_if = "Option::is_none")] - acl_patch: Option>>, + acl_patch: Option>, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(untagged)] +pub(crate) enum ACLPatch { + Replace(Vec), + Set(bool), } #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] diff --git a/src/mailbox/set.rs b/src/mailbox/set.rs index 60791e5..cf568f5 100644 --- a/src/mailbox/set.rs +++ b/src/mailbox/set.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use crate::{core::set::SetObject, principal::ACL, Get, Set}; -use super::{Mailbox, Role, SetArguments}; +use super::{ACLPatch, Mailbox, Role, SetArguments}; impl Mailbox { pub fn name(&mut self, name: impl Into) -> &mut Self { @@ -54,9 +54,18 @@ impl Mailbox { } pub fn acl(&mut self, id: &str, acl: impl IntoIterator) -> &mut Self { - self.acl_patch - .get_or_insert_with(HashMap::new) - .insert(format!("acl/{}", id), acl.into_iter().collect()); + self.acl_patch.get_or_insert_with(HashMap::new).insert( + format!("acl/{}", id), + ACLPatch::Replace(acl.into_iter().collect()), + ); + self + } + + pub fn acl_set(&mut self, id: &str, acl: ACL, set: bool) -> &mut Self { + self.acl_patch.get_or_insert_with(HashMap::new).insert( + format!("acl/{}/{}", id, acl.to_string()), + ACLPatch::Set(set), + ); self } } diff --git a/src/principal/mod.rs b/src/principal/mod.rs index ce92d65..03f0563 100644 --- a/src/principal/mod.rs +++ b/src/principal/mod.rs @@ -159,6 +159,25 @@ impl Display for Property { } } +impl Display for ACL { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ACL::Read => write!(f, "read"), + ACL::Modify => write!(f, "modify"), + ACL::Delete => write!(f, "delete"), + ACL::ReadItems => write!(f, "readItems"), + ACL::AddItems => write!(f, "addItems"), + ACL::ModifyItems => write!(f, "modifyItems"), + ACL::RemoveItems => write!(f, "removeItems"), + ACL::CreateChild => write!(f, "createChild"), + ACL::Administer => write!(f, "administer"), + ACL::SetSeen => write!(f, "setSeen"), + ACL::SetKeywords => write!(f, "setKeywords"), + ACL::Submit => write!(f, "submit"), + } + } +} + impl Object for Principal { type Property = Property;