add to_json_details_for_user

pull/5320/head
Stefan Melmuk 1 week ago
parent 23ef84d5e5
commit 493d62188f
No known key found for this signature in database
GPG Key ID: 817020C608FE9C09

@ -358,7 +358,7 @@ async fn get_org_collections_details(
let users: Vec<Value> = 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/<org_id>/groups/<group_id>", data = "<data>")]
async fn post_group(
org_id: OrganizationId,

@ -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);

Loading…
Cancel
Save