make user properties deletable
by using our usual pattern for the update call Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
e411924c7c
commit
c0026563b0
@ -268,6 +268,21 @@ pub fn read_user(userid: Userid, mut rpcenv: &mut dyn RpcEnvironment) -> Result<
|
|||||||
Ok(user)
|
Ok(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[api()]
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[serde(rename_all="kebab-case")]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
pub enum DeletableProperty {
|
||||||
|
/// Delete the comment property.
|
||||||
|
comment,
|
||||||
|
/// Delete the firstname property.
|
||||||
|
firstname,
|
||||||
|
/// Delete the lastname property.
|
||||||
|
lastname,
|
||||||
|
/// Delete the email property.
|
||||||
|
email,
|
||||||
|
}
|
||||||
|
|
||||||
#[api(
|
#[api(
|
||||||
protected: true,
|
protected: true,
|
||||||
input: {
|
input: {
|
||||||
@ -303,6 +318,14 @@ pub fn read_user(userid: Userid, mut rpcenv: &mut dyn RpcEnvironment) -> Result<
|
|||||||
schema: user::EMAIL_SCHEMA,
|
schema: user::EMAIL_SCHEMA,
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
|
delete: {
|
||||||
|
description: "List of properties to delete.",
|
||||||
|
type: Array,
|
||||||
|
optional: true,
|
||||||
|
items: {
|
||||||
|
type: DeletableProperty,
|
||||||
|
}
|
||||||
|
},
|
||||||
digest: {
|
digest: {
|
||||||
optional: true,
|
optional: true,
|
||||||
schema: PROXMOX_CONFIG_DIGEST_SCHEMA,
|
schema: PROXMOX_CONFIG_DIGEST_SCHEMA,
|
||||||
@ -326,6 +349,7 @@ pub fn update_user(
|
|||||||
firstname: Option<String>,
|
firstname: Option<String>,
|
||||||
lastname: Option<String>,
|
lastname: Option<String>,
|
||||||
email: Option<String>,
|
email: Option<String>,
|
||||||
|
delete: Option<Vec<DeletableProperty>>,
|
||||||
digest: Option<String>,
|
digest: Option<String>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
@ -340,6 +364,17 @@ pub fn update_user(
|
|||||||
|
|
||||||
let mut data: user::User = config.lookup("user", userid.as_str())?;
|
let mut data: user::User = config.lookup("user", userid.as_str())?;
|
||||||
|
|
||||||
|
if let Some(delete) = delete {
|
||||||
|
for delete_prop in delete {
|
||||||
|
match delete_prop {
|
||||||
|
DeletableProperty::comment => data.comment = None,
|
||||||
|
DeletableProperty::firstname => data.firstname = None,
|
||||||
|
DeletableProperty::lastname => data.lastname = None,
|
||||||
|
DeletableProperty::email => data.email = None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(comment) = comment {
|
if let Some(comment) = comment {
|
||||||
let comment = comment.trim().to_string();
|
let comment = comment.trim().to_string();
|
||||||
if comment.is_empty() {
|
if comment.is_empty() {
|
||||||
|
@ -100,17 +100,26 @@ Ext.define('PBS.window.UserEdit', {
|
|||||||
xtype: 'proxmoxtextfield',
|
xtype: 'proxmoxtextfield',
|
||||||
name: 'firstname',
|
name: 'firstname',
|
||||||
fieldLabel: gettext('First Name'),
|
fieldLabel: gettext('First Name'),
|
||||||
|
cbind: {
|
||||||
|
deleteEmpty: '{!isCreate}',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
xtype: 'proxmoxtextfield',
|
xtype: 'proxmoxtextfield',
|
||||||
name: 'lastname',
|
name: 'lastname',
|
||||||
fieldLabel: gettext('Last Name'),
|
fieldLabel: gettext('Last Name'),
|
||||||
|
cbind: {
|
||||||
|
deleteEmpty: '{!isCreate}',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
xtype: 'proxmoxtextfield',
|
xtype: 'proxmoxtextfield',
|
||||||
name: 'email',
|
name: 'email',
|
||||||
fieldLabel: gettext('E-Mail'),
|
fieldLabel: gettext('E-Mail'),
|
||||||
vtype: 'proxmoxMail',
|
vtype: 'proxmoxMail',
|
||||||
|
cbind: {
|
||||||
|
deleteEmpty: '{!isCreate}',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
||||||
@ -119,6 +128,9 @@ Ext.define('PBS.window.UserEdit', {
|
|||||||
xtype: 'proxmoxtextfield',
|
xtype: 'proxmoxtextfield',
|
||||||
name: 'comment',
|
name: 'comment',
|
||||||
fieldLabel: gettext('Comment'),
|
fieldLabel: gettext('Comment'),
|
||||||
|
cbind: {
|
||||||
|
deleteEmpty: '{!isCreate}',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user