From 958055a78920cf67068ec7f4f63f1b44b1c40edd Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Thu, 21 Jan 2021 15:06:15 +0100 Subject: [PATCH] ui: fix on-parse use of global Proxmox.UserName This is wrong most of the time, when not loading the web interface with valid credentials, and thus some checks or defaults did not evaluated correctly when the underlying value was only set later. Needs to be set on component creation only, this can be done through initComponent, even listeners, view controllers or cbind closures. Use the latter, as all affected components already use cbind. Signed-off-by: Thomas Lamprecht --- www/window/AddTfaRecovery.js | 10 ++++++---- www/window/AddTotp.js | 13 ++++++------- www/window/AddWebauthn.js | 8 ++++++-- www/window/TfaEdit.js | 4 +++- www/window/TokenEdit.js | 2 +- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/www/window/AddTfaRecovery.js b/www/window/AddTfaRecovery.js index 1718f026..009453f0 100644 --- a/www/window/AddTfaRecovery.js +++ b/www/window/AddTfaRecovery.js @@ -40,7 +40,7 @@ Ext.define('PBS.window.AddTfaRecovery', { viewModel: { data: { has_entry: false, - userid: Proxmox.UserName, + userid: null, }, formulas: { passwordConfirmText: (get) => { @@ -89,6 +89,7 @@ Ext.define('PBS.window.AddTfaRecovery', { name: 'userid', cbind: { editable: (get) => !get('fixedUser'), + value: () => Proxmox.UserName, }, fieldLabel: gettext('User'), editConfig: { @@ -99,7 +100,6 @@ Ext.define('PBS.window.AddTfaRecovery', { }, }, renderer: Ext.String.htmlEncode, - value: Proxmox.UserName, listeners: { change: 'onUseridChange', }, @@ -127,8 +127,10 @@ Ext.define('PBS.window.AddTfaRecovery', { name: 'password', allowBlank: false, validateBlank: true, - hidden: Proxmox.UserName === 'root@pam', - disabled: Proxmox.UserName === 'root@pam', + cbind: { + hidden: () => Proxmox.UserName === 'root@pam', + disabled: () => Proxmox.UserName === 'root@pam', + }, bind: { emptyText: '{passwordConfirmText}', }, diff --git a/www/window/AddTotp.js b/www/window/AddTotp.js index 0141707a..20f26824 100644 --- a/www/window/AddTotp.js +++ b/www/window/AddTotp.js @@ -50,7 +50,7 @@ Ext.define('PBS.window.AddTotp', { valid: false, secret: '', otpuri: '', - userid: Proxmox.UserName, + userid: null, }, formulas: { @@ -96,11 +96,6 @@ Ext.define('PBS.window.AddTotp', { view.down('#qrbox').getEl().appendChild(view.qrdiv); view.getController().randomizeSecret(); - - if (Proxmox.UserName === 'root@pam') { - view.lookup('password').setVisible(false); - view.lookup('password').setDisabled(true); - } }, }, }, @@ -140,6 +135,7 @@ Ext.define('PBS.window.AddTotp', { name: 'userid', cbind: { editable: (get) => get('isAdd') && !get('fixedUser'), + value: () => Proxmox.UserName, }, fieldLabel: gettext('User'), editConfig: { @@ -147,7 +143,6 @@ Ext.define('PBS.window.AddTotp', { allowBlank: false, }, renderer: Ext.String.htmlEncode, - value: Proxmox.UserName, listeners: { change: function(field, newValue, oldValue) { let vm = this.up('window').getViewModel(); @@ -259,6 +254,10 @@ Ext.define('PBS.window.AddTotp', { name: 'password', allowBlank: false, validateBlank: true, + cbind: { + hidden: () => Proxmox.UserName === 'root@pam', + disabled: () => Proxmox.UserName === 'root@pam', + }, bind: { emptyText: '{passwordConfirmText}', }, diff --git a/www/window/AddWebauthn.js b/www/window/AddWebauthn.js index 28d7265b..f8883da3 100644 --- a/www/window/AddWebauthn.js +++ b/www/window/AddWebauthn.js @@ -22,7 +22,7 @@ Ext.define('PBS.window.AddWebauthn', { viewModel: { data: { valid: false, - userid: Proxmox.UserName, + userid: null, }, formulas: { passwordConfirmText: (get) => { @@ -153,6 +153,7 @@ Ext.define('PBS.window.AddWebauthn', { name: 'user', cbind: { editable: (get) => !get('fixedUser'), + value: () => Proxmox.UserName, }, fieldLabel: gettext('User'), editConfig: { @@ -160,7 +161,6 @@ Ext.define('PBS.window.AddWebauthn', { allowBlank: false, }, renderer: Ext.String.htmlEncode, - value: Proxmox.UserName, listeners: { change: function(field, newValue, oldValue) { let vm = this.up('window').getViewModel(); @@ -185,6 +185,10 @@ Ext.define('PBS.window.AddWebauthn', { name: 'password', allowBlank: false, validateBlank: true, + cbind: { + hidden: () => Proxmox.UserName === 'root@pam', + disabled: () => Proxmox.UserName === 'root@pam', + }, bind: { emptyText: '{passwordConfirmText}', }, diff --git a/www/window/TfaEdit.js b/www/window/TfaEdit.js index abec1335..6b612d53 100644 --- a/www/window/TfaEdit.js +++ b/www/window/TfaEdit.js @@ -50,7 +50,9 @@ Ext.define('PBS.window.TfaEdit', { xtype: 'pbsUserSelector', allowBlank: false, }, - value: Proxmox.UserName, + cbind: { + value: () => Proxmox.UserName, + }, }, { xtype: 'proxmoxtextfield', diff --git a/www/window/TokenEdit.js b/www/window/TokenEdit.js index caa0765c..3f88b891 100644 --- a/www/window/TokenEdit.js +++ b/www/window/TokenEdit.js @@ -23,13 +23,13 @@ Ext.define('PBS.window.TokenEdit', { xtype: 'pmxDisplayEditField', cbind: { editable: (get) => get('isCreate') && !get('fixedUser'), + value: () => Proxmox.UserName, }, editConfig: { xtype: 'pbsUserSelector', allowBlank: false, }, name: 'user', - value: Proxmox.UserName, renderer: Ext.String.htmlEncode, fieldLabel: gettext('User'), },