Browse Source

Let direct collection assignments override groups on import

pull/7964/head
tom27052006 2 days ago
parent
commit
9354c42e15
  1. 2
      src/api/core/organizations.rs
  2. 20
      src/db/models/collection.rs

2
src/api/core/organizations.rs

@ -2005,7 +2005,7 @@ async fn validate_org_import_collections(
&& !membership.has_type(MembershipType::Manager) && !membership.has_type(MembershipType::Manager)
{ {
Some( Some(
Collection::find_manageable_by_any_assignment(org_id, &membership.user_uuid, conn) Collection::find_explicitly_manageable_by_user(org_id, &membership.user_uuid, conn)
.await .await
.into_iter() .into_iter()
.collect::<HashSet<_>>(), .collect::<HashSet<_>>(),

20
src/db/models/collection.rs

@ -663,25 +663,6 @@ impl Collection {
org_uuid: &OrganizationId, org_uuid: &OrganizationId,
user_uuid: &UserId, user_uuid: &UserId,
conn: &DbConn, conn: &DbConn,
) -> Vec<CollectionId> {
Self::find_manageable_by_option(org_uuid, user_uuid, false, conn).await
}
/// [`Collection::find_explicitly_manageable_by_user`], but like Bitwarden the manage option of any assignment
/// counts: a direct assignment without it doesn't hide the one of a group.
pub async fn find_manageable_by_any_assignment(
org_uuid: &OrganizationId,
user_uuid: &UserId,
conn: &DbConn,
) -> Vec<CollectionId> {
Self::find_manageable_by_option(org_uuid, user_uuid, true, conn).await
}
async fn find_manageable_by_option(
org_uuid: &OrganizationId,
user_uuid: &UserId,
any_assignment: bool,
conn: &DbConn,
) -> Vec<CollectionId> { ) -> Vec<CollectionId> {
let org_uuid = org_uuid.to_string(); let org_uuid = org_uuid.to_string();
let user_uuid = user_uuid.to_string(); let user_uuid = user_uuid.to_string();
@ -710,7 +691,6 @@ impl Collection {
users_collections::manage.eq(true).or(users_collections::user_uuid users_collections::manage.eq(true).or(users_collections::user_uuid
.is_null() .is_null()
.or(users_organizations::atype.eq(MembershipType::Manager as i32)) .or(users_organizations::atype.eq(MembershipType::Manager as i32))
.or::<_, diesel::sql_types::Bool>(any_assignment)
.and(collections_groups::manage.eq(true)) .and(collections_groups::manage.eq(true))
.and::<_, diesel::sql_types::Bool>(groups_enabled)), .and::<_, diesel::sql_types::Bool>(groups_enabled)),
) )

Loading…
Cancel
Save