WebDAV ACL tests

This commit is contained in:
mdecimus
2025-05-04 12:19:36 +02:00
parent a8d295223b
commit cb03036998
14 changed files with 889 additions and 410 deletions

View File

@@ -434,6 +434,19 @@ impl AccessToken {
.chain(self.access_to.iter().map(|(id, _)| *id))
}
pub fn all_ids_by_collection(&self, collection: Collection) -> impl Iterator<Item = u32> {
[self.primary_id]
.into_iter()
.chain(self.member_of.iter().copied())
.chain(self.access_to.iter().filter_map(move |(id, cols)| {
if cols.contains(collection) {
Some(*id)
} else {
None
}
}))
}
pub fn is_member(&self, account_id: u32) -> bool {
self.primary_id == account_id
|| self.member_of.contains(&account_id)

View File

@@ -14,8 +14,7 @@ pub struct GroupwareConfig {
pub live_property_size: usize,
pub max_lock_timeout: u64,
pub max_locks_per_user: usize,
pub max_changes: usize,
pub max_match_results: usize,
pub max_results: usize,
// Calendar settings
pub max_ical_size: usize,
@@ -51,10 +50,7 @@ impl GroupwareConfig {
max_locks_per_user: config
.property("dav.limits.max-locks-per-user")
.unwrap_or(10),
max_changes: config.property("dav.limits.max-changes").unwrap_or(1000),
max_match_results: config
.property("dav.limits.max-match-results")
.unwrap_or(1000),
max_results: config.property("dav.limits.max-results").unwrap_or(2000),
max_vcard_size: config
.property("dav.limits.size.vcard")
.unwrap_or(512 * 1024),

View File

@@ -16,7 +16,7 @@ use jmap_proto::{
types::{
acl::Acl,
property::Property,
value::{AclGrant, MaybePatchValue, Value},
value::{AclGrant, ArchivedAclGrant, MaybePatchValue, Value},
},
};
use utils::map::bitmap::Bitmap;
@@ -164,6 +164,49 @@ impl Server {
self.increment_token_revision(changed_principals).await;
}
pub async fn refresh_archived_acls(
&self,
acl_changes: &[AclGrant],
acl_current: &[ArchivedAclGrant],
) {
let mut changed_principals = ChangedPrincipals::new();
for current_item in acl_current.iter() {
let mut invalidate = true;
for change_item in acl_changes {
if change_item.account_id == current_item.account_id {
invalidate = change_item.grants != current_item.grants;
break;
}
}
if invalidate {
changed_principals.add_change(
current_item.account_id.to_native(),
Type::Individual,
PrincipalField::EnabledPermissions,
);
}
}
for change_item in acl_changes {
let mut invalidate = true;
for current_item in acl_current.iter() {
if change_item.account_id == current_item.account_id {
invalidate = change_item.grants != current_item.grants;
break;
}
}
if invalidate {
changed_principals.add_change(
change_item.account_id,
Type::Individual,
PrincipalField::EnabledPermissions,
);
}
}
self.increment_token_revision(changed_principals).await;
}
pub async fn map_acl_set(&self, acl_set: Vec<Value>) -> Result<Vec<AclGrant>, SetError> {
let mut acls = Vec::with_capacity(acl_set.len() / 2);
for item in acl_set.chunks_exact(2) {

View File

@@ -28,9 +28,7 @@ impl Server {
.chain(access_token.member_of.clone().iter())
{
for acl_item in self
.core
.storage
.data
.store()
.acl_query(AclQuery::SharedWith {
grant_account_id,
to_account_id,
@@ -92,4 +90,24 @@ impl Server {
}
Ok(false)
}
pub async fn document_acl(
&self,
grant_account_id: u32,
to_account_id: u32,
to_collection: impl Into<u8>,
to_document_id: u32,
) -> trc::Result<Bitmap<Acl>> {
self.core
.storage
.data
.get_value::<u64>(ValueKey {
account_id: to_account_id,
collection: to_collection.into(),
document_id: to_document_id,
class: ValueClass::Acl(grant_account_id),
})
.await
.map(|v| v.map(Bitmap::<Acl>::from).unwrap_or_default())
}
}