api2/access/user: drop Option, treat empty Vec as None

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2020-10-29 15:17:53 +01:00
parent 221177ba41
commit ea1853a17b
1 changed files with 5 additions and 5 deletions

View File

@ -75,8 +75,8 @@ pub struct UserWithTokens {
pub lastname: Option<String>, pub lastname: Option<String>,
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Option::is_none")]
pub email: Option<String>, pub email: Option<String>,
#[serde(skip_serializing_if="Option::is_none")] #[serde(skip_serializing_if="Vec::is_empty")]
pub tokens: Option<Vec<user::ApiToken>>, pub tokens: Vec<user::ApiToken>,
} }
impl UserWithTokens { impl UserWithTokens {
@ -89,7 +89,7 @@ impl UserWithTokens {
firstname: user.firstname, firstname: user.firstname,
lastname: user.lastname, lastname: user.lastname,
email: user.email, email: user.email,
tokens: None, tokens: Vec::new(),
} }
} }
} }
@ -145,7 +145,7 @@ pub fn list_users(
let iter = list.into_iter().filter(filter_by_privs); let iter = list.into_iter().filter(filter_by_privs);
let list = if include_tokens { let list = if include_tokens {
let tokens:Vec<user::ApiToken> = config.convert_to_typed_array("token")?; let tokens: Vec<user::ApiToken> = config.convert_to_typed_array("token")?;
let mut user_to_tokens = tokens let mut user_to_tokens = tokens
.into_iter() .into_iter()
.fold( .fold(
@ -162,7 +162,7 @@ pub fn list_users(
iter iter
.map(|user: user::User| { .map(|user: user::User| {
let mut user = UserWithTokens::new(user); let mut user = UserWithTokens::new(user);
user.tokens = user_to_tokens.remove(&user.userid); user.tokens = user_to_tokens.remove(&user.userid).unwrap_or_default();
user user
}) })
.collect() .collect()