Import upstream v0.16.22, stripped
Upstream commit: 474dd0229cb20cf513036619781ed97bd8073c3f Enterprise-only files removed or emptied: 63 Enterprise-only snippets removed: 117 in 50 files Dangling module declarations removed: 5 Cargo edits turning enterprise off: 14 Verification: clean Enterprise feature gates left for rebuilt features: 19 in 18 files Produced by tools/fork/strip.py. The full report is in docs/fork/strip-reports/ on main.
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020 Stalwart Labs LLC <[email protected]>
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
|
||||
*/
|
||||
|
||||
use super::propfind::PrincipalPropFind;
|
||||
use common::{Server, auth::AccessToken};
|
||||
use dav_proto::schema::{
|
||||
property::{DavProperty, WebDavProperty},
|
||||
request::{PrincipalPropertySearch, PropFind},
|
||||
response::MultiStatus,
|
||||
};
|
||||
use http_proto::HttpResponse;
|
||||
use hyper::StatusCode;
|
||||
use registry::schema::prelude::{ObjectType, Property};
|
||||
use store::{registry::RegistryQuery, roaring::RoaringBitmap};
|
||||
use trc::AddContext;
|
||||
use types::collection::Collection;
|
||||
|
||||
pub(crate) trait PrincipalPropSearch: Sync + Send {
|
||||
fn handle_principal_property_search(
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
request: PrincipalPropertySearch,
|
||||
) -> impl Future<Output = crate::Result<HttpResponse>> + Send;
|
||||
}
|
||||
|
||||
impl PrincipalPropSearch for Server {
|
||||
async fn handle_principal_property_search(
|
||||
&self,
|
||||
access_token: &AccessToken,
|
||||
mut request: PrincipalPropertySearch,
|
||||
) -> crate::Result<HttpResponse> {
|
||||
let mut search_for = None;
|
||||
|
||||
for prop_search in request.property_search {
|
||||
if matches!(
|
||||
prop_search.property,
|
||||
DavProperty::WebDav(WebDavProperty::DisplayName)
|
||||
) && !prop_search.match_.is_empty()
|
||||
{
|
||||
search_for = Some(prop_search.match_);
|
||||
}
|
||||
}
|
||||
|
||||
let mut response = MultiStatus::new(Vec::with_capacity(16));
|
||||
if let Some(search_for) = search_for {
|
||||
let ids = self
|
||||
.registry()
|
||||
.query::<RoaringBitmap>(
|
||||
RegistryQuery::new(ObjectType::Account)
|
||||
.with_tenant(access_token.tenant_id())
|
||||
.text(Property::Text, search_for),
|
||||
)
|
||||
.await
|
||||
.caused_by(trc::location!())?;
|
||||
|
||||
if !ids.is_empty() {
|
||||
if request.properties.is_empty() {
|
||||
request
|
||||
.properties
|
||||
.push(DavProperty::WebDav(WebDavProperty::DisplayName));
|
||||
}
|
||||
let request = PropFind::Prop(request.properties);
|
||||
self.prepare_principal_propfind_response(
|
||||
access_token,
|
||||
Collection::Principal,
|
||||
ids.into_iter(),
|
||||
&request,
|
||||
&mut response,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(HttpResponse::new(StatusCode::MULTI_STATUS).with_xml_body(response.to_string()))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user