public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-widget-toolkit] add PermissionView
Date: Wed, 28 Oct 2020 12:36:22 +0100	[thread overview]
Message-ID: <20201028113632.814586-2-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20201028113632.814586-1-f.gruenbichler@proxmox.com>

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 <f.gruenbichler@proxmox.com>
---
 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





  reply	other threads:[~2020-10-28 11:37 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-28 11:36 [pbs-devel] [PATCH proxmox-backup 00/16] API tokens Fabian Grünbichler
2020-10-28 11:36 ` Fabian Grünbichler [this message]
2020-10-28 16:18   ` [pbs-devel] applied: [PATCH proxmox-widget-toolkit] add PermissionView Thomas Lamprecht
2020-10-28 11:36 ` [pbs-devel] [PATCH proxmox-backup 01/16] api: add Authid as wrapper around Userid Fabian Grünbichler
2020-10-28 11:36 ` [pbs-devel] [PATCH proxmox] rpcenv: rename user to auth_id Fabian Grünbichler
2020-10-28 11:36 ` [pbs-devel] [PATCH proxmox-backup 02/16] config: add token.shadow file Fabian Grünbichler
2020-10-28 11:36 ` [pbs-devel] [PATCH proxmox-backup 03/16] replace Userid with Authid Fabian Grünbichler
2020-10-28 11:36 ` [pbs-devel] [PATCH proxmox-backup 04/16] REST: extract and handle API tokens Fabian Grünbichler
2020-10-28 11:36 ` [pbs-devel] [PATCH proxmox-backup 05/16] api: add API token endpoints Fabian Grünbichler
2020-10-28 11:36 ` [pbs-devel] [PATCH proxmox-backup 06/16] api: allow listing users + tokens Fabian Grünbichler
2020-10-28 11:36 ` [pbs-devel] [PATCH proxmox-backup 07/16] api: add permissions endpoint Fabian Grünbichler
2020-10-28 11:36 ` [pbs-devel] [PATCH proxmox-backup 08/16] client/remote: allow using ApiToken + secret Fabian Grünbichler
2020-10-28 11:36 ` [pbs-devel] [PATCH proxmox-backup 09/16] owner checks: handle backups owned by API tokens Fabian Grünbichler
2020-10-28 11:37 ` [pbs-devel] [PATCH proxmox-backup 10/16] tasks: allow unpriv users to read their tokens' tasks Fabian Grünbichler
2020-10-28 11:37   ` [pbs-devel] [PATCH proxmox-backup 11/16] manager: add token commands Fabian Grünbichler
2020-10-28 11:37   ` [pbs-devel] [PATCH proxmox-backup 12/16] manager: add user permissions command Fabian Grünbichler
2020-10-28 11:37   ` [pbs-devel] [PATCH proxmox-backup 13/16] gui: add permissions button to user view Fabian Grünbichler
2020-10-28 11:37   ` [pbs-devel] [PATCH proxmox-backup 14/16] gui: add API token UI Fabian Grünbichler
2020-10-28 11:37   ` [pbs-devel] [PATCH proxmox-backup 15/16] acls: allow viewing/editing user's token ACLs Fabian Grünbichler
2020-10-28 11:37   ` [pbs-devel] [PATCH proxmox-backup 16/16] gui: add API " Fabian Grünbichler
2020-10-29 14:23 ` [pbs-devel] applied: [PATCH proxmox-backup 00/16] API tokens Wolfgang Bumiller
2020-10-29 19:50 ` [pbs-devel] " Thomas Lamprecht
2020-10-30  8:03   ` Fabian Grünbichler
2020-10-30  8:48     ` Thomas Lamprecht
2020-10-30  9:55       ` Fabian Grünbichler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201028113632.814586-2-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal