JMAP Sharing Principals
parent
66b70ee79e
commit
f33ab4fbd3
|
@ -3,37 +3,244 @@ use crate::{
|
||||||
core::{
|
core::{
|
||||||
changes::{ChangesRequest, ChangesResponse},
|
changes::{ChangesRequest, ChangesResponse},
|
||||||
get::GetRequest,
|
get::GetRequest,
|
||||||
query::{QueryRequest, QueryResponse},
|
query::{Comparator, Filter, QueryRequest, QueryResponse},
|
||||||
query_changes::{QueryChangesRequest, QueryChangesResponse},
|
query_changes::{QueryChangesRequest, QueryChangesResponse},
|
||||||
request::{Arguments, Request},
|
request::{Arguments, Request},
|
||||||
response::{PrincipalGetResponse, PrincipalSetResponse},
|
response::{PrincipalGetResponse, PrincipalSetResponse},
|
||||||
set::SetRequest,
|
set::{SetObject, SetRequest},
|
||||||
},
|
},
|
||||||
Get, Method, Set,
|
Get, Method, Set,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::Principal;
|
use super::{Principal, Property, Type};
|
||||||
|
|
||||||
impl Client {
|
impl Client {
|
||||||
pub async fn individual_create(
|
pub async fn individual_create(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
email: impl Into<String>,
|
||||||
|
secret: impl Into<String>,
|
||||||
name: impl Into<String>,
|
name: impl Into<String>,
|
||||||
parent_id: Option<impl Into<String>>,
|
|
||||||
) -> crate::Result<Principal> {
|
) -> crate::Result<Principal> {
|
||||||
/*let mut request = self.build();
|
let mut request = self.build();
|
||||||
let id = request
|
let id = request
|
||||||
.set_mailbox()
|
.set_principal()
|
||||||
.create()
|
.create()
|
||||||
.name(name)
|
.name(name)
|
||||||
.role(role)
|
.secret(secret)
|
||||||
.parent_id(parent_id)
|
.email(email)
|
||||||
|
.ptype(Type::Individual)
|
||||||
.create_id()
|
.create_id()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
request
|
request
|
||||||
.send_single::<MailboxSetResponse>()
|
.send_single::<PrincipalSetResponse>()
|
||||||
.await?
|
.await?
|
||||||
.created(&id)*/
|
.created(&id)
|
||||||
todo!()
|
}
|
||||||
|
|
||||||
|
pub async fn domain_create(&mut self, name: impl Into<String>) -> crate::Result<Principal> {
|
||||||
|
let mut request = self.build();
|
||||||
|
let id = request
|
||||||
|
.set_principal()
|
||||||
|
.create()
|
||||||
|
.name(name)
|
||||||
|
.ptype(Type::Domain)
|
||||||
|
.create_id()
|
||||||
|
.unwrap();
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.created(&id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn list_create(
|
||||||
|
&mut self,
|
||||||
|
email: impl Into<String>,
|
||||||
|
name: impl Into<String>,
|
||||||
|
members: impl IntoIterator<Item = impl Into<String>>,
|
||||||
|
) -> crate::Result<Principal> {
|
||||||
|
let mut request = self.build();
|
||||||
|
let id = request
|
||||||
|
.set_principal()
|
||||||
|
.create()
|
||||||
|
.name(name)
|
||||||
|
.email(email)
|
||||||
|
.ptype(Type::List)
|
||||||
|
.members(members.into())
|
||||||
|
.create_id()
|
||||||
|
.unwrap();
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.created(&id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn group_create(
|
||||||
|
&mut self,
|
||||||
|
email: impl Into<String>,
|
||||||
|
name: impl Into<String>,
|
||||||
|
members: impl IntoIterator<Item = impl Into<String>>,
|
||||||
|
) -> crate::Result<Principal> {
|
||||||
|
let mut request = self.build();
|
||||||
|
let id = request
|
||||||
|
.set_principal()
|
||||||
|
.create()
|
||||||
|
.name(name)
|
||||||
|
.email(email)
|
||||||
|
.ptype(Type::Group)
|
||||||
|
.members(members.into())
|
||||||
|
.create_id()
|
||||||
|
.unwrap();
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.created(&id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_set_name(
|
||||||
|
&mut self,
|
||||||
|
id: &str,
|
||||||
|
name: impl Into<String>,
|
||||||
|
) -> crate::Result<Option<Principal>> {
|
||||||
|
let mut request = self.build();
|
||||||
|
request.set_principal().update(id).name(name);
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.updated(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_set_secret(
|
||||||
|
&mut self,
|
||||||
|
id: &str,
|
||||||
|
secret: impl Into<String>,
|
||||||
|
) -> crate::Result<Option<Principal>> {
|
||||||
|
let mut request = self.build();
|
||||||
|
request.set_principal().update(id).secret(secret);
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.updated(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_set_email(
|
||||||
|
&mut self,
|
||||||
|
id: &str,
|
||||||
|
email: impl Into<String>,
|
||||||
|
) -> crate::Result<Option<Principal>> {
|
||||||
|
let mut request = self.build();
|
||||||
|
request.set_principal().update(id).email(email);
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.updated(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_set_timezone(
|
||||||
|
&mut self,
|
||||||
|
id: &str,
|
||||||
|
timezone: Option<impl Into<String>>,
|
||||||
|
) -> crate::Result<Option<Principal>> {
|
||||||
|
let mut request = self.build();
|
||||||
|
request.set_principal().update(id).timezone(timezone);
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.updated(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_set_members(
|
||||||
|
&mut self,
|
||||||
|
id: &str,
|
||||||
|
members: Option<impl IntoIterator<Item = impl Into<String>>>,
|
||||||
|
) -> crate::Result<Option<Principal>> {
|
||||||
|
let mut request = self.build();
|
||||||
|
request.set_principal().update(id).members(members);
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.updated(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_set_aliases(
|
||||||
|
&mut self,
|
||||||
|
id: &str,
|
||||||
|
aliases: Option<impl IntoIterator<Item = impl Into<String>>>,
|
||||||
|
) -> crate::Result<Option<Principal>> {
|
||||||
|
let mut request = self.build();
|
||||||
|
request.set_principal().update(id).aliases(aliases);
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.updated(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_set_capabilities(
|
||||||
|
&mut self,
|
||||||
|
id: &str,
|
||||||
|
capabilities: Option<impl IntoIterator<Item = impl Into<String>>>,
|
||||||
|
) -> crate::Result<Option<Principal>> {
|
||||||
|
let mut request = self.build();
|
||||||
|
request
|
||||||
|
.set_principal()
|
||||||
|
.update(id)
|
||||||
|
.capabilities(capabilities);
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.updated(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_destroy(&mut self, id: &str) -> crate::Result<()> {
|
||||||
|
let mut request = self.build();
|
||||||
|
request.set_principal().destroy([id]).arguments();
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalSetResponse>()
|
||||||
|
.await?
|
||||||
|
.destroyed(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_get(
|
||||||
|
&mut self,
|
||||||
|
id: &str,
|
||||||
|
properties: Option<Vec<Property>>,
|
||||||
|
) -> crate::Result<Option<Principal>> {
|
||||||
|
let mut request = self.build();
|
||||||
|
let get_request = request.get_principal().ids([id]);
|
||||||
|
if let Some(properties) = properties {
|
||||||
|
get_request.properties(properties.into_iter());
|
||||||
|
}
|
||||||
|
request
|
||||||
|
.send_single::<PrincipalGetResponse>()
|
||||||
|
.await
|
||||||
|
.map(|mut r| r.unwrap_list().pop())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_query(
|
||||||
|
&mut self,
|
||||||
|
filter: Option<impl Into<Filter<super::query::Filter>>>,
|
||||||
|
sort: Option<impl IntoIterator<Item = Comparator<super::query::Comparator>>>,
|
||||||
|
) -> crate::Result<QueryResponse> {
|
||||||
|
let mut request = self.build();
|
||||||
|
let query_request = request.query_principal();
|
||||||
|
if let Some(filter) = filter {
|
||||||
|
query_request.filter(filter);
|
||||||
|
}
|
||||||
|
if let Some(sort) = sort {
|
||||||
|
query_request.sort(sort.into_iter());
|
||||||
|
}
|
||||||
|
request.send_single::<QueryResponse>().await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn principal_changes(
|
||||||
|
&mut self,
|
||||||
|
since_state: impl Into<String>,
|
||||||
|
max_changes: usize,
|
||||||
|
) -> crate::Result<ChangesResponse<Principal<Get>>> {
|
||||||
|
let mut request = self.build();
|
||||||
|
request
|
||||||
|
.changes_principal(since_state)
|
||||||
|
.max_changes(max_changes);
|
||||||
|
request.send_single().await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ use crate::{core::set::SetObject, Get, Set};
|
||||||
use super::{Principal, Type, ACL, DKIM};
|
use super::{Principal, Type, ACL, DKIM};
|
||||||
|
|
||||||
impl Principal<Set> {
|
impl Principal<Set> {
|
||||||
pub fn name(&mut self, name: Option<impl Into<String>>) -> &mut Self {
|
pub fn name(&mut self, name: impl Into<String>) -> &mut Self {
|
||||||
self.name = name.map(|s| s.into());
|
self.name = name.into().into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,13 +15,13 @@ impl Principal<Set> {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn email(&mut self, email: Option<impl Into<String>>) -> &mut Self {
|
pub fn email(&mut self, email: impl Into<String>) -> &mut Self {
|
||||||
self.email = email.map(|s| s.into());
|
self.email = email.into().into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn secret(&mut self, secret: Option<impl Into<String>>) -> &mut Self {
|
pub fn secret(&mut self, secret: impl Into<String>) -> &mut Self {
|
||||||
self.secret = secret.map(|s| s.into());
|
self.secret = secret.into().into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue