public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v2 1/4] show optional consent-banner before login
Date: Fri,  6 Dec 2024 12:19:55 +0100	[thread overview]
Message-ID: <20241206111958.117362-2-g.goller@proxmox.com> (raw)
In-Reply-To: <20241206111958.117362-1-g.goller@proxmox.com>

Add ConsentBanner variable to html template and populate it from the
`datacenter.cfg` config file. Add Datacenter option to set the text and
trigger the popup on login.

Signed-off-by: Gabriel Goller <g.goller@proxmox.com>
---
 PVE/Service/pveproxy.pm            | 13 ++++++++++---
 www/index.html.tpl                 |  3 ++-
 www/manager6/dc/OptionView.js      |  8 ++++++++
 www/manager6/window/LoginWindow.js | 12 +++++++++++-
 4 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/PVE/Service/pveproxy.pm b/PVE/Service/pveproxy.pm
index ac1085457f2e..b5bfd34ca3aa 100755
--- a/PVE/Service/pveproxy.pm
+++ b/PVE/Service/pveproxy.pm
@@ -218,10 +218,16 @@ sub get_index {
 	}
     }
 
-    if (!$lang) {
+    my $consent_text;
+    eval {
 	my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
-	$lang = $dc_conf->{language} // 'en';
-    }
+	$consent_text = $dc_conf->{'consent-text'};
+
+	if (!$lang) {
+	    $lang = $dc_conf->{language} // 'en';
+	}
+    };
+    warn "$@\n" if $@;
 
     my $mobile = (is_phone($r->header('User-Agent')) && (!defined($args->{mobile}) || $args->{mobile})) || $args->{mobile};
 
@@ -251,6 +257,7 @@ sub get_index {
 	version => "$version",
 	wtversion => $wtversion,
 	theme => $theme,
+	consenttext => $consent_text
     };
 
     # by default, load the normal index
diff --git a/www/index.html.tpl b/www/index.html.tpl
index 46dc877bcaf2..d53a867522dd 100644
--- a/www/index.html.tpl
+++ b/www/index.html.tpl
@@ -41,7 +41,8 @@
 	defaultLang: '[% lang %]',
 	NodeName: '[% nodename %]',
 	UserName: '[% username %]',
-	CSRFPreventionToken: '[% token %]'
+	CSRFPreventionToken: '[% token %]',
+	ConsentText: '[% consenttext %]'
     };
     </script>
     <script type="text/javascript" src="/proxmoxlib.js?ver=[% wtversion %]"></script>
diff --git a/www/manager6/dc/OptionView.js b/www/manager6/dc/OptionView.js
index b200fd12dcc9..8f9ea66eab1c 100644
--- a/www/manager6/dc/OptionView.js
+++ b/www/manager6/dc/OptionView.js
@@ -516,6 +516,14 @@ Ext.define('PVE.dc.OptionView', {
 	    },
 	};
 
+	me.add_textareafield_row('consent-text', gettext('Consent Text'), {
+	    deleteEmpty: true,
+	    fieldOpts: {
+		maxLength: 24000,
+	    },
+	    onlineHelp: 'consent_banner',
+	});
+
 	me.selModel = Ext.create('Ext.selection.RowModel', {});
 
 	Ext.apply(me, {
diff --git a/www/manager6/window/LoginWindow.js b/www/manager6/window/LoginWindow.js
index aaeca3550289..b4dff0c19ac1 100644
--- a/www/manager6/window/LoginWindow.js
+++ b/www/manager6/window/LoginWindow.js
@@ -18,9 +18,19 @@ Ext.define('PVE.window.LoginWindow', {
     },
 
     controller: {
-
 	xclass: 'Ext.app.ViewController',
 
+	init: async function() {
+	    if (Proxmox.ConsentText) {
+		Ext.create("Proxmox.window.ConsentModal", {
+		    autoShow: true,
+		    consent: Proxmox.Markdown.parse(
+			Proxmox.Utils.base64ToUtf8(Proxmox.ConsentText),
+		    ),
+		});
+	    }
+	},
+
 	onLogon: async function() {
 	    var me = this;
 
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  reply	other threads:[~2024-12-06 11:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-06 11:19 [pve-devel] [PATCH cluster/docs/manager/widget-toolkit v2 0/4] fix #5463: add optional Consent Banner on login Gabriel Goller
2024-12-06 11:19 ` Gabriel Goller [this message]
2024-12-06 11:19 ` [pve-devel] [PATCH cluster v2 2/4] add consent-text parameter to datacenter config file Gabriel Goller
2024-12-06 11:19 ` [pve-devel] [PATCH docs v2 3/4] add consent-banner description Gabriel Goller
2024-12-06 11:19 ` [pve-devel] [PATCH widget-toolkit v2 4/4] form: set enforceMaxLength on textareafield Gabriel Goller
2024-12-10 16:12 ` [pve-devel] [PATCH cluster/docs/manager/widget-toolkit v2 0/4] fix #5463: add optional Consent Banner on login Gabriel Goller

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=20241206111958.117362-2-g.goller@proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=pve-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