public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-manager v2 2/4] notifications: apt: clean up notification template
Date: Fri, 28 Mar 2025 11:19:12 +0100	[thread overview]
Message-ID: <20250328101915.73951-4-l.wagner@proxmox.com> (raw)
In-Reply-To: <20250328101915.73951-1-l.wagner@proxmox.com>

Clean up the notification templates to prepare for user-customizable
templates
 - Change some of the template variable names to improve clarity
 - Generate the table for available updates in the template itself,
   not via the 'table' helper. This makes it possible for users
   to change the style/structure of the table.

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---
 PVE/API2/APT.pm                               | 27 ++++++++-----------
 .../default/package-updates-body.html.hbs     | 15 ++++++++++-
 .../default/package-updates-body.txt.hbs      |  2 +-
 .../default/package-updates-subject.txt.hbs   |  2 +-
 4 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm
index 47c50961..99c2e152 100644
--- a/PVE/API2/APT.pm
+++ b/PVE/API2/APT.pm
@@ -306,43 +306,38 @@ __PACKAGE__->register_method({
 		    schema => {
 			columns => [
 			    {
-				label => "Package",
-				id    => "package",
+				label => "Package Name",
+				id    => "package-name",
 			    },
 			    {
-				label => "Old Version",
-				id    => "old-version",
+				label => "Installed Version",
+				id    => "installed-version",
 			    },
 			    {
-				label => "New Version",
-				id    => "new-version",
+				label => "Available Version",
+				id    => "available-version",
 			    }
 			]
 		    },
 		    data => []
 		};
 
-		my $hostname = `hostname -f` || PVE::INotify::nodename();
-		chomp $hostname;
-
 		my $count = 0;
 		foreach my $p (sort {$a->{Package} cmp $b->{Package} } @$pkglist) {
 		    next if $p->{NotifyStatus} && $p->{NotifyStatus} eq $p->{Version};
 		    $count++;
 
 		    push @{$updates_table->{data}}, {
-			"package"     => $p->{Package},
-			"old-version" => $p->{OldVersion},
-			"new-version" => $p->{Version}
+			"package-name" => $p->{Package},
+			"installed-version" => $p->{OldVersion},
+			"available-version" => $p->{Version}
 		    };
 		}
 
 		return if !$count;
 
-		my $template_data = {
-		    updates  => $updates_table,
-		    hostname => $hostname,
-		};
+		my $template_data = PVE::Notify::common_template_data();
+		$template_data->{"available-updates"} = $updates_table;
 
 		# Additional metadata fields that can be used in notification
 		# matchers.
diff --git a/templates/default/package-updates-body.html.hbs b/templates/default/package-updates-body.html.hbs
index d058e114..ad29a941 100644
--- a/templates/default/package-updates-body.html.hbs
+++ b/templates/default/package-updates-body.html.hbs
@@ -1,6 +1,19 @@
 <html>
     <body>
         The following updates are available:
-        {{table updates}}
+        <table style="border: 1px solid;border-collapse=collapse;margin-top: 5px;">
+            <tr>
+                <th style="border: 1px solid;border-collapse=collapse;">Package Name</th>
+                <th style="border: 1px solid;border-collapse=collapse;">Installed Version</th>
+                <th style="border: 1px solid;border-collapse=collapse;">Available Version</th>
+            </tr>
+        {{#each available-updates.data}}
+            <tr>
+                <td style="border: 1px solid;border-collapse=collapse;">{{this.package-name}}</th>
+                <td style="border: 1px solid;border-collapse=collapse;">{{this.installed-version}}</th>
+                <td style="border: 1px solid;border-collapse=collapse;">{{this.available-version}}</th>
+            </tr>
+        {{/each}}
+        </table>
     </body>
 </html>
diff --git a/templates/default/package-updates-body.txt.hbs b/templates/default/package-updates-body.txt.hbs
index 14bdbf9e..74969433 100644
--- a/templates/default/package-updates-body.txt.hbs
+++ b/templates/default/package-updates-body.txt.hbs
@@ -1,3 +1,3 @@
 The following updates are available:
 
-{{table updates}}
+{{table available-updates}}
diff --git a/templates/default/package-updates-subject.txt.hbs b/templates/default/package-updates-subject.txt.hbs
index 556a67b8..b73fdefd 100644
--- a/templates/default/package-updates-subject.txt.hbs
+++ b/templates/default/package-updates-subject.txt.hbs
@@ -1 +1 @@
-New software packages available ({{hostname}})
+New software packages available ({{fqdn}})
-- 
2.39.5



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


  parent reply	other threads:[~2025-03-28 10:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-28 10:19 [pve-devel] [PATCH cluster/ha-manager/manager v2 0/6] preparation for #6143: notification template cleanup Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-cluster v2 1/1] notify: add common_template_data Lukas Wagner
2025-04-04 10:15   ` [pve-devel] applied: " Thomas Lamprecht
2025-03-28 10:19 ` [pve-devel] [PATCH pve-manager v2 1/4] notification templates: vzdump: generate HTML table in template Lukas Wagner
2025-03-28 10:19 ` Lukas Wagner [this message]
2025-03-28 10:19 ` [pve-devel] [PATCH pve-manager v2 3/4] notification: replication: add common properties to template data Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-manager v2 4/4] notifications: test: style fixup Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-ha-manager v2 1/1] notifications: overhaul fence notification Lukas Wagner
2025-04-04 18:25   ` [pve-devel] applied: " Thomas Lamprecht
2025-04-04 18:27 ` [pve-devel] applied-series: [PATCH cluster/ha-manager/manager v2 0/6] preparation for #6143: notification template cleanup Thomas Lamprecht

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=20250328101915.73951-4-l.wagner@proxmox.com \
    --to=l.wagner@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