Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-26 05:50:29 +01:00
Deserialize "null" to empty Vec for Collections
Dieser Commit ist enthalten in:
Ursprung
eb5641b863
Commit
00b882935f
1 geänderte Dateien mit 12 neuen und 1 gelöschten Zeilen
|
@ -8,6 +8,8 @@ use db::models::*;
|
||||||
use api::{PasswordData, JsonResult, EmptyResult, NumberOrString, JsonUpcase};
|
use api::{PasswordData, JsonResult, EmptyResult, NumberOrString, JsonUpcase};
|
||||||
use auth::{Headers, AdminHeaders, OwnerHeaders};
|
use auth::{Headers, AdminHeaders, OwnerHeaders};
|
||||||
|
|
||||||
|
use serde::{Deserialize, Deserializer};
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
|
@ -327,6 +329,14 @@ fn get_org_users(org_id: String, headers: AdminHeaders, conn: DbConn) -> JsonRes
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn deserialize_collections<'de, D>(deserializer: D) -> Result<Vec<CollectionData>, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
// Deserialize null to empty Vec
|
||||||
|
Deserialize::deserialize(deserializer).or(Ok(vec![]))
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
struct CollectionData {
|
struct CollectionData {
|
||||||
|
@ -339,6 +349,7 @@ struct CollectionData {
|
||||||
struct InviteData {
|
struct InviteData {
|
||||||
Emails: Vec<String>,
|
Emails: Vec<String>,
|
||||||
Type: NumberOrString,
|
Type: NumberOrString,
|
||||||
|
#[serde(deserialize_with = "deserialize_collections")]
|
||||||
Collections: Vec<CollectionData>,
|
Collections: Vec<CollectionData>,
|
||||||
AccessAll: Option<bool>,
|
AccessAll: Option<bool>,
|
||||||
}
|
}
|
||||||
|
@ -443,11 +454,11 @@ fn get_user(org_id: String, user_id: String, _headers: AdminHeaders, conn: DbCon
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
struct EditUserData {
|
struct EditUserData {
|
||||||
Type: NumberOrString,
|
Type: NumberOrString,
|
||||||
|
#[serde(deserialize_with = "deserialize_collections")]
|
||||||
Collections: Vec<CollectionData>,
|
Collections: Vec<CollectionData>,
|
||||||
AccessAll: bool,
|
AccessAll: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[put("/organizations/<org_id>/users/<user_id>", data = "<data>", rank = 1)]
|
#[put("/organizations/<org_id>/users/<user_id>", data = "<data>", rank = 1)]
|
||||||
fn put_organization_user(org_id: String, user_id: String, data: JsonUpcase<EditUserData>, headers: AdminHeaders, conn: DbConn) -> EmptyResult {
|
fn put_organization_user(org_id: String, user_id: String, data: JsonUpcase<EditUserData>, headers: AdminHeaders, conn: DbConn) -> EmptyResult {
|
||||||
edit_user(org_id, user_id, data, headers, conn)
|
edit_user(org_id, user_id, data, headers, conn)
|
||||||
|
|
Laden …
In neuem Issue referenzieren