diff --git a/src/api/core/organizations.rs b/src/api/core/organizations.rs index 974335a2..455c2c72 100644 --- a/src/api/core/organizations.rs +++ b/src/api/core/organizations.rs @@ -358,7 +358,7 @@ async fn get_org_collections_details( let users: Vec = col_users .iter() .filter(|collection_user| collection_user.collection_uuid == col.uuid) - .map(|collection_user| UserSelection::to_collection_user_details_read_only(collection_user).to_json()) + .map(|collection_user| collection_user.to_json_details_for_user()) .collect(); // get the group details for the given collection @@ -660,9 +660,7 @@ async fn get_org_collection_detail( CollectionUser::find_by_collection_swap_user_uuid_with_member_uuid(&collection.uuid, &mut conn) .await .iter() - .map(|collection_user| { - UserSelection::to_collection_user_details_read_only(collection_user).to_json() - }) + .map(|collection_user| collection_user.to_json_details_for_user()) .collect(); let assigned = Collection::can_access_collection(&member, &collection.uuid, &mut conn).await; @@ -2387,28 +2385,6 @@ impl CollectionSelection { } } -#[derive(Deserialize, Serialize)] -#[serde(rename_all = "camelCase")] -struct UserSelection { - id: UserId, - read_only: bool, - hide_passwords: bool, -} - -impl UserSelection { - pub fn to_collection_user_details_read_only(collection_user: &CollectionUser) -> Self { - Self { - id: collection_user.user_uuid.clone(), - read_only: collection_user.read_only, - hide_passwords: collection_user.hide_passwords, - } - } - - pub fn to_json(&self) -> Value { - json!(self) - } -} - #[post("/organizations//groups/", data = "")] async fn post_group( org_id: OrganizationId, diff --git a/src/db/models/collection.rs b/src/db/models/collection.rs index 1b8c11bf..52d23fa6 100644 --- a/src/db/models/collection.rs +++ b/src/db/models/collection.rs @@ -779,6 +779,17 @@ impl CollectionCipher { } } +impl CollectionUser { + pub fn to_json_details_for_user(&self) -> Value { + json!({ + "id": self.user_uuid, + "readOnly": self.read_only, + "hidePasswords": self.hide_passwords, + "manage": false + }) + } +} + #[derive(DieselNewType, FromForm, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)] pub struct CollectionId(String);