From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 8B1D1679ED for ; Wed, 13 Jan 2021 12:07:27 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 7B67A10200 for ; Wed, 13 Jan 2021 12:06:57 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 7FDFB101B6 for ; Wed, 13 Jan 2021 12:06:55 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 4B2D7452AE for ; Wed, 13 Jan 2021 12:06:55 +0100 (CET) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Wed, 13 Jan 2021 12:06:51 +0100 Message-Id: <20210113110654.17425-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210113110654.17425-1-d.csapak@proxmox.com> References: <20210113110654.17425-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.269 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 3/6] ui: window/AddTfaRecovery: rewrite to a Proxmox.window.Edit X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 Jan 2021 11:07:27 -0000 we can reuse the edit window from widget toolkit for the most part this solves some spacing and layout issues and is less code Signed-off-by: Dominik Csapak --- www/window/AddTfaRecovery.js | 116 +++++++++++------------------------ 1 file changed, 36 insertions(+), 80 deletions(-) diff --git a/www/window/AddTfaRecovery.js b/www/window/AddTfaRecovery.js index 710c243f..a260c0ca 100644 --- a/www/window/AddTfaRecovery.js +++ b/www/window/AddTfaRecovery.js @@ -1,23 +1,34 @@ Ext.define('PBS.window.AddTfaRecovery', { - extend: 'Ext.window.Window', + extend: 'Proxmox.window.Edit', alias: 'widget.pbsAddTfaRecovery', mixins: ['Proxmox.Mixin.CBind'], onlineHelp: 'user_mgmt', - - modal: true, - resizable: false, - title: gettext('Add TFA recovery keys'), + isCreate: true, + isAdd: true, + subject: gettext('TFA recovery keys'), width: 512, + method: 'POST', fixedUser: false, - baseurl: '/api2/extjs/access/tfa', + url: '/api2/extjs/access/tfa', + submitUrl: function(url, values) { + let userid = values.userid; + delete values.userid; + return `${url}/${userid}`; + }, + + apiCallDone: function(success, response) { + if (!success) { + return; + } - initComponent: function() { - let me = this; - me.callParent(); - Ext.GlobalEvents.fireEvent('proxmoxShowHelp', me.onlineHelp); + let values = response.result.data.recovery.join("\n"); + Ext.create('PBS.window.TfaRecoveryShow', { + autoShow: true, + values, + }); }, viewModel: { @@ -28,27 +39,13 @@ Ext.define('PBS.window.AddTfaRecovery', { controller: { xclass: 'Ext.app.ViewController', - control: { - '#': { - show: function() { - let me = this; - let view = me.getView(); - - if (Proxmox.UserName === 'root@pam') { - view.lookup('password').setVisible(false); - view.lookup('password').setDisabled(true); - } - }, - }, - }, - hasEntry: async function(userid) { let me = this; let view = me.getView(); try { await PBS.Async.api2({ - url: `${view.baseurl}/${userid}/recovery`, + url: `${view.url}/${userid}/recovery`, method: 'GET', }); return true; @@ -57,11 +54,11 @@ Ext.define('PBS.window.AddTfaRecovery', { } }, - init: function() { + init: function(view) { this.onUseridChange(null, Proxmox.UserName); }, - onUseridChange: async function(_field, userid) { + onUseridChange: async function(field, userid) { let me = this; me.userid = userid; @@ -69,43 +66,6 @@ Ext.define('PBS.window.AddTfaRecovery', { let has_entry = await me.hasEntry(userid); me.getViewModel().set('has_entry', has_entry); }, - - onAdd: async function() { - let me = this; - let view = me.getView(); - - view.mask(gettext('Please wait...'), 'x-mask-loading'); - - let baseurl = view.baseurl; - - let userid = me.userid; - if (userid === undefined) { - throw "no userid set"; - } - - let params = { type: 'recovery' }; - - if (Proxmox.UserName !== 'root@pam') { - params.password = me.lookup('password').getValue(); - } - - try { - let response = await PBS.Async.api2({ - url: `${baseurl}/${userid}`, - method: 'POST', - params, - }); - let values = response.result.data.recovery.join("\n"); - Ext.create('PBS.window.TfaRecoveryShow', { - autoShow: true, - values, - }); - } catch (ex) { - Ext.Msg.alert(gettext('Error'), ex); - } finally { - view.close(); - } - }, }, items: [ @@ -119,6 +79,9 @@ Ext.define('PBS.window.AddTfaRecovery', { editConfig: { xtype: 'pbsUserSelector', allowBlank: false, + validator: function(_value) { + return !this.up('window').getViewModel().get('has_entry'); + }, }, renderer: Ext.String.htmlEncode, value: Proxmox.UserName, @@ -126,11 +89,18 @@ Ext.define('PBS.window.AddTfaRecovery', { change: 'onUseridChange', }, }, + { + xtype: 'hiddenfield', + name: 'type', + value: 'recovery', + }, { xtype: 'displayfield', bind: { hidden: '{!has_entry}', }, + hidden: true, + userCls: 'pmx-hint', value: gettext('User already has recovery keys.'), }, { @@ -142,25 +112,11 @@ Ext.define('PBS.window.AddTfaRecovery', { name: 'password', allowBlank: false, validateBlank: true, - padding: '0 0 5 5', + hidden: Proxmox.UserName === 'root@pam', + disabled: Proxmox.UserName === 'root@pam', emptyText: gettext('verify current password'), }, ], - - buttons: [ - { - xtype: 'proxmoxHelpButton', - }, - '->', - { - xtype: 'button', - text: gettext('Add'), - handler: 'onAdd', - bind: { - disabled: '{has_entry}', - }, - }, - ], }); Ext.define('PBS.window.TfaRecoveryShow', { -- 2.20.1