From 827bf4c7f8b0f9eb6e69a558f6b908da053e8160 Mon Sep 17 00:00:00 2001 From: MFijak Date: Tue, 2 Aug 2022 10:56:41 +0200 Subject: [PATCH] fix for group collections --- src/db/models/collection.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/db/models/collection.rs b/src/db/models/collection.rs index 0d6d507a..d60e41ba 100644 --- a/src/db/models/collection.rs +++ b/src/db/models/collection.rs @@ -171,22 +171,33 @@ impl Collection { users_organizations::user_uuid.eq(user_uuid) ) )) - .left_join(collection_groups::table.on( - collections::uuid.eq(collection_groups::collections_uuid) - )) .left_join(groups_users::table.on( - groups_users::groups_uuid.eq(collection_groups::groups_uuid) + groups_users::users_organizations_uuid.eq(users_organizations::uuid) + )) + .left_join(groups::table.on( + groups::uuid.eq(groups_users::groups_uuid) + )) + .left_join(collection_groups::table.on( + collection_groups::groups_uuid.eq(groups_users::groups_uuid).and( + collection_groups::collections_uuid.eq(collections::uuid) + ) )) .filter( users_organizations::status.eq(UserOrgStatus::Confirmed as i32) ) - .filter( - users_collections::user_uuid.eq(user_uuid).or( // Directly accessed collection + .filter( + users_collections::user_uuid.eq(user_uuid).or( // Directly accessed collection users_organizations::access_all.eq(true) // access_all in Organization - ).or( - groups_users::users_organizations_uuid.eq(users_organizations::uuid) // access via groups - ) - ).select(collections::all_columns) + ).or( + groups::access_all.eq(true) // access_all in groups + ).or( // access via groups + groups_users::users_organizations_uuid.eq(users_organizations::uuid).and( + collection_groups::collections_uuid.is_not_null() + ) + ) + ) + .select(collections::all_columns) + .distinct() .load::(conn).expect("Error loading collections").from_db() }} }