Skip to content

Commit

Permalink
refactor the code to make it easier to review
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan0xC committed Jan 5, 2024
1 parent f19459b commit ee8a264
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/api/core/organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,6 @@ async fn get_org_collections_details(org_id: &str, headers: ManagerHeadersLoose,
let has_full_access_to_org = user_org.access_all || has_full_access_via_group;

for col in Collection::find_by_organization(org_id, &mut conn).await {
// get the group details for the given collection
let groups: Vec<Value> = if CONFIG.org_groups_enabled() {
CollectionGroup::find_by_collection(&col.uuid, &mut conn)
.await
.iter()
.map(|collection_group| {
SelectionReadOnly::to_collection_group_details_read_only(collection_group).to_json()
})
.collect()
} else {
// The Bitwarden clients seem to call this API regardless of whether groups are enabled,
// so just act as if there are no groups.
Vec::with_capacity(0)
};

// assigned indicates whether the current user has access to the given collection
let mut assigned = has_full_access_to_org;

Expand All @@ -366,6 +351,19 @@ async fn get_org_collections_details(org_id: &str, headers: ManagerHeadersLoose,
assigned = GroupUser::has_access_to_collection_by_member(&col.uuid, &user_org.uuid, &mut conn).await;
}

// get the group details for the given collection
let groups: Vec<Value> = if CONFIG.org_groups_enabled() {
CollectionGroup::find_by_collection(&col.uuid, &mut conn)
.await
.iter()
.map(|collection_group| {
SelectionReadOnly::to_collection_group_details_read_only(collection_group).to_json()
})
.collect()
} else {
Vec::with_capacity(0)
};

let mut json_object = col.to_json();
json_object["Assigned"] = json!(assigned);
json_object["Users"] = json!(users);
Expand Down

0 comments on commit ee8a264

Please sign in to comment.