From c6b628f4e53afb1f234d2a8fe5defffe3076723d Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: May 20 2023 02:28:06 +0000
Subject: [PATCH 1/2] better handling of deleted tags in kojiweb


1. notifications might reference deleted tags
2. tasks might reference deleted tags
3. handle deleted tags in taskinfo page

---

diff --git a/www/kojiweb/index.py b/www/kojiweb/index.py
index 731fe87..e6db22f 100644
--- a/www/kojiweb/index.py
+++ b/www/kojiweb/index.py
@@ -363,15 +363,21 @@ def index(environ, packageOrder='package_name', packageStart=None):
 
         notifs = server.getBuildNotifications(user['id'])
         notifs.sort(key=lambda x: x['id'])
-        # XXX Make this a multicall
+        with server.multicall() as m:
+            for notif in notifs:
+                notif['package'] = None
+                if notif['package_id']:
+                    notif['package'] = m.getPackage(notif['package_id'])
+
+                notif['tag'] = None
+                if notif['tag_id']:
+                    # it's possible a notification could reference a deleted tag
+                    notif['tag'] = m.getTag(notif['tag_id'], event='auto')
         for notif in notifs:
-            notif['package'] = None
-            if notif['package_id']:
-                notif['package'] = server.getPackage(notif['package_id'])
-
-            notif['tag'] = None
-            if notif['tag_id']:
-                notif['tag'] = server.getTag(notif['tag_id'])
+            if notif['package']:
+                notif['package'] = notif['package'].result
+            if notif['tag']:
+                notif['tag'] = notif['tag'].result
         values['notifs'] = notifs
 
     values['user'] = user
@@ -702,10 +708,10 @@ def taskinfo(environ, taskID):
         elif isinstance(tag_id, dict):
             return tag_id
         else:
-            try:
-                return server.getTag(tag_id, strict=True)
-            except koji.GenericError:
-                return {'name': "%d (deleted)" % tag_id, 'id': None}
+            info = server.getTag(tag_id, event='auto')
+            if info and 'revoke_event' in info:
+                info['name'] = "%(name)s (deleted)" % info
+            return info
 
     if 'root' in params:
         params['build_tag'] = _get_tag(params.pop('root'))
@@ -995,9 +1001,14 @@ def taginfo(environ, tagID, all='0', packageOrder='package_name', packageStart=N
     server = _getServer(environ)
 
     tagID = _convert_if_int(tagID)
-    tag = server.getTag(tagID, strict=True)
+    tag = server.getTag(tagID, strict=True, event='auto')
 
     values['title'] = tag['name'] + ' | Tag Info'
+    values['tag'] = tag
+    values['tagID'] = tag['id']
+    if 'revoke_event' in tag:
+        values['delete_ts'] = server.getEvent(tag['revoke_event'])['ts']
+        return _genHTML(environ, 'taginfo_deleted.chtml')
 
     all = int(all)
 
@@ -1023,8 +1034,6 @@ def taginfo(environ, tagID, all='0', packageOrder='package_name', packageStart=N
     destTargets = server.getBuildTargets(destTagID=tag['id'])
     destTargets.sort(key=_sortbyname)
 
-    values['tag'] = tag
-    values['tagID'] = tag['id']
     values['inheritance'] = inheritance
     values['tagsByChild'] = tagsByChild
     values['srcTargets'] = srcTargets

From ee966a2155be0c8ed5f79d0ad57fb20ac1c6ea64 Mon Sep 17 00:00:00 2001
From: Mike McLean <mikem@redhat.com>
Date: May 20 2023 02:35:29 +0000
Subject: [PATCH 2/2] include new template


---

diff --git a/www/kojiweb/taginfo_deleted.chtml b/www/kojiweb/taginfo_deleted.chtml
new file mode 100644
index 0000000..be4302c
--- /dev/null
+++ b/www/kojiweb/taginfo_deleted.chtml
@@ -0,0 +1,21 @@
+#from kojiweb import util
+#from urllib.parse import quote
+#import pprint
+
+#include "includes/header.chtml"
+
+  <h4>Information for deleted tag <a href="taginfo?tagID=$tag.id">$util.escapeHTML($tag.name)</a></h4>
+
+  <table>
+    <tr>
+      <th>Name</th><td>$util.escapeHTML($tag.name)</td>
+    </tr>
+    <tr>
+      <th>ID</th><td>$tag.id</td>
+    </tr>
+    <tr>
+      <th>Deleted</th><td>$util.formatTimeLong($delete_ts)</td>
+    </tr>
+  </table>
+
+#include "includes/footer.chtml"

