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 <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2021-01-21 15:06:15 +01:00
parent edda5039d4
commit 958055a789
5 changed files with 22 additions and 15 deletions

View File

@ -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}',
},

View File

@ -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}',
},

View File

@ -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}',
},

View File

@ -50,7 +50,9 @@ Ext.define('PBS.window.TfaEdit', {
xtype: 'pbsUserSelector',
allowBlank: false,
},
value: Proxmox.UserName,
cbind: {
value: () => Proxmox.UserName,
},
},
{
xtype: 'proxmoxtextfield',

View File

@ -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'),
},