Browse Source

Update src/api/core/ciphers.rs

Co-authored-by: Mathijs van Veluw <black.dex@gmail.com>
pull/6017/head
Richy 2 weeks ago
parent
commit
0789a7567c
  1. 32
      src/api/core/ciphers.rs

32
src/api/core/ciphers.rs

@ -1924,24 +1924,20 @@ impl CipherSyncData {
// Generate a HashMap with the collections_uuid as key and the CollectionGroup record // Generate a HashMap with the collections_uuid as key and the CollectionGroup record
let user_collections_groups: HashMap<CollectionId, CollectionGroup> = if CONFIG.org_groups_enabled() { let user_collections_groups: HashMap<CollectionId, CollectionGroup> = if CONFIG.org_groups_enabled() {
let all_user_collection_groups = CollectionGroup::find_by_user(user_id, conn).await; CollectionGroup::find_by_user(user_id, conn)
let mut combined_permissions: HashMap<CollectionId, CollectionGroup> = HashMap::new(); .await
.into_iter()
for cg in all_user_collection_groups { .fold(HashMap::new(), |mut combined_permissions, cg| {
match combined_permissions.get_mut(&cg.collections_uuid) { combined_permissions.entry(cg.collections_uuid.clone())
Some(existing) => { .and_modify(|existing| {
// Combine permissions by taking the most permissive settings // Combine permissions: take the most permissive settings.
existing.read_only = existing.read_only && cg.read_only; // false if ANY group allows write existing.read_only &= cg.read_only; // false if ANY group allows write
existing.hide_passwords = existing.hide_passwords && cg.hide_passwords; // false if ANY group allows password view existing.hide_passwords &= cg.hide_passwords; // false if ANY group allows password view
existing.manage = existing.manage || cg.manage; // true if ANY group allows manage existing.manage |= cg.manage; // true if ANY group allows manage
} })
None => { .or_insert(cg);
// First group for this collection combined_permissions
combined_permissions.insert(cg.collections_uuid.clone(), cg); })
}
}
}
combined_permissions
} else { } else {
HashMap::new() HashMap::new()
}; };

Loading…
Cancel
Save