Update all modules to use registry - part 3
This commit is contained in:
@@ -369,10 +369,9 @@ impl RequestHandler for Server {
|
||||
|
||||
self.sieve_script_query(req).await?.into()
|
||||
}
|
||||
QueryRequestMethod::Principal(req) => self
|
||||
.principal_query(req, access_token, session)
|
||||
.await?
|
||||
.into(),
|
||||
QueryRequestMethod::Principal(req) => {
|
||||
self.principal_query(req, access_token).await?.into()
|
||||
}
|
||||
QueryRequestMethod::Quota(mut req) => {
|
||||
set_account_id_if_missing(&mut req.account_id, access_token);
|
||||
access_token.assert_is_member(req.account_id)?;
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use super::{UploadResponse, download::BlobDownload};
|
||||
use common::{Server, auth::AccessToken};
|
||||
use jmap_proto::{
|
||||
|
||||
@@ -6,13 +6,18 @@
|
||||
|
||||
use crate::api::query::QueryResponseBuilder;
|
||||
use common::{Server, auth::AccessToken};
|
||||
use http_proto::HttpSessionData;
|
||||
use jmap_proto::{
|
||||
method::query::{Filter, QueryRequest, QueryResponse},
|
||||
object::principal::{Principal, PrincipalFilter, PrincipalType},
|
||||
types::state::State,
|
||||
};
|
||||
use registry::schema::prelude::{Object, Permission, Property};
|
||||
use registry::{
|
||||
schema::{
|
||||
enums::AccountType,
|
||||
prelude::{Object, Permission, Property},
|
||||
},
|
||||
types::EnumType,
|
||||
};
|
||||
use std::future::Future;
|
||||
use store::{
|
||||
registry::RegistryQuery,
|
||||
@@ -27,7 +32,6 @@ pub trait PrincipalQuery: Sync + Send {
|
||||
&self,
|
||||
request: QueryRequest<Principal>,
|
||||
access_token: &AccessToken,
|
||||
session: &HttpSessionData,
|
||||
) -> impl Future<Output = trc::Result<QueryResponse>> + Send;
|
||||
}
|
||||
|
||||
@@ -36,7 +40,6 @@ impl PrincipalQuery for Server {
|
||||
&self,
|
||||
mut request: QueryRequest<Principal>,
|
||||
access_token: &AccessToken,
|
||||
session: &HttpSessionData,
|
||||
) -> trc::Result<QueryResponse> {
|
||||
if !self.core.groupware.allow_directory_query
|
||||
&& !access_token.has_permission(Permission::IndividualList)
|
||||
@@ -58,74 +61,73 @@ impl PrincipalQuery for Server {
|
||||
let mut filters = Vec::with_capacity(request.filter.len());
|
||||
for cond in std::mem::take(&mut request.filter) {
|
||||
match cond {
|
||||
Filter::Property(cond) => {
|
||||
match cond {
|
||||
PrincipalFilter::Name(name) | PrincipalFilter::Email(name) => {
|
||||
if let Some(account_id) = self.account_id(&name).await? {
|
||||
filters.push(SearchFilter::is_in_set(
|
||||
RoaringBitmap::from_sorted_iter([account_id]).unwrap(),
|
||||
));
|
||||
}
|
||||
}
|
||||
PrincipalFilter::AccountIds(ids) => {
|
||||
Filter::Property(cond) => match cond {
|
||||
PrincipalFilter::Name(name) | PrincipalFilter::Email(name) => {
|
||||
if let Some(account_id) = self.account_id(&name).await? {
|
||||
filters.push(SearchFilter::is_in_set(
|
||||
ids.into_iter()
|
||||
.filter_map(|id| {
|
||||
let id = id.document_id();
|
||||
if principal_ids.contains(id) {
|
||||
Some(id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<RoaringBitmap>(),
|
||||
RoaringBitmap::from_sorted_iter([account_id]).unwrap(),
|
||||
));
|
||||
}
|
||||
PrincipalFilter::Text(text) => {
|
||||
filters.push(SearchFilter::is_in_set(
|
||||
self.registry()
|
||||
.query::<RoaringBitmap>(
|
||||
RegistryQuery::new(Object::Account)
|
||||
.equal_opt(
|
||||
Property::MemberTenantId,
|
||||
access_token.tenant_id(),
|
||||
)
|
||||
.text(text),
|
||||
)
|
||||
.await
|
||||
.caused_by(trc::location!())?,
|
||||
));
|
||||
}
|
||||
PrincipalFilter::Type(principal_type) => {
|
||||
let todo = "make sure this works";
|
||||
let typ = match principal_type {
|
||||
PrincipalType::Individual => Object::UserAccount,
|
||||
PrincipalType::Group => Object::GroupAccount,
|
||||
PrincipalType::Resource
|
||||
| PrincipalType::Location
|
||||
| PrincipalType::Other => {
|
||||
filters.push(SearchFilter::is_in_set(Default::default()));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
filters.push(SearchFilter::is_in_set(
|
||||
self.registry()
|
||||
.query::<RoaringBitmap>(RegistryQuery::new(typ).equal_opt(
|
||||
Property::MemberTenantId,
|
||||
access_token.tenant_id(),
|
||||
))
|
||||
.await
|
||||
.caused_by(trc::location!())?,
|
||||
));
|
||||
}
|
||||
other => {
|
||||
return Err(trc::JmapEvent::UnsupportedFilter
|
||||
.into_err()
|
||||
.details(other.to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
PrincipalFilter::AccountIds(ids) => {
|
||||
filters.push(SearchFilter::is_in_set(
|
||||
ids.into_iter()
|
||||
.filter_map(|id| {
|
||||
let id = id.document_id();
|
||||
if principal_ids.contains(id) {
|
||||
Some(id)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect::<RoaringBitmap>(),
|
||||
));
|
||||
}
|
||||
PrincipalFilter::Text(text) => {
|
||||
filters.push(SearchFilter::is_in_set(
|
||||
self.registry()
|
||||
.query::<RoaringBitmap>(
|
||||
RegistryQuery::new(Object::Account)
|
||||
.equal_opt(
|
||||
Property::MemberTenantId,
|
||||
access_token.tenant_id(),
|
||||
)
|
||||
.text(text),
|
||||
)
|
||||
.await
|
||||
.caused_by(trc::location!())?,
|
||||
));
|
||||
}
|
||||
PrincipalFilter::Type(principal_type) => {
|
||||
let typ = match principal_type {
|
||||
PrincipalType::Individual => AccountType::User,
|
||||
PrincipalType::Group => AccountType::Group,
|
||||
_ => {
|
||||
filters.push(SearchFilter::is_in_set(Default::default()));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
filters.push(SearchFilter::is_in_set(
|
||||
self.registry()
|
||||
.query::<RoaringBitmap>(
|
||||
RegistryQuery::new(Object::Account)
|
||||
.equal(Property::Type, typ.to_id())
|
||||
.equal_opt(
|
||||
Property::MemberTenantId,
|
||||
access_token.tenant_id(),
|
||||
),
|
||||
)
|
||||
.await
|
||||
.caused_by(trc::location!())?,
|
||||
));
|
||||
}
|
||||
other => {
|
||||
return Err(trc::JmapEvent::UnsupportedFilter
|
||||
.into_err()
|
||||
.details(other.to_string()));
|
||||
}
|
||||
},
|
||||
Filter::And => {
|
||||
filters.push(SearchFilter::And);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user