Groupware caching improvements

This commit is contained in:
mdecimus
2025-05-08 17:30:57 +02:00
parent e69b5ec2b7
commit fe7d646966
54 changed files with 2138 additions and 1963 deletions

View File

@@ -4,6 +4,7 @@
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use crate::auth::AccessToken;
use jmap_proto::types::{
acl::Acl,
value::{AclGrant, ArchivedAclGrant},
@@ -11,10 +12,9 @@ use jmap_proto::types::{
use rkyv::vec::ArchivedVec;
use utils::map::bitmap::Bitmap;
use crate::auth::AccessToken;
pub mod acl;
pub mod document;
pub mod resources;
pub trait EffectiveAcl {
fn effective_acl(&self, access_token: &AccessToken) -> Bitmap<Acl>;

View File

@@ -0,0 +1,83 @@
/*
* SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd <hello@stalw.art>
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
use crate::{DavResources, auth::AccessToken};
use jmap_proto::types::acl::Acl;
use store::roaring::RoaringBitmap;
use utils::map::bitmap::Bitmap;
impl DavResources {
pub fn shared_containers(
&self,
access_token: &AccessToken,
check_acls: impl IntoIterator<Item = Acl>,
match_any: bool,
) -> RoaringBitmap {
let check_acls = Bitmap::<Acl>::from_iter(check_acls);
let mut document_ids = RoaringBitmap::new();
for resource in &self.resources {
if let Some(acls) = resource.acls() {
for acl in acls {
if access_token.is_member(acl.account_id) {
let mut grants = acl.grants;
grants.intersection(&check_acls);
if grants == check_acls || (match_any && !grants.is_empty()) {
document_ids.insert(resource.document_id);
}
}
}
}
}
document_ids
}
pub fn has_access_to_container(
&self,
access_token: &AccessToken,
document_id: u32,
check_acls: impl Into<Bitmap<Acl>>,
) -> bool {
let check_acls = check_acls.into();
for resource in &self.resources {
if resource.document_id == document_id {
if let Some(acls) = resource.acls() {
for acl in acls {
if access_token.is_member(acl.account_id) {
let mut grants = acl.grants;
grants.intersection(&check_acls);
return !grants.is_empty();
}
}
break;
}
}
}
false
}
pub fn container_acl(&self, access_token: &AccessToken, document_id: u32) -> Bitmap<Acl> {
let mut account_acls = Bitmap::<Acl>::new();
for resource in &self.resources {
if resource.document_id == document_id {
if let Some(acls) = resource.acls() {
for acl in acls {
if access_token.is_member(acl.account_id) {
account_acls.union(&acl.grants);
}
}
break;
}
}
}
account_acls
}
}