use proxmox::api::schema::{Schema, StringSchema};
use proxmox::tools::fs::open_file_locked;
-use crate::api2::types::*;
+use pbs_api_types::{
+ PASSWORD_FORMAT, PROXMOX_CONFIG_DIGEST_SCHEMA, SINGLE_LINE_COMMENT_SCHEMA, Authid,
+ Tokenname, UserWithTokens, Userid,
+};
+
use crate::config::user;
use crate::config::token_shadow;
use crate::config::acl::{PRIV_SYS_AUDIT, PRIV_PERMISSIONS_MODIFY};
.max_length(64)
.schema();
-#[api(
- properties: {
- userid: {
- type: Userid,
- },
- comment: {
- optional: true,
- schema: SINGLE_LINE_COMMENT_SCHEMA,
- },
- enable: {
- optional: true,
- schema: user::ENABLE_USER_SCHEMA,
- },
- expire: {
- optional: true,
- schema: user::EXPIRE_USER_SCHEMA,
- },
- firstname: {
- optional: true,
- schema: user::FIRST_NAME_SCHEMA,
- },
- lastname: {
- schema: user::LAST_NAME_SCHEMA,
- optional: true,
- },
- email: {
- schema: user::EMAIL_SCHEMA,
- optional: true,
- },
- tokens: {
- type: Array,
- optional: true,
- description: "List of user's API tokens.",
- items: {
- type: user::ApiToken
- },
- },
- }
-)]
-#[derive(Serialize,Deserialize)]
-/// User properties with added list of ApiTokens
-pub struct UserWithTokens {
- pub userid: Userid,
- #[serde(skip_serializing_if="Option::is_none")]
- pub comment: Option<String>,
- #[serde(skip_serializing_if="Option::is_none")]
- pub enable: Option<bool>,
- #[serde(skip_serializing_if="Option::is_none")]
- pub expire: Option<i64>,
- #[serde(skip_serializing_if="Option::is_none")]
- pub firstname: Option<String>,
- #[serde(skip_serializing_if="Option::is_none")]
- pub lastname: Option<String>,
- #[serde(skip_serializing_if="Option::is_none")]
- pub email: Option<String>,
- #[serde(skip_serializing_if="Vec::is_empty", default)]
- pub tokens: Vec<user::ApiToken>,
-}
-
-impl UserWithTokens {
- fn new(user: user::User) -> Self {
- Self {
- userid: user.userid,
- comment: user.comment,
- enable: user.enable,
- expire: user.expire,
- firstname: user.firstname,
- lastname: user.lastname,
- email: user.email,
- tokens: Vec::new(),
- }
+fn new_user_with_tokens(user: user::User) -> UserWithTokens {
+ UserWithTokens {
+ userid: user.userid,
+ comment: user.comment,
+ enable: user.enable,
+ expire: user.expire,
+ firstname: user.firstname,
+ lastname: user.lastname,
+ email: user.email,
+ tokens: Vec::new(),
}
}
});
iter
.map(|user: user::User| {
- let mut user = UserWithTokens::new(user);
+ let mut user = new_user_with_tokens(user);
user.tokens = user_to_tokens.remove(&user.userid).unwrap_or_default();
user
})
.collect()
} else {
- iter.map(UserWithTokens::new)
+ iter.map(new_user_with_tokens)
.collect()
};