[pve-devel] [PATCH manager 5/6] ui: Utils: refactor userid parsing to Utils

Dominik Csapak d.csapak at proxmox.com
Thu Jul 1 14:25:05 CEST 2021


we'll need that again

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/Utils.js       | 26 +++++++++++++++++++++++++-
 www/manager6/dc/UserView.js |  4 ++--
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/www/manager6/Utils.js b/www/manager6/Utils.js
index fbd2dfa8..d807a37e 100644
--- a/www/manager6/Utils.js
+++ b/www/manager6/Utils.js
@@ -1770,7 +1770,31 @@ Ext.define('PVE.Utils', {
 	}
 	return undefined;
     },
-},
+
+     // returns username + realm
+     parse_userid: function(userid) {
+	 if (!Ext.isString(userid)) {
+	     return [undefined, undefined];
+	 }
+
+	 let match = userid.match(/^(.+)@([^@]+)$/);
+	 if (match !== null) {
+	     return [match[1], match[2]];
+	 }
+
+	 return [undefined, undefined];
+     },
+
+     render_username: function(userid) {
+	 let username = PVE.Utils.parse_userid(userid)[0] || "";
+	 return Ext.htmlEncode(username);
+     },
+
+     render_realm: function(userid) {
+	 let username = PVE.Utils.parse_userid(userid)[1] || "";
+	 return Ext.htmlEncode(username);
+     },
+ },
 
     singleton: true,
     constructor: function() {
diff --git a/www/manager6/dc/UserView.js b/www/manager6/dc/UserView.js
index 957b7724..79f7c52c 100644
--- a/www/manager6/dc/UserView.js
+++ b/www/manager6/dc/UserView.js
@@ -152,14 +152,14 @@ Ext.define('PVE.dc.UserView', {
 		    header: gettext('User name'),
 		    width: 200,
 		    sortable: true,
-		    renderer: userid => Ext.String.htmlEncode(userid.match(/^(.+)(@[^@]+)$/)[1]),
+		    renderer: PVE.Utils.render_username,
 		    dataIndex: 'userid',
 		},
 		{
 		    header: gettext('Realm'),
 		    width: 100,
 		    sortable: true,
-		    renderer: userid => Ext.String.htmlEncode(userid.match(/@([^@]+)$/)[1]),
+		    renderer: PVE.Utils.render_realm,
 		    dataIndex: 'userid',
 		},
 		{
-- 
2.30.2






More information about the pve-devel mailing list