From 333051ab1f65d28fce7ecbae8ada50a75564303d Mon Sep 17 00:00:00 2001
From: Mario Oenning <mo-son@mailbox.org>
Date: Fri, 28 Oct 2022 16:55:16 +0000
Subject: [PATCH] feat: add field "Submitter" to metadata-archives

---
 aurweb/scripts/mkpkglists.py | 5 +++++
 test/test_mkpkglists.py      | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/aurweb/scripts/mkpkglists.py b/aurweb/scripts/mkpkglists.py
index 67cc7fab5..1ff6fbb28 100755
--- a/aurweb/scripts/mkpkglists.py
+++ b/aurweb/scripts/mkpkglists.py
@@ -163,6 +163,7 @@ def as_dict(package: Package) -> dict[str, Any]:
         "Popularity": float(package.Popularity),
         "OutOfDate": package.OutOfDate,
         "Maintainer": package.Maintainer,
+        "Submitter": package.Submitter,
         "FirstSubmitted": package.FirstSubmitted,
         "LastModified": package.LastModified,
     }
@@ -190,10 +191,13 @@ def _main():
     logger.warning(f"{sys.argv[0]} is deprecated and will be soon be removed")
     logger.info("Started re-creating archives, wait a while...")
 
+    Submitter = orm.aliased(User)
+
     query = (
         db.query(Package)
         .join(PackageBase, PackageBase.ID == Package.PackageBaseID)
         .join(User, PackageBase.MaintainerUID == User.ID, isouter=True)
+        .join(Submitter, PackageBase.SubmitterUID == Submitter.ID, isouter=True)
         .filter(PackageBase.PackagerUID.isnot(None))
         .with_entities(
             Package.ID,
@@ -207,6 +211,7 @@ def _main():
             PackageBase.Popularity,
             PackageBase.OutOfDateTS.label("OutOfDate"),
             User.Username.label("Maintainer"),
+            Submitter.Username.label("Submitter"),
             PackageBase.SubmittedTS.label("FirstSubmitted"),
             PackageBase.ModifiedTS.label("LastModified"),
         )
diff --git a/test/test_mkpkglists.py b/test/test_mkpkglists.py
index 3c1058177..e7800ffea 100644
--- a/test/test_mkpkglists.py
+++ b/test/test_mkpkglists.py
@@ -30,6 +30,7 @@ META_KEYS = [
     "Popularity",
     "OutOfDate",
     "Maintainer",
+    "Submitter",
     "FirstSubmitted",
     "LastModified",
     "URLPath",
@@ -61,7 +62,12 @@ def packages(user: User) -> list[Package]:
         lic = db.create(License, Name="GPL")
         for i in range(5):
             # Create the package.
-            pkgbase = db.create(PackageBase, Name=f"pkgbase_{i}", Packager=user)
+            pkgbase = db.create(
+                PackageBase,
+                Name=f"pkgbase_{i}",
+                Packager=user,
+                Submitter=user,
+            )
             pkg = db.create(Package, PackageBase=pkgbase, Name=f"pkg_{i}")
 
             # Create some related records.
-- 
GitLab