From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <p.hufnagl@proxmox.com>
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 5AD3299077
 for <pve-devel@lists.proxmox.com>; Tue, 10 Oct 2023 12:40:50 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 4483E3174D
 for <pve-devel@lists.proxmox.com>; Tue, 10 Oct 2023 12:40:50 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (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
 for <pve-devel@lists.proxmox.com>; Tue, 10 Oct 2023 12:40:49 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B9E824496C
 for <pve-devel@lists.proxmox.com>; Tue, 10 Oct 2023 12:40:48 +0200 (CEST)
From: Philipp Hufnagl <p.hufnagl@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Tue, 10 Oct 2023 12:40:33 +0200
Message-Id: <20231010104034.932760-5-p.hufnagl@proxmox.com>
X-Mailer: git-send-email 2.39.2
In-Reply-To: <20231010104034.932760-1-p.hufnagl@proxmox.com>
References: <20231010104034.932760-1-p.hufnagl@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.083 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH proxmox-widget-toolkit v2 1/1] fix #4546: ui:
 notify user if there usser account expires soon
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Tue, 10 Oct 2023 10:40:50 -0000

When the user account that is currently logged in will expire soon, the
user icon will turn into a yellow exclamation mark. In the user menu
there will be a new element informing the user briefly about it. If the
element is clicked, a popup will appear informing the user in detail
about it

Signed-off-by: Philipp Hufnagl <p.hufnagl@proxmox.com>
---
 www/manager6/Workspace.js | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/www/manager6/Workspace.js b/www/manager6/Workspace.js
index 18d574b7..41d44a00 100644
--- a/www/manager6/Workspace.js
+++ b/www/manager6/Workspace.js
@@ -42,6 +42,7 @@ Ext.define('PVE.Workspace', {
 	Proxmox.Utils.authClear();
 	Ext.state.Manager.clear('GuiCap');
 	Proxmox.UserName = null;
+	Proxmox.AccountExpiryDate = null;
 	me.loginData = null;
 
 	if (!me.login) {
@@ -198,6 +199,18 @@ Ext.define('PVE.StdWorkspace', {
 	let me = this;
 	let ui = me.query('#userinfo')[0];
 	ui.setText(Ext.String.htmlEncode(Proxmox.UserName || ''));
+	let label = me.query('#expirewarning')[0];
+	if (Proxmox.AccountExpiryDate !== null) {
+	    let expiryWarningThreshold = Ext.Date.add(new Date(), Ext.Date.DAY, 7);
+	    let expireDate = new Date(Proxmox.AccountExpiryDate * 1000);
+	    if (expiryWarningThreshold >= expireDate) {
+	        ui.setIconCls('fa fa-exclamation-triangle warning');
+		label.setHidden(false);
+	    }
+	} else {
+		label.setHidden(true);
+		ui.setIconCls('fa fa-user');
+	}
 	ui.updateLayout();
     },
 
@@ -367,6 +380,21 @@ Ext.define('PVE.StdWorkspace', {
 			    },
 			    iconCls: 'fa fa-user',
 			    menu: [
+				{
+				    iconCls: 'fa fa-exclamation-triangle warning',
+				    itemId: 'expirewarning',
+				    text: gettext('Account expiring soon!'),
+				    hidden: true,
+				    handler: function() {
+					let expireDate = new Date(Proxmox.AccountExpiryDate * 1000);
+					Ext.Msg.show({
+					    title: gettext('Account expiring soon!'),
+					    icon: Ext.Msg.WARNING,
+					    message: Ext.String.format(gettext("Your account is expiring on {0} . After that you won't be able to log in!"), expireDate),
+					    buttons: Ext.Msg.OK,
+					});
+				    },
+				},
 				{
 				    iconCls: 'fa fa-gear',
 				    text: gettext('My Settings'),
-- 
2.39.2