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 305DB62E00 for ; Wed, 28 Oct 2020 12:37:10 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 103101E7F1 for ; Wed, 28 Oct 2020 12:36:40 +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 3F35A1E7C0 for ; Wed, 28 Oct 2020 12:36:39 +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 0B7B7444E7 for ; Wed, 28 Oct 2020 12:36:39 +0100 (CET) From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= To: pbs-devel@lists.proxmox.com Date: Wed, 28 Oct 2020 12:36:22 +0100 Message-Id: <20201028113632.814586-2-f.gruenbichler@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201028113632.814586-1-f.gruenbichler@proxmox.com> References: <20201028113632.814586-1-f.gruenbichler@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.030 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [result.data] Subject: [pbs-devel] [PATCH proxmox-widget-toolkit] add PermissionView 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, 28 Oct 2020 11:37:10 -0000 copied from pve-manager, but handling both '1' and 'true' as propagate values, and making the authentication ID name/parameter configurable. Signed-off-by: Fabian Grünbichler --- src/Makefile | 1 + src/panel/PermissionView.js | 153 ++++++++++++++++++++++++++++++++++++ 2 files changed, 154 insertions(+) create mode 100644 src/panel/PermissionView.js diff --git a/src/Makefile b/src/Makefile index cd0bf26..f984ac7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -40,6 +40,7 @@ JSSRC= \ panel/InfoWidget.js \ panel/LogView.js \ panel/JournalView.js \ + panel/PermissionView.js \ panel/RRDChart.js \ panel/GaugeWidget.js \ window/Edit.js \ diff --git a/src/panel/PermissionView.js b/src/panel/PermissionView.js new file mode 100644 index 0000000..5aa74ff --- /dev/null +++ b/src/panel/PermissionView.js @@ -0,0 +1,153 @@ +Ext.define('pmx-permissions', { + extend: 'Ext.data.TreeModel', + fields: [ + 'text', 'type', + { + type: 'boolean', name: 'propagate', + }, + ], +}); + +Ext.define('Proxmox.panel.PermissionViewPanel', { + extend: 'Ext.tree.Panel', + xtype: 'proxmoxPermissionViewPanel', + + scrollable: true, + layout: 'fit', + rootVisible: false, + animate: false, + sortableColumns: false, + + auth_id_name: "userid", + auth_id: undefined, + + columns: [ + { + xtype: 'treecolumn', + header: gettext('Path') + '/' + gettext('Permission'), + dataIndex: 'text', + flex: 6, + }, + { + header: gettext('Propagate'), + dataIndex: 'propagate', + flex: 1, + renderer: function(value) { + if (Ext.isDefined(value)) { + return Proxmox.Utils.format_boolean(value); + } + return ''; + }, + }, + ], + + initComponent: function() { + let me = this; + + Proxmox.Utils.API2Request({ + url: '/access/permissions?' + encodeURIComponent(me.auth_id_name) + '=' + encodeURIComponent(me.auth_id), + method: 'GET', + failure: function(response, opts) { + Proxmox.Utils.setErrorMask(me, response.htmlStatus); + }, + success: function(response, opts) { + Proxmox.Utils.setErrorMask(me, false); + let result = Ext.decode(response.responseText); + let data = result.data || {}; + + let root = { + name: '__root', + expanded: true, + children: [], + }; + let idhash = { + '/': { + children: [], + text: '/', + type: 'path', + }, + }; + Ext.Object.each(data, function(path, perms) { + let path_item = { + text: path, + type: 'path', + children: [], + }; + Ext.Object.each(perms, function(perm, propagate) { + let perm_item = { + text: perm, + type: 'perm', + propagate: propagate === 1 || propagate === true, + iconCls: 'fa fa-fw fa-unlock', + leaf: true, + }; + path_item.children.push(perm_item); + path_item.expandable = true; + }); + idhash[path] = path_item; + }); + + Ext.Object.each(idhash, function(path, item) { + let parent_item = idhash['/']; + if (path === '/') { + parent_item = root; + item.expanded = true; + } else { + let split_path = path.split('/'); + while (split_path.pop()) { + let parent_path = split_path.join('/'); + if (idhash[parent_path]) { + parent_item = idhash[parent_path]; + break; + } + } + } + parent_item.children.push(item); + }); + + me.setRootNode(root); + }, + }); + + me.callParent(); + + me.store.sorters.add(new Ext.util.Sorter({ + sorterFn: function(rec1, rec2) { + let v1 = rec1.data.text, + v2 = rec2.data.text; + if (rec1.data.type !== rec2.data.type) { + v2 = rec1.data.type; + v1 = rec2.data.type; + } + if (v1 > v2) { + return 1; + } else if (v1 < v2) { + return -1; + } + return 0; + }, + })); + }, +}); + +Ext.define('Proxmox.PermissionView', { + extend: 'Ext.window.Window', + alias: 'widget.userShowPermissionWindow', + mixins: ['Proxmox.Mixin.CBind'], + + scrollable: true, + width: 800, + height: 600, + layout: 'fit', + cbind: { + title: (get) => Ext.String.htmlEncode(get('auth_id')) + + ` - ${gettext('Granted Permissions')}`, + }, + items: [{ + xtype: 'proxmoxPermissionViewPanel', + cbind: { + auth_id: '{auth_id}', + auth_id_name: '{auth_id_name}', + }, + }], +}); -- 2.20.1