From 23ef84d5e56f406b921065a9e8a0a2a288de9502 Mon Sep 17 00:00:00 2001 From: Stefan Melmuk Date: Sat, 21 Dec 2024 23:37:43 +0100 Subject: [PATCH] add to_json_details_for_group --- src/api/core/organizations.rs | 30 ++---------------------------- src/db/models/group.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 38206745..974335a2 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -366,9 +366,7 @@ async fn get_org_collections_details( CollectionGroup::find_by_collection(&col.uuid, &mut conn) .await .iter() - .map(|collection_group| { - GroupSelection::to_collection_group_details_read_only(collection_group).to_json() - }) + .map(|collection_group| collection_group.to_json_details_for_group()) .collect() } else { Vec::with_capacity(0) @@ -650,9 +648,7 @@ async fn get_org_collection_detail( CollectionGroup::find_by_collection(&collection.uuid, &mut conn) .await .iter() - .map(|collection_group| { - GroupSelection::to_collection_group_details_read_only(collection_group).to_json() - }) + .map(|collection_group| collection_group.to_json_details_for_group()) .collect() } else { // The Bitwarden clients seem to call this API regardless of whether groups are enabled, @@ -2377,28 +2373,6 @@ impl GroupRequest { } } -#[derive(Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -struct GroupSelection { - id: GroupId, - read_only: bool, - hide_passwords: bool, -} - -impl GroupSelection { - pub fn to_collection_group_details_read_only(collection_group: &CollectionGroup) -> Self { - Self { - id: collection_group.groups_uuid.clone(), - read_only: collection_group.read_only, - hide_passwords: collection_group.hide_passwords, - } - } - - pub fn to_json(&self) -> Value { - json!(self) - } -} - #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct CollectionSelection { diff --git a/src/db/models/group.rs b/src/db/models/group.rs index 1ed23f04..60a2dce7 100644 --- a/src/db/models/group.rs +++ b/src/db/models/group.rs @@ -127,6 +127,15 @@ impl CollectionGroup { hide_passwords, } } + + pub fn to_json_details_for_group(&self) -> Value { + json!({ + "id": self.groups_uuid, + "readOnly": self.read_only, + "hidePasswords": self.hide_passwords, + "manage": false + }) + } } impl GroupUser {