From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@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 627336A50A
 for <pbs-devel@lists.proxmox.com>; Fri, 26 Feb 2021 16:10:40 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 07175188BB
 for <pbs-devel@lists.proxmox.com>; Fri, 26 Feb 2021 16:10:10 +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 BD09B18879
 for <pbs-devel@lists.proxmox.com>; Fri, 26 Feb 2021 16:10:07 +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 8679142732
 for <pbs-devel@lists.proxmox.com>; Fri, 26 Feb 2021 16:10:07 +0100 (CET)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pbs-devel@lists.proxmox.com
Date: Fri, 26 Feb 2021 16:09:59 +0100
Message-Id: <20210226150959.9518-11-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20210226150959.9518-1-f.ebner@proxmox.com>
References: <20210226150959.9518-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.000 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. [values.name]
Subject: [pbs-devel] [RFC v2 widget-toolkit 10/10] APT: show warnings for
 repositories
X-BeenThere: pbs-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Backup Server development discussion
 <pbs-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pbs-devel/>
List-Post: <mailto:pbs-devel@lists.proxmox.com>
List-Help: <mailto:pbs-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel>, 
 <mailto:pbs-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Fri, 26 Feb 2021 15:10:40 -0000

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v1:
    * Use the row body feature to pin warnings to the repository they are for
      and make warnings more prominent.
    * Also check the subscription status.

Sent as an RFC, because there's probably a better way than using the
title bar for the global warning.

 src/node/APTRepositories.js | 116 +++++++++++++++++++++++++++++++++++-
 1 file changed, 115 insertions(+), 1 deletion(-)

diff --git a/src/node/APTRepositories.js b/src/node/APTRepositories.js
index f4a3a43..c8033df 100644
--- a/src/node/APTRepositories.js
+++ b/src/node/APTRepositories.js
@@ -21,6 +21,51 @@ Ext.define('Proxmox.node.APTRepositories', {
 
     sortableColumns: false,
 
+    viewModel: {
+	data: {
+	    subscriptionActive: '',
+	    noSubscriptionRepo: '',
+	    enterpriseRepo: '',
+	},
+	formulas: {
+	    globalWarning: function(get) {
+		if (get('subscriptionActive') === '' ||
+		    get('noSubscriptionRepo') === '' ||
+		    get('enterpriseRepo') === '') {
+		    return '';
+		}
+
+		if (!get('subscriptionActive') && get('enterpriseRepo')) {
+		    return "WARNING: The enterprise repository is configured " +
+			"but there is no active subscription!";
+		}
+
+		if (get('noSubscriptionRepo')) {
+		    return "WARNING: The no-subscription repository is not " +
+			"recommended for production use!";
+		}
+
+		if (!get('enterpriseRepo') && !get('noSubscriptionRepo')) {
+		    return "WARNING: Neither the enterprise nor the " +
+			"no-subscription repository is active!";
+		}
+
+		return '';
+	    },
+	},
+    },
+
+    tbar: [
+	{
+	    xtype: 'label',
+	    text: 'default',
+	    style: 'color: red;',
+	    bind: {
+		text: '{globalWarning}',
+	    },
+	},
+    ],
+
     columns: [
 	{
 	    header: gettext('Enabled'),
@@ -94,6 +139,71 @@ Ext.define('Proxmox.node.APTRepositories', {
 	},
     ],
 
+    check_repositories: function(rowBodyFeature) {
+	let me = this;
+	let vm = me.getViewModel();
+
+	Proxmox.Utils.API2Request({
+	    url: `/nodes/${me.nodename}/apt/checkrepositories`,
+	    method: 'GET',
+	    failure: function(response, opts) {
+		Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+	    },
+	    success: function(response, opts) {
+		const data = response.result.data;
+
+		vm.set('enterpriseRepo', data.enterprise);
+		vm.set('noSubscriptionRepo', data.nosubscription);
+
+		let warnings = {};
+		for (const warning of data.warnings) {
+		    const key = `${warning.Path}:${warning.Number}`;
+		    if (warnings[key]) {
+			warnings[key] += "\n";
+			warnings[key] += "Warning: " + warning.Warning;
+		    } else {
+			warnings[key] = "Warning: " + warning.Warning;
+		    }
+		}
+
+		rowBodyFeature.getAdditionalData = function(innerData, rowIndex, record, orig) {
+		    let headerCt = this.view.headerCt;
+		    let colspan = headerCt.getColumnCount();
+
+		    const key = `${innerData.Path}:${innerData.Number}`;
+		    const warning_text = warnings[key];
+
+		    return {
+			rowBody: '<div style="color: red; white-space: pre-line">' +
+			    Ext.String.htmlEncode(warning_text) +
+			    '</div>',
+			rowBodyCls: warning_text ? '' : Ext.baseCSSPrefix + 'grid-row-body-hidden',
+			rowBodyColspan: colspan,
+		    };
+		};
+	    },
+	});
+    },
+
+    check_subscription: function() {
+	let me = this;
+	let vm = me.getViewModel();
+
+	Proxmox.Utils.API2Request({
+	    url: `/nodes/${me.nodename}/subscription`,
+	    method: 'GET',
+	    failure: function(response, opts) {
+		Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+	    },
+	    success: function(response, opts) {
+		const res = response.result;
+		const subscription = !(res === null || res === undefined ||
+		    !res || res.data.status.toLowerCase() !== 'active');
+		vm.set('subscriptionActive', subscription);
+	    },
+	});
+    },
+
     initComponent: function() {
 	let me = this;
 
@@ -116,6 +226,8 @@ Ext.define('Proxmox.node.APTRepositories', {
 	    ],
 	});
 
+	let rowBodyFeature = Ext.create('Ext.grid.feature.RowBody', {});
+
 	let groupingFeature = Ext.create('Ext.grid.feature.Grouping', {
 	    groupHeaderTpl: '{[ "File: " + values.name ]} ({rows.length} ' +
 		'repositor{[values.rows.length > 1 ? "ies" : "y"]})',
@@ -124,6 +236,8 @@ Ext.define('Proxmox.node.APTRepositories', {
 
 	let reload = function() {
 	    store.load();
+	    me.check_repositories(rowBodyFeature);
+	    me.check_subscription();
 	};
 
 	let sm = Ext.create('Ext.selection.RowModel', {});
@@ -131,7 +245,7 @@ Ext.define('Proxmox.node.APTRepositories', {
 	Ext.apply(me, {
 	    store: store,
 	    selModel: sm,
-	    features: [groupingFeature],
+	    features: [groupingFeature, rowBodyFeature],
 	    listeners: {
 		activate: reload,
 	    },
-- 
2.20.1