Browse Source

converted to HashMap

pull/2667/head
MFijak 3 years ago
committed by Maximilian Fijak
parent
commit
72de021319
  1. 17
      src/api/core/ciphers.rs
  2. 12
      src/db/models/cipher.rs

17
src/api/core/ciphers.rs

@ -1497,8 +1497,8 @@ pub struct CipherSyncData {
pub cipher_collections: HashMap<String, Vec<String>>,
pub user_organizations: HashMap<String, UserOrganization>,
pub user_collections: HashMap<String, CollectionUser>,
pub user_collections_groups: Vec<CollectionGroup>,
pub user_groups: Vec<Group>,
pub user_collections_groups: HashMap<String, CollectionGroup>,
pub user_groups: HashMap<String, Group>,
}
pub enum CipherSyncType {
@ -1554,8 +1554,17 @@ impl CipherSyncData {
.collect()
.await;
let user_collections_groups = CollectionGroup::find_by_user(user_uuid, conn).await;
let user_groups = Group::find_by_user(user_uuid, conn).await;
// Generate a HashMap with the collections_uuid as key and the CollectionGroup record
let user_collections_groups = stream::iter(CollectionGroup::find_by_user(user_uuid, conn).await)
.map(|collection_group| (collection_group.collections_uuid.clone(), collection_group))
.collect()
.await;
// Generate a HashMap with the group.uuid as key and the Group record
let user_groups = stream::iter(Group::find_by_user(user_uuid, conn).await)
.map(|group| (group.uuid.clone(), group))
.collect()
.await;
Self {
cipher_attachments,

12
src/db/models/cipher.rs

@ -364,7 +364,9 @@ impl Cipher {
conn: &DbConn,
) -> bool {
match cipher_sync_data {
Some(cipher_sync_data) => cipher_sync_data.user_groups.iter().any(|group| group.access_all),
Some(cipher_sync_data) => {
cipher_sync_data.user_groups.iter().any(|hash_map_entry| hash_map_entry.1.access_all)
}
None => Group::is_in_full_access_group(user_uuid, conn).await,
}
}
@ -400,12 +402,8 @@ impl Cipher {
}
//Group permissions
if let Some(gc) = cipher_sync_data
.user_collections_groups
.iter()
.find(|collection_group| collection_group.collections_uuid == collection.clone())
{
rows.push((gc.read_only, gc.hide_passwords));
if let Some(cg) = cipher_sync_data.user_collections_groups.get(collection) {
rows.push((cg.read_only, cg.hide_passwords));
}
}
}

Loading…
Cancel
Save